Merge "Prevent silent failure of element-info:"

This commit is contained in:
Jenkins 2013-02-19 04:52:04 +00:00 committed by Gerrit Code Review
commit e4957e37a9
3 changed files with 15 additions and 4 deletions

View File

@ -20,9 +20,8 @@ import sys
def get_elements_dir():
if 'ELEMENTS_DIR' not in os.environ:
return os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'elements'))
if not os.environ.get('ELEMENTS_DIR'):
raise Exception("$ELEMENTS_DIR must be set.")
return os.environ['ELEMENTS_DIR']

View File

@ -16,9 +16,10 @@
import os
from testtools import TestCase
from fixtures import Fixture, TempDir
from fixtures import Fixture, EnvironmentVariable, TempDir
from diskimage_builder.elements import expand_dependencies
from diskimage_builder.elements import get_elements_dir
data_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'test-elements'))
@ -72,3 +73,13 @@ class TestElementDeps(TestCase):
result = expand_dependencies(['circular1'],
elements_dir=self.element_dir)
self.assertEquals(set(['circular1', 'circular2']), result)
class TestElements(TestCase):
def test_depends_on_env(self):
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', '/foo/bar'))
self.assertEquals('/foo/bar', get_elements_dir())
def test_env_not_set(self):
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', ''))
self.assertRaises(Exception, get_elements_dir, ())

View File

@ -22,6 +22,7 @@ class StubPackage:
pass
# load all tests from /elements/*/tests/ dirs.
# conceptually load_tests should be in __init__, but see
# http://bugs.python.org/issue16662 instead. So, its here in test_elements.py
def load_tests(loader, tests, pattern):