diff --git a/.gitignore b/.gitignore index a15083e3..7a8d3eef 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ _testmain.go *.test coverage.html -coverage*.out \ No newline at end of file +coverage*.out + +*.pyc diff --git a/system/lib.py b/system/lib.py index 66b90a73..a682a6fb 100644 --- a/system/lib.py +++ b/system/lib.py @@ -48,7 +48,7 @@ class BaseTest(object): return string.Template(gold).substitute(os.environ) def get_gold(self): - gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), "gold") + gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__ + "_gold") return self.gold_processor(open(gold, "r").read()) def check_output(self): diff --git a/system/run.py b/system/run.py index cae119f9..a67b017d 100755 --- a/system/run.py +++ b/system/run.py @@ -1,9 +1,14 @@ -#!/usr/bin/python +#!/usr/local/bin/python import glob import importlib +import os +import inspect import sys +from lib import BaseTest +from termcolor import colored + def run(): """ @@ -11,29 +16,43 @@ def run(): """ tests = glob.glob("t*_*") fails = [] + numTests = numFailed = 0 for test in tests: - sys.stdout.write("%s..." % (test, )) testModule = importlib.import_module(test) - t = testModule.Test() - try: - t.test() - except BaseException, e: - fails.append((test, t, e, testModule)) - sys.stdout.write("FAIL\n") - else: - sys.stdout.write("OK\n") + for name in dir(testModule): + o = getattr(testModule, name) + + if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest): + continue + + t = o() + numTests += 1 + + sys.stdout.write("%s:%s... " % (test, o.__name__)) + + try: + t.test() + except BaseException, e: + numFailed += 1 + fails.append((test, t, e, testModule)) + sys.stdout.write("FAIL\n") + else: + sys.stdout.write(colored("OK\n", color="green")) + + print "TESTS: %d SUCCESS: %d FAIL: %d" % (numTests, numTests - numFailed, numFailed) if len(fails) > 0: print "\nFAILURES (%d):" % (len(fails), ) for (test, t, e, testModule) in fails: - print "%s: %s" % (test, testModule.__doc__.strip()) + print "%s:%s %s" % (test, t.__class__.__name__, testModule.__doc__.strip() + ": " + t.__doc__.strip()) print "ERROR: %s" % (e, ) print "=" * 60 if __name__ == "__main__": + os.chdir(os.path.realpath(os.path.dirname(sys.argv[0]))) run() diff --git a/system/t01_version/gold b/system/t01_version/VersionTest_gold similarity index 100% rename from system/t01_version/gold rename to system/t01_version/VersionTest_gold diff --git a/system/t01_version/__init__.py b/system/t01_version/__init__.py index 358f0496..ca7276a9 100644 --- a/system/t01_version/__init__.py +++ b/system/t01_version/__init__.py @@ -1,9 +1,13 @@ """ -Test aptly version. +Test aptly version """ from lib import BaseTest -class Test(BaseTest): +class VersionTest(BaseTest): + """ + version should match + """ + runCmd = "aptly version" diff --git a/system/t03_bad_config/gold b/system/t02_config/BadConfigTest_gold similarity index 100% rename from system/t03_bad_config/gold rename to system/t02_config/BadConfigTest_gold diff --git a/system/t02_config/gold b/system/t02_config/CreateConfigTest_gold similarity index 100% rename from system/t02_config/gold rename to system/t02_config/CreateConfigTest_gold diff --git a/system/t02_config/__init__.py b/system/t02_config/__init__.py index 7a6ae465..002bf1c0 100644 --- a/system/t02_config/__init__.py +++ b/system/t02_config/__init__.py @@ -1,15 +1,33 @@ """ -Test config file generation. +Test config file """ import os from lib import BaseTest -class Test(BaseTest): +class CreateConfigTest(BaseTest): + """ + new file is generated if missing + """ runCmd = "aptly" checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf") check = BaseTest.check_file gold_processor = BaseTest.expand_environ prepare = BaseTest.prepare_remove_all + + +class BadConfigTest(BaseTest): + """ + broken config file + """ + runCmd = "aptly" + expectedCode = 1 + + def prepare(self): + self.prepare_remove_all() + + f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w") + f.write("{some crap") + f.close() diff --git a/system/t03_bad_config/__init__.py b/system/t03_bad_config/__init__.py deleted file mode 100644 index 2dde4233..00000000 --- a/system/t03_bad_config/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -Start with bad config. -""" - -import os -from lib import BaseTest - - -class Test(BaseTest): - runCmd = "aptly" - expectedCode = 1 - - def prepare(self): - self.prepare_remove_all() - - f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w") - f.write("{some crap") - f.close()