1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# -*- coding: UTF-8 -*-
# Copyright 2015 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""Testing command"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
from _shared import empty_opts
from os.path import join, dirname as d; execfile(join(d(d((__file__))), '_go'))
from unittest import TestCase
from os.path import dirname, join
from os import remove, stat
#from pprint import pprint
from .command import Command, CommandError
from .filter_manager import FilterManager
from .format import formats
formats = formats.plugins
class ChainResolve(TestCase):
def testShapeAndProtocolMatch(self):
filters = FilterManager.init_lookup('ccs2ccsflat',
'ccsflat2cibprelude',
'ccs2needlexml',
ext_plugins=False).plugins
from tempfile import mktemp
testfile = join(dirname(__file__), 'empty.conf')
testoutput = mktemp(prefix='out', suffix='.conf',
dir=join(dirname(__file__), 'tmp'))
@Command.deco(('ccs2ccsflat',
('ccsflat2cibprelude'),
('ccs2needlexml')))
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_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',
('ccsflat2cibprelude'),
('ccs2needlexml'),
('ccs2needlexml')))
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',
('ccsflat2cibprelude'),
('ccs2needlexml')))
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_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):
try:
ret = cmd_cls(filters)(empty_opts, ()) # no opts/args
self.assertTrue(ret is not None)
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)
self.assertTrue(i < split)
raise
else:
self.assertTrue(i < split)
# also test non-zero-size output whe
self.assertTrue(stat(testoutput).st_size > 0)
remove(testoutput)
continue
from os.path import join, dirname as d; execfile(join(d(__file__), '_gone'))
|