From cd83db9b13dad5e0f4af16a63b9b963bbd72e094 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Fri, 13 Aug 2010 15:24:22 +0200 Subject: [PATCH] [tests] add unit tests for .spec parsers --- molecule/settings.py | 6 +++++- tests/run | 4 ++-- tests/specs.py | 2 ++ tests/utils.py | 1 + tests/version.py | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/molecule/settings.py b/molecule/settings.py index eb46a1e..a00a901 100644 --- a/molecule/settings.py +++ b/molecule/settings.py @@ -146,7 +146,11 @@ class SpecPreprocessor: if split_line: expander = self.__builtin_expanders.get(split_line[0]) if expander is not None: - line = expander(line) + try: + line = expander(line) + except RuntimeError as err: + raise SpecPreprocessor.PreprocessorError( + "invalid preprocessor line: %s" % (err,)) lines += line return lines diff --git a/tests/run b/tests/run index 6726dbc..175a889 100755 --- a/tests/run +++ b/tests/run @@ -7,11 +7,11 @@ import unittest sys.path.insert(0,'.') sys.path.insert(0,'..') -from tests import version, utils +from tests import version, utils, specs, parsers rc = 0 # Add to the list the module to test -mods = [version, utils] +mods = [version, utils, specs, parsers] tests = [] for mod in mods: diff --git a/tests/specs.py b/tests/specs.py index 2e106a8..2183f04 100644 --- a/tests/specs.py +++ b/tests/specs.py @@ -18,6 +18,8 @@ class SpecsTest(unittest.TestCase): sys.stdout.write("%s ran\n" % (self,)) sys.stdout.flush() + + if __name__ == '__main__': unittest.main() raise SystemExit(0) diff --git a/tests/utils.py b/tests/utils.py index ab645a5..08d1ab1 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,6 +5,7 @@ sys.path.insert(0,'.') sys.path.insert(0,'..') import unittest import tempfile + from molecule.compat import get_stringtype from molecule.utils import md5sum, copy_dir, get_random_number, \ remove_path_sandbox, remove_path, mkdtemp, empty_dir, \ diff --git a/tests/version.py b/tests/version.py index 256d880..c984274 100644 --- a/tests/version.py +++ b/tests/version.py @@ -3,6 +3,7 @@ import sys sys.path.insert(0,'.') sys.path.insert(0,'..') import unittest + from molecule.compat import get_stringtype class VersionTest(unittest.TestCase):