mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
Refactor system tests to live together in one package.
This commit is contained in:
+1
-1
@@ -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):
|
||||
|
||||
+30
-11
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user