diff options
author | Zuul <zuul@review.openstack.org> | 2017-12-15 03:49:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-12-15 03:49:31 +0000 |
commit | b26b1355602afd92895b136aadc58970ce93d86b (patch) | |
tree | 2175a1373f55b024cc72bdfb3dadf57417668efb /pbr | |
parent | ae661b4a0ac068433b79d9562e9bc43ea89f9d90 (diff) | |
parent | 6c8455c8c53bd0be32e13b9ca4efad4e25015b5c (diff) | |
download | pbr-b26b1355602afd92895b136aadc58970ce93d86b.tar.gz |
Merge "tests: Increase coverage of requirements parsing"
Diffstat (limited to 'pbr')
-rw-r--r-- | pbr/tests/test_packaging.py | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index 64f63ce..526e12d 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -488,70 +488,75 @@ class TestPresenceOfGit(base.BaseTestCase): self.assertEqual(False, git._git_is_installed()) -class TestIndexInRequirements(base.BaseTestCase): - - def test_index_in_requirement(self): - tempdir = tempfile.mkdtemp() - requirements = os.path.join(tempdir, 'requirements.txt') - with open(requirements, 'w') as f: - f.write('-i https://myindex.local') - f.write(' --index-url https://myindex.local') - f.write(' --extra-index-url https://myindex.local') - result = packaging.parse_requirements([requirements]) - self.assertEqual([], result) - +class ParseRequirementsTest(base.BaseTestCase): -class TestNestedRequirements(base.BaseTestCase): + def test_empty_requirements(self): + actual = packaging.parse_requirements([]) + self.assertEqual([], actual) - def test_nested_requirement(self): + def test_default_requirements(self): + """Ensure default files used if no files provided.""" tempdir = tempfile.mkdtemp() requirements = os.path.join(tempdir, 'requirements.txt') - nested = os.path.join(tempdir, 'nested.txt') with open(requirements, 'w') as f: - f.write('-r ' + nested) - with open(nested, 'w') as f: f.write('pbr') - result = packaging.parse_requirements([requirements]) + # the defaults are relative to where pbr is called from so we need to + # override them. This is OK, however, as we want to validate that + # defaults are used - not what those defaults are + with mock.patch.object(packaging, 'REQUIREMENTS_FILES', ( + requirements,)): + result = packaging.parse_requirements() self.assertEqual(['pbr'], result) - -class ParseRequirementsTest(base.BaseTestCase): - - def setUp(self): - super(ParseRequirementsTest, self).setUp() - (fd, self.tmp_file) = tempfile.mkstemp(prefix='openstack', - suffix='.setup') - - def test_parse_requirements_override_with_env(self): - with open(self.tmp_file, 'w') as fh: + def test_override_with_env(self): + """Ensure environment variable used if no files provided.""" + _, tmp_file = tempfile.mkstemp(prefix='openstack', suffix='.setup') + with open(tmp_file, 'w') as fh: fh.write("foo\nbar") self.useFixture( - fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', - self.tmp_file)) + fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', tmp_file)) self.assertEqual(['foo', 'bar'], packaging.parse_requirements()) - def test_parse_requirements_override_with_env_multiple_files(self): - with open(self.tmp_file, 'w') as fh: + def test_override_with_env_multiple_files(self): + _, tmp_file = tempfile.mkstemp(prefix='openstack', suffix='.setup') + with open(tmp_file, 'w') as fh: fh.write("foo\nbar") self.useFixture( fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', - "no-such-file," + self.tmp_file)) + "no-such-file," + tmp_file)) self.assertEqual(['foo', 'bar'], packaging.parse_requirements()) - def test_get_requirement_from_file_empty(self): - actual = packaging.get_reqs_from_files([]) - self.assertEqual([], actual) + def test_index_present(self): + tempdir = tempfile.mkdtemp() + requirements = os.path.join(tempdir, 'requirements.txt') + with open(requirements, 'w') as f: + f.write('-i https://myindex.local') + f.write(' --index-url https://myindex.local') + f.write(' --extra-index-url https://myindex.local') + result = packaging.parse_requirements([requirements]) + self.assertEqual([], result) + + def test_nested_requirements(self): + tempdir = tempfile.mkdtemp() + requirements = os.path.join(tempdir, 'requirements.txt') + nested = os.path.join(tempdir, 'nested.txt') + with open(requirements, 'w') as f: + f.write('-r ' + nested) + with open(nested, 'w') as f: + f.write('pbr') + result = packaging.parse_requirements([requirements]) + self.assertEqual(['pbr'], result) - def test_parse_requirements_python_version(self): + def test_python_version(self): with open("requirements-py%d.txt" % sys.version_info[0], "w") as fh: fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz") self.assertEqual(['foobar', 'foobaz'], packaging.parse_requirements()) - def test_parse_requirements_right_python_version(self): + def test_python_version_multiple_options(self): with open("requirements-py1.txt", "w") as fh: fh.write("thisisatrap") with open("requirements-py%d.txt" % sys.version_info[0], @@ -609,8 +614,8 @@ class ParseDependencyLinksTest(base.BaseTestCase): def setUp(self): super(ParseDependencyLinksTest, self).setUp() - (fd, self.tmp_file) = tempfile.mkstemp(prefix="openstack", - suffix=".setup") + _, self.tmp_file = tempfile.mkstemp(prefix="openstack", + suffix=".setup") def test_parse_dependency_normal(self): with open(self.tmp_file, "w") as fh: |