Merge "Python code refactorings."

This commit is contained in:
Jenkins 2013-11-13 01:06:48 +00:00 committed by Gerrit Code Review
commit a097b6d572
5 changed files with 12 additions and 11 deletions

View File

@ -17,7 +17,7 @@
import os import os
import sys import sys
from diskimage_builder.elements import main from diskimage_builder.element_dependencies import main
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

View File

View File

@ -18,7 +18,7 @@ import os
import fixtures import fixtures
import testtools import testtools
from diskimage_builder import elements from diskimage_builder import element_dependencies
data_dir = os.path.abspath( data_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'test-elements')) os.path.join(os.path.dirname(__file__), 'test-elements'))
@ -47,34 +47,35 @@ class TestElementDeps(testtools.TestCase):
_populate_element(self.element_dir, 'circular2', ['circular1']) _populate_element(self.element_dir, 'circular2', ['circular1'])
def test_non_transitive_deps(self): def test_non_transitive_deps(self):
result = elements.expand_dependencies( result = element_dependencies.expand_dependencies(
['requires-foo'], ['requires-foo'],
elements_dir=self.element_dir) elements_dir=self.element_dir)
self.assertEqual(set(['requires-foo', 'foo']), result) self.assertEqual(set(['requires-foo', 'foo']), result)
def test_missing_deps(self): def test_missing_deps(self):
self.assertRaises(SystemExit, elements.expand_dependencies, ['fake'], self.assertRaises(SystemExit,
element_dependencies.expand_dependencies, ['fake'],
self.element_dir) self.element_dir)
def test_transitive_deps(self): def test_transitive_deps(self):
result = elements.expand_dependencies( result = element_dependencies.expand_dependencies(
['requires-requires-foo'], elements_dir=self.element_dir) ['requires-requires-foo'], elements_dir=self.element_dir)
self.assertEqual(set(['requires-requires-foo', self.assertEqual(set(['requires-requires-foo',
'requires-foo', 'requires-foo',
'foo']), result) 'foo']), result)
def test_no_deps(self): def test_no_deps(self):
result = elements.expand_dependencies( result = element_dependencies.expand_dependencies(
['foo'], elements_dir=self.element_dir) ['foo'], elements_dir=self.element_dir)
self.assertEqual(set(['foo']), result) self.assertEqual(set(['foo']), result)
def test_self(self): def test_self(self):
result = elements.expand_dependencies( result = element_dependencies.expand_dependencies(
['self'], elements_dir=self.element_dir) ['self'], elements_dir=self.element_dir)
self.assertEqual(set(['self']), result) self.assertEqual(set(['self']), result)
def test_circular(self): def test_circular(self):
result = elements.expand_dependencies( result = element_dependencies.expand_dependencies(
['circular1'], elements_dir=self.element_dir) ['circular1'], elements_dir=self.element_dir)
self.assertEqual(set(['circular1', 'circular2']), result) self.assertEqual(set(['circular1', 'circular2']), result)
@ -83,8 +84,8 @@ class TestElements(testtools.TestCase):
def test_depends_on_env(self): def test_depends_on_env(self):
self.useFixture( self.useFixture(
fixtures.EnvironmentVariable('ELEMENTS_PATH', '/foo/bar')) 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): def test_env_not_set(self):
self.useFixture(fixtures.EnvironmentVariable('ELEMENTS_PATH', '')) self.useFixture(fixtures.EnvironmentVariable('ELEMENTS_PATH', ''))
self.assertRaises(Exception, elements.get_elements_dir, ()) self.assertRaises(Exception, element_dependencies.get_elements_dir, ())

View File

@ -30,7 +30,7 @@ def load_tests(loader, tests, pattern):
# http://bugs.python.org/issue11218 # http://bugs.python.org/issue11218
pattern = "test*.py" pattern = "test*.py"
this_dir = os.path.dirname(__file__) 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 # Make a fake elements top level package, as discovery doesn't let us
# override the python path. # override the python path.
package = StubPackage() package = StubPackage()