Revision b57eaeb0 kamaki/cli/argument/test.py
b/kamaki/cli/argument/test.py | ||
---|---|---|
51 | 51 |
|
52 | 52 |
|
53 | 53 |
cnf_path = 'kamaki.cli.config.Config' |
54 |
arg_path = 'kamaki.cli.argument' |
|
54 | 55 |
|
55 | 56 |
|
56 | 57 |
class Argument(TestCase): |
... | ... | |
176 | 177 |
def setUp(self): |
177 | 178 |
argument._config_arg = argument.ConfigArgument('Recovered Path') |
178 | 179 |
|
179 |
@patch('kamaki.cli.argument.Argument.__init__')
|
|
180 |
@patch('%s.Argument.__init__' % arg_path)
|
|
180 | 181 |
def test___init__(self, arg): |
181 | 182 |
config, help, pname, default = 'config', 'help', 'pname', 'default' |
182 | 183 |
rca = argument.RuntimeConfigArgument(config, help, pname, default) |
... | ... | |
204 | 205 |
|
205 | 206 |
class FlagArgument(TestCase): |
206 | 207 |
|
207 |
@patch('kamaki.cli.argument.Argument.__init__')
|
|
208 |
@patch('%s.Argument.__init__' % arg_path)
|
|
208 | 209 |
def test___init__(self, arg): |
209 | 210 |
help, pname, default = 'help', 'pname', 'default' |
210 | 211 |
fa = argument.FlagArgument(help, pname, default) |
... | ... | |
214 | 215 |
|
215 | 216 |
class ValueArgument(TestCase): |
216 | 217 |
|
217 |
@patch('kamaki.cli.argument.Argument.__init__')
|
|
218 |
@patch('%s.Argument.__init__' % arg_path)
|
|
218 | 219 |
def test___init__(self, arg): |
219 | 220 |
help, pname, default = 'help', 'pname', 'default' |
220 | 221 |
fa = argument.ValueArgument(help, pname, default) |
... | ... | |
259 | 260 |
da._value = argument.dtm.strptime(date, format) |
260 | 261 |
self.assertEqual(da.formated, exp) |
261 | 262 |
|
262 |
@patch('kamaki.cli.argument.DateArgument.timestamp')
|
|
263 |
@patch('kamaki.cli.argument.DateArgument.format_date')
|
|
263 |
@patch('%s.DateArgument.timestamp' % arg_path)
|
|
264 |
@patch('%s.DateArgument.format_date' % arg_path)
|
|
264 | 265 |
def test_value(self, format_date, timestamp): |
265 | 266 |
da = argument.DateArgument(parsed_name='--date') |
266 | 267 |
self.assertTrue(isinstance(da.value, MagicMock)) |
... | ... | |
292 | 293 |
|
293 | 294 |
class KeyValueArgument(TestCase): |
294 | 295 |
|
295 |
@patch('kamaki.cli.argument.Argument.__init__')
|
|
296 |
@patch('%s.Argument.__init__' % arg_path)
|
|
296 | 297 |
def test___init__(self, init): |
297 | 298 |
help, pname, default = 'help', 'pname', 'default' |
298 | 299 |
kva = argument.KeyValueArgument(help, pname, default) |
... | ... | |
331 | 332 |
def start(): |
332 | 333 |
pass |
333 | 334 |
|
334 |
@patch('kamaki.cli.argument.FlagArgument.__init__')
|
|
335 |
@patch('%s.FlagArgument.__init__' % arg_path)
|
|
335 | 336 |
def test___init__(self, init): |
336 | 337 |
help, pname, default = 'help', '--progress', 'default' |
337 | 338 |
pba = argument.ProgressBarArgument(help, pname, default) |
... | ... | |
352 | 353 |
pba = argument.ProgressBarArgument(parsed_name='--progress') |
353 | 354 |
pba.value = None |
354 | 355 |
msg, msg_len = 'message', 40 |
355 |
with patch('kamaki.cli.argument.KamakiProgressBar.start') as start:
|
|
356 |
with patch('%s.KamakiProgressBar.start' % arg_path) as start:
|
|
356 | 357 |
pba.get_generator(msg, msg_len) |
357 | 358 |
self.assertTrue(isinstance(pba.bar, argument.KamakiProgressBar)) |
358 | 359 |
self.assertNotEqual(pba.bar.message, msg) |
... | ... | |
366 | 367 |
pba.value = None |
367 | 368 |
self.assertEqual(pba.finish(), None) |
368 | 369 |
pba.bar = argument.KamakiProgressBar() |
369 |
with patch('kamaki.cli.argument.KamakiProgressBar.finish') as finish:
|
|
370 |
with patch('%s.KamakiProgressBar.finish' % arg_path) as finish:
|
|
370 | 371 |
pba.finish() |
371 | 372 |
finish.assert_called_once() |
372 | 373 |
|
373 | 374 |
|
374 | 375 |
class ArgumentParseManager(TestCase): |
375 | 376 |
|
376 |
@patch('kamaki.cli.argument.ArgumentParseManager.parse')
|
|
377 |
@patch('kamaki.cli.argument.ArgumentParseManager.update_parser')
|
|
377 |
@patch('%s.ArgumentParseManager.parse' % arg_path)
|
|
378 |
@patch('%s.ArgumentParseManager.update_parser' % arg_path)
|
|
378 | 379 |
def test___init__(self, parse, update_parser): |
379 | 380 |
for arguments in (None, {'k1': 'v1', 'k2': 'v2'}): |
380 | 381 |
apm = argument.ArgumentParseManager('exe', arguments) |
... | ... | |
405 | 406 |
apm.syntax = 'some syntax' |
406 | 407 |
self.assertEqual(apm.syntax, 'some syntax') |
407 | 408 |
|
408 |
@patch('kamaki.cli.argument.ArgumentParseManager.update_parser')
|
|
409 |
@patch('%s.ArgumentParseManager.update_parser' % arg_path)
|
|
409 | 410 |
def test_arguments(self, update_parser): |
410 | 411 |
apm = argument.ArgumentParseManager('exe') |
411 | 412 |
assert_dicts_are_equal(self, apm.arguments, argument._arguments) |
... | ... | |
419 | 420 |
except Exception as e: |
420 | 421 |
self.assertTrue(isinstance(e, AssertionError)) |
421 | 422 |
|
422 |
@patch('kamaki.cli.argument.ArgumentParseManager.parse')
|
|
423 |
@patch('%s.ArgumentParseManager.parse' % arg_path)
|
|
423 | 424 |
def test_parsed(self, parse): |
424 | 425 |
apm = argument.ArgumentParseManager('exe') |
425 | 426 |
self.assertEqual(apm.parsed, None) |
... | ... | |
431 | 432 |
self.assertEqual(apm.parsed, exp + ' v2') |
432 | 433 |
self.assertEqual(parse.mock_calls, [call(), call()]) |
433 | 434 |
|
434 |
@patch('kamaki.cli.argument.ArgumentParseManager.parse')
|
|
435 |
@patch('%s.ArgumentParseManager.parse' % arg_path)
|
|
435 | 436 |
def test_unparsed(self, parse): |
436 | 437 |
apm = argument.ArgumentParseManager('exe') |
437 | 438 |
self.assertEqual(apm.unparsed, None) |
... | ... | |
443 | 444 |
self.assertEqual(apm.unparsed, exp + ' v2') |
444 | 445 |
self.assertEqual(parse.mock_calls, [call(), call()]) |
445 | 446 |
|
446 |
@patch('kamaki.cli.argument.Argument.update_parser') |
|
447 |
@patch('%s.Argument.update_parser' % arg_path |
|
448 |
) |
|
447 | 449 |
def test_update_parser(self, update_parser): |
448 | 450 |
apm = argument.ArgumentParseManager('exe') |
449 | 451 |
body_count = len(update_parser.mock_calls) |
... | ... | |
460 | 462 |
body_count = len(update_parser.mock_calls) |
461 | 463 |
self.assertEqual(body_count, exp + 2) |
462 | 464 |
|
465 |
def test_update_arguments(self): |
|
466 |
(inp, cor, exp) = ( |
|
467 |
{'k1': 'v1', 'k2': 'v3'}, {'k2': 'v2'}, {'k1': 'v1', 'k2': 'v2'}) |
|
468 |
apm = argument.ArgumentParseManager('exe') |
|
469 |
with patch( |
|
470 |
'%s.ArgumentParseManager.update_parser' % arg_path) as UP: |
|
471 |
apm.update_arguments(None) |
|
472 |
self.assertEqual(len(UP.mock_calls), 0) |
|
473 |
apm._arguments = inp |
|
474 |
apm.update_arguments(cor) |
|
475 |
assert_dicts_are_equal(self, apm.arguments, exp) |
|
476 |
UP.assert_called_once_with() |
|
477 |
|
|
478 |
def test_parse(self): |
|
479 |
raise errors.CLIUnimplemented() |
|
480 |
|
|
481 |
|
|
463 | 482 |
if __name__ == '__main__': |
464 | 483 |
from sys import argv |
465 | 484 |
from kamaki.cli.test import runTestCase |
Also available in: Unified diff