-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes mode dictionary creation, removal of 'mode' member from args_to_add dictionary and repositioning of the latter for the sake of consistency.
- Loading branch information
Showing
1 changed file
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,20 @@ | |
sys.exit(1) | ||
|
||
|
||
args_to_add = { | ||
'source': ['f', 's', 'h'], | ||
'dest': ['f', 's', 'h'], | ||
} | ||
|
||
|
||
# mode: source, dest, EOM, EOP | ||
modes = { | ||
's': ['s', 's', '\n', '\0'], | ||
'f': ['f', 'f', '\n', ''], | ||
'm': ['s', 's', '\n', ''], | ||
} | ||
|
||
|
||
class ProcessorStageArgsTestCase(unittest.TestCase): | ||
default_args = { | ||
'mode': 'f', | ||
|
@@ -103,11 +117,6 @@ def test_o(self): | |
self.check_args(args) | ||
|
||
|
||
args_to_add = { | ||
'source': ['f', 's', 'h'], | ||
'dest': ['f', 's', 'h'], | ||
'mode': ['f', 's', 'm'], | ||
} | ||
|
||
|
||
def add_arg(arg, val, short=False): | ||
|
@@ -125,10 +134,32 @@ def f(self): | |
setattr(ProcessorStageArgsTestCase, 'test_%s_%s' % (arg, val), f) | ||
|
||
|
||
def add_mode(val, short=False): | ||
def f(self): | ||
if short: | ||
self.stage.parse_args(['-m', val]) | ||
else: | ||
self.stage.parse_args(['--mode', val]) | ||
args = dict(self.default_args) | ||
args['mode'] = val | ||
args['source'] = modes[val][0] | ||
args['dest'] = modes[val][1] | ||
args['eom'] = modes[val][2] | ||
args['eop'] = modes[val][3] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mgolosova
Collaborator
|
||
self.check_args(args) | ||
if short: | ||
setattr(ProcessorStageArgsTestCase, 'test_m_%s' % (val), f) | ||
else: | ||
setattr(ProcessorStageArgsTestCase, 'test_mode_%s' % (val), f) | ||
|
||
|
||
for a in args_to_add: | ||
for v in args_to_add[a]: | ||
add_arg(a, v) | ||
add_arg(a, v, True) | ||
for m in modes: | ||
add_mode(m) | ||
add_mode(m, True) | ||
|
||
|
||
test_cases = ( | ||
|
If (one day) we need to extend number of parametersm involved into the
mode
definition, we will have to change bothmodes
hash and this piece of code. Or if we need more tests relying on themodes
hash, they all will have to reproduce the 4 lines above (and be changed if/when themode
definition changed).It could be simplified if done this way:
Why:
modes
you should not check the rest of the code to realize what the list of values means);mode
);modes
hash.Why not:
This "not" argument is Ok -- we need to make things working, first of all. But if you leave things "as is" for now, you should promise me that when you have to change the code / reuse
modes
, you will first make it more comfortable to use and to read.