Refactor system tests to live together in one package.

This commit is contained in:
Andrey Smirnov
2014-01-21 12:15:28 +04:00
parent 0f902ee74b
commit 362cdbcd57
9 changed files with 60 additions and 35 deletions
+3 -1
View File
@@ -23,4 +23,6 @@ _testmain.go
*.test *.test
coverage.html coverage.html
coverage*.out coverage*.out
*.pyc
+1 -1
View File
@@ -48,7 +48,7 @@ class BaseTest(object):
return string.Template(gold).substitute(os.environ) return string.Template(gold).substitute(os.environ)
def get_gold(self): 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()) return self.gold_processor(open(gold, "r").read())
def check_output(self): def check_output(self):
+30 -11
View File
@@ -1,9 +1,14 @@
#!/usr/bin/python #!/usr/local/bin/python
import glob import glob
import importlib import importlib
import os
import inspect
import sys import sys
from lib import BaseTest
from termcolor import colored
def run(): def run():
""" """
@@ -11,29 +16,43 @@ def run():
""" """
tests = glob.glob("t*_*") tests = glob.glob("t*_*")
fails = [] fails = []
numTests = numFailed = 0
for test in tests: for test in tests:
sys.stdout.write("%s..." % (test, ))
testModule = importlib.import_module(test) testModule = importlib.import_module(test)
t = testModule.Test()
try: for name in dir(testModule):
t.test() o = getattr(testModule, name)
except BaseException, e:
fails.append((test, t, e, testModule)) if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest):
sys.stdout.write("FAIL\n") continue
else:
sys.stdout.write("OK\n") 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: if len(fails) > 0:
print "\nFAILURES (%d):" % (len(fails), ) print "\nFAILURES (%d):" % (len(fails), )
for (test, t, e, testModule) in 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 "ERROR: %s" % (e, )
print "=" * 60 print "=" * 60
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
run() run()
+6 -2
View File
@@ -1,9 +1,13 @@
""" """
Test aptly version. Test aptly version
""" """
from lib import BaseTest from lib import BaseTest
class Test(BaseTest): class VersionTest(BaseTest):
"""
version should match
"""
runCmd = "aptly version" runCmd = "aptly version"
+20 -2
View File
@@ -1,15 +1,33 @@
""" """
Test config file generation. Test config file
""" """
import os import os
from lib import BaseTest from lib import BaseTest
class Test(BaseTest): class CreateConfigTest(BaseTest):
"""
new file is generated if missing
"""
runCmd = "aptly" runCmd = "aptly"
checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf") checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf")
check = BaseTest.check_file check = BaseTest.check_file
gold_processor = BaseTest.expand_environ gold_processor = BaseTest.expand_environ
prepare = BaseTest.prepare_remove_all 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()
-18
View File
@@ -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()