Fix requirements differences via normalization
Hash randomization (or the newer pip version) seems to be altering the order of which requirements are created, so normalize the created and expected requirements into lists that we can check existence on (which doesn't care about ordering) to work around this issue. Change-Id: Ia00c3ddcf48f68662d307964ff3395890f4b9ef2
This commit is contained in:
committed by
Joshua Harlow
parent
673b1c35ac
commit
2e337d5ca0
@@ -19,7 +19,12 @@ import pkg_resources
|
||||
import re
|
||||
|
||||
from pip import req as pip_req
|
||||
from pip import util as pip_util
|
||||
|
||||
try:
|
||||
from pip import util as pip_util
|
||||
except ImportError:
|
||||
# pip >=6 changed this location for some reason...
|
||||
from pip import utils as pip_util
|
||||
|
||||
from anvil import log as logging
|
||||
from anvil import shell as sh
|
||||
|
||||
@@ -18,6 +18,7 @@ import glob
|
||||
import re
|
||||
import sys
|
||||
|
||||
from anvil.packaging.helpers import pip_helper
|
||||
from anvil import shell as sh
|
||||
from anvil import test
|
||||
from anvil import utils
|
||||
@@ -82,11 +83,22 @@ class TestTools(test.TestCase):
|
||||
pass
|
||||
return conflicts
|
||||
|
||||
def assertEquivalentRequirements(self, expected, created):
|
||||
self.assertEqual(len(expected), len(created))
|
||||
for req in created:
|
||||
self.assertIn(req, expected)
|
||||
|
||||
@parameterized.expand(load_examples())
|
||||
def test_example(self, _name, example):
|
||||
(stdout, stderr) = self._run_multipip(example['requirements'])
|
||||
stdout = stdout.strip()
|
||||
self.assertEqual(example['expected'], stdout)
|
||||
expected_normalized = []
|
||||
for line in example['expected'].strip().splitlines():
|
||||
expected_normalized.append(pip_helper.extract_requirement(line))
|
||||
parsed_normalized = []
|
||||
for line in stdout.strip().splitlines():
|
||||
parsed_normalized.append(pip_helper.extract_requirement(line))
|
||||
self.assertEquivalentRequirements(expected_normalized,
|
||||
parsed_normalized)
|
||||
if 'conflicts' in example:
|
||||
self.assertEqual(example['conflicts'],
|
||||
self._extract_conflicts(stderr))
|
||||
|
||||
Reference in New Issue
Block a user