summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2017-12-06 11:13:22 +0000
committerStephen Finucane <sfinucan@redhat.com>2017-12-06 11:32:44 +0000
commitec210af0f57e726c0bc3f897bc4c99542cf38882 (patch)
treefcbd077151a5b862233157c0202117375d1a5819
parentcd3e4f2949545389bd39d195e1556c3e5bf1d14a (diff)
downloadpbr-ec210af0f57e726c0bc3f897bc4c99542cf38882.tar.gz
trivial: Move packaging tests to test_packaging
There's a little bit of duplication going on here. Resolve this by moving tests that predominantly focus on FILE to tests/test_FILE. Change-Id: I29355155853e543d017db00c936bcdc88c1c97ad
-rw-r--r--pbr/tests/test_packaging.py114
-rw-r--r--pbr/tests/test_setup.py115
2 files changed, 114 insertions, 115 deletions
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index 9efcbd7..64f63ce 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -43,6 +43,7 @@ import email.errors
import imp
import os
import re
+import sys
import sysconfig
import tempfile
import textwrap
@@ -51,6 +52,7 @@ import fixtures
import mock
import pkg_resources
import six
+import testscenarios
import testtools
from testtools import matchers
import virtualenv
@@ -513,6 +515,118 @@ class TestNestedRequirements(base.BaseTestCase):
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:
+ fh.write("foo\nbar")
+ self.useFixture(
+ fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES',
+ self.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:
+ fh.write("foo\nbar")
+ self.useFixture(
+ fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES',
+ "no-such-file," + self.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_parse_requirements_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):
+ with open("requirements-py1.txt", "w") as fh:
+ fh.write("thisisatrap")
+ 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())
+
+
+class ParseRequirementsTestScenarios(base.BaseTestCase):
+
+ versioned_scenarios = [
+ ('non-versioned', {'versioned': False, 'expected': ['bar']}),
+ ('versioned', {'versioned': True, 'expected': ['bar>=1.2.3']})
+ ]
+
+ scenarios = [
+ ('normal', {'url': "foo\nbar", 'expected': ['foo', 'bar']}),
+ ('normal_with_comments', {
+ 'url': "# this is a comment\nfoo\n# and another one\nbar",
+ 'expected': ['foo', 'bar']}),
+ ('removes_index_lines', {'url': '-f foobar', 'expected': []}),
+ ]
+
+ scenarios = scenarios + testscenarios.multiply_scenarios([
+ ('ssh_egg_url', {'url': 'git+ssh://foo.com/zipball#egg=bar'}),
+ ('git_https_egg_url', {'url': 'git+https://foo.com/zipball#egg=bar'}),
+ ('http_egg_url', {'url': 'https://foo.com/zipball#egg=bar'}),
+ ], versioned_scenarios)
+
+ scenarios = scenarios + testscenarios.multiply_scenarios(
+ [
+ ('git_egg_url',
+ {'url': 'git://foo.com/zipball#egg=bar', 'name': 'bar'})
+ ], [
+ ('non-editable', {'editable': False}),
+ ('editable', {'editable': True}),
+ ],
+ versioned_scenarios)
+
+ def test_parse_requirements(self):
+ tmp_file = tempfile.NamedTemporaryFile()
+ req_string = self.url
+ if hasattr(self, 'editable') and self.editable:
+ req_string = ("-e %s" % req_string)
+ if hasattr(self, 'versioned') and self.versioned:
+ req_string = ("%s-1.2.3" % req_string)
+ with open(tmp_file.name, 'w') as fh:
+ fh.write(req_string)
+ self.assertEqual(self.expected,
+ packaging.parse_requirements([tmp_file.name]))
+
+
+class ParseDependencyLinksTest(base.BaseTestCase):
+
+ def setUp(self):
+ super(ParseDependencyLinksTest, self).setUp()
+ (fd, self.tmp_file) = tempfile.mkstemp(prefix="openstack",
+ suffix=".setup")
+
+ def test_parse_dependency_normal(self):
+ with open(self.tmp_file, "w") as fh:
+ fh.write("http://test.com\n")
+ self.assertEqual(
+ ["http://test.com"],
+ packaging.parse_dependency_links([self.tmp_file]))
+
+ def test_parse_dependency_with_git_egg_url(self):
+ with open(self.tmp_file, "w") as fh:
+ fh.write("-e git://foo.com/zipball#egg=bar")
+ self.assertEqual(
+ ["git://foo.com/zipball#egg=bar"],
+ packaging.parse_dependency_links([self.tmp_file]))
+
+
class TestVersions(base.BaseTestCase):
scenarios = [
diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py
index 0b9c81b..85d40eb 100644
--- a/pbr/tests/test_setup.py
+++ b/pbr/tests/test_setup.py
@@ -17,9 +17,6 @@
from __future__ import print_function
import os
-import sys
-import tempfile
-import testscenarios
try:
import cStringIO as io
@@ -446,115 +443,3 @@ class APIAutoDocTest(base.BaseTestCase):
self.assertTrue(
os.path.exists(
"contributor/api/fake_package.fake_private_module.rst"))
-
-
-class ParseRequirementsTestScenarios(base.BaseTestCase):
-
- versioned_scenarios = [
- ('non-versioned', {'versioned': False, 'expected': ['bar']}),
- ('versioned', {'versioned': True, 'expected': ['bar>=1.2.3']})
- ]
-
- scenarios = [
- ('normal', {'url': "foo\nbar", 'expected': ['foo', 'bar']}),
- ('normal_with_comments', {
- 'url': "# this is a comment\nfoo\n# and another one\nbar",
- 'expected': ['foo', 'bar']}),
- ('removes_index_lines', {'url': '-f foobar', 'expected': []}),
- ]
-
- scenarios = scenarios + testscenarios.multiply_scenarios([
- ('ssh_egg_url', {'url': 'git+ssh://foo.com/zipball#egg=bar'}),
- ('git_https_egg_url', {'url': 'git+https://foo.com/zipball#egg=bar'}),
- ('http_egg_url', {'url': 'https://foo.com/zipball#egg=bar'}),
- ], versioned_scenarios)
-
- scenarios = scenarios + testscenarios.multiply_scenarios(
- [
- ('git_egg_url',
- {'url': 'git://foo.com/zipball#egg=bar', 'name': 'bar'})
- ], [
- ('non-editable', {'editable': False}),
- ('editable', {'editable': True}),
- ],
- versioned_scenarios)
-
- def test_parse_requirements(self):
- tmp_file = tempfile.NamedTemporaryFile()
- req_string = self.url
- if hasattr(self, 'editable') and self.editable:
- req_string = ("-e %s" % req_string)
- if hasattr(self, 'versioned') and self.versioned:
- req_string = ("%s-1.2.3" % req_string)
- with open(tmp_file.name, 'w') as fh:
- fh.write(req_string)
- self.assertEqual(self.expected,
- packaging.parse_requirements([tmp_file.name]))
-
-
-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:
- fh.write("foo\nbar")
- self.useFixture(
- fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES',
- self.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:
- fh.write("foo\nbar")
- self.useFixture(
- fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES',
- "no-such-file," + self.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_parse_requirements_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):
- with open("requirements-py1.txt", "w") as fh:
- fh.write("thisisatrap")
- 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())
-
-
-class ParseDependencyLinksTest(base.BaseTestCase):
-
- def setUp(self):
- super(ParseDependencyLinksTest, self).setUp()
- (fd, self.tmp_file) = tempfile.mkstemp(prefix="openstack",
- suffix=".setup")
-
- def test_parse_dependency_normal(self):
- with open(self.tmp_file, "w") as fh:
- fh.write("http://test.com\n")
- self.assertEqual(
- ["http://test.com"],
- packaging.parse_dependency_links([self.tmp_file]))
-
- def test_parse_dependency_with_git_egg_url(self):
- with open(self.tmp_file, "w") as fh:
- fh.write("-e git://foo.com/zipball#egg=bar")
- self.assertEqual(
- ["git://foo.com/zipball#egg=bar"],
- packaging.parse_dependency_links([self.tmp_file]))