summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--tests/command.py90
-rw-r--r--tests/tmp/.keepme1
3 files changed, 59 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 4cd3914..0e05adc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.py[co]
/.ropeproject
/tests/lon-test/
+/tests/tmp/
diff --git a/tests/command.py b/tests/command.py
index 981f106..fa469d0 100644
--- a/tests/command.py
+++ b/tests/command.py
@@ -6,6 +6,8 @@
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
import unittest
+from os.path import dirname, join
+from os import remove
#from pprint import pprint
import _bootstrap # known W402, required
@@ -27,57 +29,79 @@ from clufter.utils import apply_preserving_depth, \
class ChainResolve(unittest.TestCase):
def testShapeAndProtocolMatch(self):
-
+ from tempfile import mktemp
filters = dict(
ccs2ccsflat=ccs2ccsflat(ccs, ccsflat),
ccsflat2pcs=ccsflat2pcs(ccsflat, pcs),
ccs2coroxml=ccs2coroxml(ccs, coroxml),
)
+ testfile = join(dirname(__file__), 'empty.conf')
+ testoutput = mktemp(prefix='out', suffix='.conf',
+ dir=join(dirname(__file__), 'tmp'))
- @Command.deco('ccs2ccsflat', ('ccsflat2pcs', 'ccs2coroxml'))
- def cmd_chain_match(input='.in', output='.out', coro='.coro'):
+ @Command.deco(('ccs2ccsflat',
+ 'ccsflat2pcs', 'ccs2coroxml'))
+ def cmd_chain_match_01(cmd_ctxt,
+ input=testfile, output=testoutput, coro='.coro'):
return ('file', input), (('file', output), ('file', coro))
- @Command.deco('ccs2ccsflat')
- def cmd_chain_nonmatch_01(input='.in', output='.out', coro='.coro'):
+ @Command.deco(('ccs2ccsflat'))
+ def cmd_chain_match_02(cmd_ctxt,
+ input=testfile, output=testoutput, coro='.coro'):
+ return ('file', input), ('file', output)
+ @Command.deco(('ccs2ccsflat'))
+ def cmd_chain_nonmatch_01(cmd_ctxt,
+ input=testfile, output=testoutput,
+ coro='.coro'):
return ('file', input), (('file', output), ('file', coro))
- @Command.deco('ccs2ccsflat',
- ('ccsflat2pcs', 'ccs2coroxml', 'ccs2coroxml'))
- def cmd_chain_nonmatch_02(input='.in', output='.out', coro='.coro'):
+ @Command.deco(('ccs2ccsflat',
+ 'ccsflat2pcs', 'ccs2coroxml', 'ccs2coroxml'))
+ def cmd_chain_nonmatch_02(cmd_ctxt,
+ input=testfile, output=testoutput,
+ coro='.coro'):
return ('file', input), (('file', output), ('file', coro))
# malformed protocol name
- @Command.deco('ccs2ccsflat', ('ccsflat2pcs', 'ccs2coroxml'))
- def cmd_chain_nonmatch_03(input='.in', output='.out', coro='.coro'):
+ @Command.deco(('ccs2ccsflat',
+ 'ccsflat2pcs', 'ccs2coroxml'))
+ def cmd_chain_nonmatch_03(cmd_ctxt,
+ input=testfile, output=testoutput,
+ coro='.coro'):
return ('file', input), (('file', output), ('life', coro))
- cmd_classes = (cmd_chain_match, cmd_chain_nonmatch_01,
- cmd_chain_nonmatch_02,
- cmd_chain_nonmatch_03)
- cmd_names = map(lambda x: x.name, cmd_classes)
- commands = {}
- for cmd_cls, cmd_name in zip(cmd_classes, cmd_names):
+ cmd_classes = (cmd_chain_match_01,
+ cmd_chain_match_02,
+ cmd_chain_nonmatch_01,
+ cmd_chain_nonmatch_02,
+ cmd_chain_nonmatch_03
+ )
+ split = cmd_classes.index(cmd_chain_nonmatch_01)
+ for i, cmd_cls in enumerate(cmd_classes):
res_input = cmd_cls.filter_chain
res_output = apply_preserving_depth(filters.get)(res_input)
if apply_aggregation_preserving_depth(all)(res_output):
#log.debug("resolve at `{0}' command: `{1}' -> {2}"
- # .format(cmd_name, repr(res_input), repr(res_output)))
- commands[cmd_name] = cmd_cls(*res_output)
+ # .format(cmd_cls.name, repr(res_input), repr(res_output)))
+ try:
+ cmd = cmd_cls(*res_output)
+ cmd({}, [])
+ except CommandError as e:
+ print "{0}: {1}".format(cmd_cls.name, e)
+ self.assertFalse(i < split)
+ except Exception as e:
+ print "{0}: {1}".format(cmd_cls.name, e)
+ raise
+ self.assertTrue(i < split)
+ else:
+ self.assertTrue(i < split)
+ try:
+ with open(testfile) as src, open(testoutput) as dst:
+ #self.assertEqual(src.read(), dst.read())
+ pass
+ except IOError:
+ pass
+ else:
+ remove(testoutput)
continue
- match, nonmatches = head_tail(cmd_names)
- try:
- commands[match]({}, [])
- except Exception as e:
- print "{0}: {1}".format(match, e)
self.assertTrue(False)
- else:
- self.assertTrue(True)
- for nonmatch in nonmatches:
- try:
- commands[nonmatch]({}, [])
- except CommandError as e:
- print "{0}: {1}".format(nonmatch, e)
- self.assertTrue(True)
- else:
- self.assertTrue(False)
if __name__ == '__main__':
diff --git a/tests/tmp/.keepme b/tests/tmp/.keepme
new file mode 100644
index 0000000..06f3797
--- /dev/null
+++ b/tests/tmp/.keepme
@@ -0,0 +1 @@
+directory to store temporary files in the testruns