From dee69b181071b2e74fcad79f5419bcd717752c2f Mon Sep 17 00:00:00 2001 From: James Slagle Date: Tue, 12 Nov 2013 09:58:00 -0500 Subject: [PATCH] Python code refactorings. This commit refactors the python code in diskimage_builder slightly. This is in preparation for a larger review that adds more functionality to the python code, namely the ability to apply elements to the current system as opposed to a chroot. Further, the refactorings can stand on their own for better clarity. They include: - renaming elements.py to element_dependencies.py. Adds clarity about the purpose of this module. - updating other code for this rename. - move tests into a tests submodule. Change-Id: I5519cc52398e442b24e33802bae42070d64b0c1d --- bin/element-info | 2 +- .../{elements.py => element_dependencies.py} | 0 diskimage_builder/tests/__init__.py | 0 .../{ => tests}/test_elementdeps.py | 19 ++++++++++--------- .../{ => tests}/test_elements.py | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) rename diskimage_builder/{elements.py => element_dependencies.py} (100%) create mode 100644 diskimage_builder/tests/__init__.py rename diskimage_builder/{ => tests}/test_elementdeps.py (82%) rename diskimage_builder/{ => tests}/test_elements.py (96%) diff --git a/bin/element-info b/bin/element-info index 44f2f3e8..1bdf3c01 100755 --- a/bin/element-info +++ b/bin/element-info @@ -17,7 +17,7 @@ import os import sys -from diskimage_builder.elements import main +from diskimage_builder.element_dependencies import main sys.exit(main(sys.argv)) diff --git a/diskimage_builder/elements.py b/diskimage_builder/element_dependencies.py similarity index 100% rename from diskimage_builder/elements.py rename to diskimage_builder/element_dependencies.py diff --git a/diskimage_builder/tests/__init__.py b/diskimage_builder/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/diskimage_builder/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py similarity index 82% rename from diskimage_builder/test_elementdeps.py rename to diskimage_builder/tests/test_elementdeps.py index b1af6aba..fc99f0ba 100644 --- a/diskimage_builder/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -18,7 +18,7 @@ import os import fixtures import testtools -from diskimage_builder import elements +from diskimage_builder import element_dependencies data_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), 'test-elements')) @@ -47,34 +47,35 @@ class TestElementDeps(testtools.TestCase): _populate_element(self.element_dir, 'circular2', ['circular1']) def test_non_transitive_deps(self): - result = elements.expand_dependencies( + result = element_dependencies.expand_dependencies( ['requires-foo'], elements_dir=self.element_dir) self.assertEqual(set(['requires-foo', 'foo']), result) def test_missing_deps(self): - self.assertRaises(SystemExit, elements.expand_dependencies, ['fake'], + self.assertRaises(SystemExit, + element_dependencies.expand_dependencies, ['fake'], self.element_dir) def test_transitive_deps(self): - result = elements.expand_dependencies( + result = element_dependencies.expand_dependencies( ['requires-requires-foo'], elements_dir=self.element_dir) self.assertEqual(set(['requires-requires-foo', 'requires-foo', 'foo']), result) def test_no_deps(self): - result = elements.expand_dependencies( + result = element_dependencies.expand_dependencies( ['foo'], elements_dir=self.element_dir) self.assertEqual(set(['foo']), result) def test_self(self): - result = elements.expand_dependencies( + result = element_dependencies.expand_dependencies( ['self'], elements_dir=self.element_dir) self.assertEqual(set(['self']), result) def test_circular(self): - result = elements.expand_dependencies( + result = element_dependencies.expand_dependencies( ['circular1'], elements_dir=self.element_dir) self.assertEqual(set(['circular1', 'circular2']), result) @@ -83,8 +84,8 @@ class TestElements(testtools.TestCase): def test_depends_on_env(self): self.useFixture( fixtures.EnvironmentVariable('ELEMENTS_PATH', '/foo/bar')) - self.assertEqual('/foo/bar', elements.get_elements_dir()) + self.assertEqual('/foo/bar', element_dependencies.get_elements_dir()) def test_env_not_set(self): self.useFixture(fixtures.EnvironmentVariable('ELEMENTS_PATH', '')) - self.assertRaises(Exception, elements.get_elements_dir, ()) + self.assertRaises(Exception, element_dependencies.get_elements_dir, ()) diff --git a/diskimage_builder/test_elements.py b/diskimage_builder/tests/test_elements.py similarity index 96% rename from diskimage_builder/test_elements.py rename to diskimage_builder/tests/test_elements.py index fa6d9d24..b24fd99d 100644 --- a/diskimage_builder/test_elements.py +++ b/diskimage_builder/tests/test_elements.py @@ -30,7 +30,7 @@ def load_tests(loader, tests, pattern): # http://bugs.python.org/issue11218 pattern = "test*.py" this_dir = os.path.dirname(__file__) - elements_dir = os.path.join(this_dir, "..", "elements") + elements_dir = os.path.join(this_dir, "..", "..", "elements") # Make a fake elements top level package, as discovery doesn't let us # override the python path. package = StubPackage()