summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pbr/tests/test_packaging.py85
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):
488 self.assertEqual(False, git._git_is_installed()) 488 self.assertEqual(False, git._git_is_installed())
489 489
490 490
491class TestIndexInRequirements(base.BaseTestCase): 491class ParseRequirementsTest(base.BaseTestCase):
492
493 def test_index_in_requirement(self):
494 tempdir = tempfile.mkdtemp()
495 requirements = os.path.join(tempdir, 'requirements.txt')
496 with open(requirements, 'w') as f:
497 f.write('-i https://myindex.local')
498 f.write(' --index-url https://myindex.local')
499 f.write(' --extra-index-url https://myindex.local')
500 result = packaging.parse_requirements([requirements])
501 self.assertEqual([], result)
502
503 492
504class TestNestedRequirements(base.BaseTestCase): 493 def test_empty_requirements(self):
494 actual = packaging.parse_requirements([])
495 self.assertEqual([], actual)
505 496
506 def test_nested_requirement(self): 497 def test_default_requirements(self):
498 """Ensure default files used if no files provided."""
507 tempdir = tempfile.mkdtemp() 499 tempdir = tempfile.mkdtemp()
508 requirements = os.path.join(tempdir, 'requirements.txt') 500 requirements = os.path.join(tempdir, 'requirements.txt')
509 nested = os.path.join(tempdir, 'nested.txt')
510 with open(requirements, 'w') as f: 501 with open(requirements, 'w') as f:
511 f.write('-r ' + nested)
512 with open(nested, 'w') as f:
513 f.write('pbr') 502 f.write('pbr')
514 result = packaging.parse_requirements([requirements]) 503 # the defaults are relative to where pbr is called from so we need to
504 # override them. This is OK, however, as we want to validate that
505 # defaults are used - not what those defaults are
506 with mock.patch.object(packaging, 'REQUIREMENTS_FILES', (
507 requirements,)):
508 result = packaging.parse_requirements()
515 self.assertEqual(['pbr'], result) 509 self.assertEqual(['pbr'], result)
516 510
517 511 def test_override_with_env(self):
518class ParseRequirementsTest(base.BaseTestCase): 512 """Ensure environment variable used if no files provided."""
519 513 _, tmp_file = tempfile.mkstemp(prefix='openstack', suffix='.setup')
520 def setUp(self): 514 with open(tmp_file, 'w') as fh:
521 super(ParseRequirementsTest, self).setUp()
522 (fd, self.tmp_file) = tempfile.mkstemp(prefix='openstack',
523 suffix='.setup')
524
525 def test_parse_requirements_override_with_env(self):
526 with open(self.tmp_file, 'w') as fh:
527 fh.write("foo\nbar") 515 fh.write("foo\nbar")
528 self.useFixture( 516 self.useFixture(
529 fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', 517 fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', tmp_file))
530 self.tmp_file))
531 self.assertEqual(['foo', 'bar'], 518 self.assertEqual(['foo', 'bar'],
532 packaging.parse_requirements()) 519 packaging.parse_requirements())
533 520
534 def test_parse_requirements_override_with_env_multiple_files(self): 521 def test_override_with_env_multiple_files(self):
535 with open(self.tmp_file, 'w') as fh: 522 _, tmp_file = tempfile.mkstemp(prefix='openstack', suffix='.setup')
523 with open(tmp_file, 'w') as fh:
536 fh.write("foo\nbar") 524 fh.write("foo\nbar")
537 self.useFixture( 525 self.useFixture(
538 fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', 526 fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES',
539 "no-such-file," + self.tmp_file)) 527 "no-such-file," + tmp_file))
540 self.assertEqual(['foo', 'bar'], 528 self.assertEqual(['foo', 'bar'],
541 packaging.parse_requirements()) 529 packaging.parse_requirements())
542 530
543 def test_get_requirement_from_file_empty(self): 531 def test_index_present(self):
544 actual = packaging.get_reqs_from_files([]) 532 tempdir = tempfile.mkdtemp()
545 self.assertEqual([], actual) 533 requirements = os.path.join(tempdir, 'requirements.txt')
534 with open(requirements, 'w') as f:
535 f.write('-i https://myindex.local')
536 f.write(' --index-url https://myindex.local')
537 f.write(' --extra-index-url https://myindex.local')
538 result = packaging.parse_requirements([requirements])
539 self.assertEqual([], result)
540
541 def test_nested_requirements(self):
542 tempdir = tempfile.mkdtemp()
543 requirements = os.path.join(tempdir, 'requirements.txt')
544 nested = os.path.join(tempdir, 'nested.txt')
545 with open(requirements, 'w') as f:
546 f.write('-r ' + nested)
547 with open(nested, 'w') as f:
548 f.write('pbr')
549 result = packaging.parse_requirements([requirements])
550 self.assertEqual(['pbr'], result)
546 551
547 def test_parse_requirements_python_version(self): 552 def test_python_version(self):
548 with open("requirements-py%d.txt" % sys.version_info[0], 553 with open("requirements-py%d.txt" % sys.version_info[0],
549 "w") as fh: 554 "w") as fh:
550 fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz") 555 fh.write("# this is a comment\nfoobar\n# and another one\nfoobaz")
551 self.assertEqual(['foobar', 'foobaz'], 556 self.assertEqual(['foobar', 'foobaz'],
552 packaging.parse_requirements()) 557 packaging.parse_requirements())
553 558
554 def test_parse_requirements_right_python_version(self): 559 def test_python_version_multiple_options(self):
555 with open("requirements-py1.txt", "w") as fh: 560 with open("requirements-py1.txt", "w") as fh:
556 fh.write("thisisatrap") 561 fh.write("thisisatrap")
557 with open("requirements-py%d.txt" % sys.version_info[0], 562 with open("requirements-py%d.txt" % sys.version_info[0],
@@ -609,8 +614,8 @@ class ParseDependencyLinksTest(base.BaseTestCase):
609 614
610 def setUp(self): 615 def setUp(self):
611 super(ParseDependencyLinksTest, self).setUp() 616 super(ParseDependencyLinksTest, self).setUp()
612 (fd, self.tmp_file) = tempfile.mkstemp(prefix="openstack", 617 _, self.tmp_file = tempfile.mkstemp(prefix="openstack",
613 suffix=".setup") 618 suffix=".setup")
614 619
615 def test_parse_dependency_normal(self): 620 def test_parse_dependency_normal(self):
616 with open(self.tmp_file, "w") as fh: 621 with open(self.tmp_file, "w") as fh: