diff options
author | Loic Dachary <loic@dachary.org> | 2013-09-15 17:19:41 +0200 |
---|---|---|
committer | Loic Dachary <loic@dachary.org> | 2013-09-23 23:46:44 +0200 |
commit | 1d54754c48c76cc9324c6ea83c0f17987a657fc4 (patch) | |
tree | 60676bf6b675d061d0a4709cadf43db7c5f53d0c | |
parent | f9c7bc697ce99479ecbcb47571e416ceb53d6bf3 (diff) | |
download | ceph-1d54754c48c76cc9324c6ea83c0f17987a657fc4.tar.gz |
pybind: ceph_argparse unit tests foundations
The general idea is to have a series of commands, in the same order as
they show in mon/MonCommands.h, as if they were input to the ceph
client. For each command a valid combination is verified. And at least
one validation error is checked to produce a validation error. For
instance:
['pg', 'stat']
is a valid command and the validate_command function is expected to
return a value that is not None or {}. The command
['pg', 'stat', 'toomany' ]
is also given to validate_command to check that an error occurs when
an extra argument is given.
The TestArparse class implements a few methods to reduce the verbosity
of the tests. It does not provide many methods : only those that
significantly reduce the verbosity have been implemented. The drawback
of writing too many convenience methods is that they are more difficult
to read and maintain.
The signature dictionary is made a global variable so that
it is only extracted once for all classes. It is immutable.
http://tracker.ceph.com/issues/6274 refs #6274
Reviewed-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Joao Eduardo Luis <joao.luis@inktank.com>
Signed-off-by: Loic Dachary <loic@dachary.org>
-rwxr-xr-x | src/test/pybind/test_ceph_argparse.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/pybind/test_ceph_argparse.py b/src/test/pybind/test_ceph_argparse.py index 4e091da3d9f..b5261f61a1f 100755 --- a/src/test/pybind/test_ceph_argparse.py +++ b/src/test/pybind/test_ceph_argparse.py @@ -36,6 +36,54 @@ def test_parse_json_funcsigs(): commands = get_command_descriptions("pull585") assert_raises(TypeError, parse_json_funcsigs, commands, 'cli') +sigdict = parse_json_funcsigs(get_command_descriptions("all"), 'cli') + + +class TestArgparse: + + def assert_valid_command(self, args): + result = validate_command(sigdict, args) + assert_not_in(result, [None, {}]) + + def check_1_natural_arg(self, prefix, command): + self.assert_valid_command([prefix, command, '1']) + assert_equal({}, validate_command(sigdict, [prefix, command])) + assert_equal({}, validate_command(sigdict, [prefix, command, '-1'])) + assert_equal({}, validate_command(sigdict, [prefix, command, '1', + '1'])) + + def check_0_or_1_natural_arg(self, prefix, command): + self.assert_valid_command([prefix, command, '1']) + self.assert_valid_command([prefix, command]) + assert_equal({}, validate_command(sigdict, [prefix, command, '-1'])) + assert_equal({}, validate_command(sigdict, [prefix, command, '1', + '1'])) + + def check_1_string_arg(self, prefix, command): + assert_equal({}, validate_command(sigdict, [prefix, command])) + self.assert_valid_command([prefix, command, 'string']) + assert_equal({}, validate_command(sigdict, [prefix, + command, + 'string', + 'toomany'])) + + def check_1_or_more_string_args(self, prefix, command): + assert_equal({}, validate_command(sigdict, [prefix, + command])) + self.assert_valid_command([prefix, + command, + 'string']) + self.assert_valid_command([prefix, + command, + 'string', + 'more string']) + + def check_no_arg(self, prefix, command): + self.assert_valid_command([prefix, + command]) + assert_equal({}, validate_command(sigdict, [prefix, + command, + 'toomany'])) # Local Variables: # compile-command: "cd ../.. ; make -j4 && # PYTHONPATH=pybind nosetests --stop \ |