]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: unit tests for ceph_argparse::parse_json_funcsigs
authorLoic Dachary <loic@dachary.org>
Wed, 11 Sep 2013 16:33:52 +0000 (18:33 +0200)
committerLoic Dachary <loic@dachary.org>
Mon, 23 Sep 2013 21:46:43 +0000 (23:46 +0200)
Run parse_json_funcsigs against the builtin commands found
in mon/MonCommands.h. Although it does not provide for a full
validation, it will detect some degenerate cases.

It is expected to raise if a space is missing at the end of an option
specification ( see https://github.com/ceph/ceph/pull/585 ) and this
case is tested. New tests of the same kind can be added whenever an
undetected error is found. Ideally a validation function is implemented
and it would be updated ( with an associated test ) when a new
pathological case is found.

The json string given to parse_json_funcsigs is obtained from
the support program get_command_descriptions.

The python-nose dependencies are added to the build requirements in
debian/control and ceph.spec.in because make check should always be run
at built time.

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>
ceph.spec.in
debian/control
src/test/Makefile.am
src/test/pybind/test_ceph_argparse.py [new file with mode: 0755]

index 851ee7acfd509caac9b39d3d1a5084edcb131765..a60d87ad81471cf7edc791b08861ace37089b460 100644 (file)
@@ -37,6 +37,7 @@ BuildRequires:        perl
 BuildRequires: gdbm
 BuildRequires: pkgconfig
 BuildRequires: python
+BuildRequires: python-nose
 BuildRequires:  libaio-devel
 BuildRequires:  libcurl-devel
 BuildRequires:  libxml2-devel
index 44ee725efd4202901d505f86e1ba432551c15fd9..1aec592c9f891f4643862031940090a09c258632 100644 (file)
@@ -34,6 +34,7 @@ Build-Depends: autoconf,
                libxml2-dev,
                pkg-config,
                python (>= 2.6.6-3~),
+               python-nose,
                uuid-dev,
                yasm
 Standards-Version: 3.9.3
index 6c127615b42742ffb3682d241ab63a438aedc9be..5b709d248a81247f4404f6c9b3d9d0021f11a9fa 100644 (file)
@@ -546,6 +546,8 @@ unittest_texttable_LDADD = $(LIBCOMMON) $(UNITTEST_LDADD)
 unittest_texttable_CXXFLAGS = $(UNITTEST_CXXFLAGS)
 check_PROGRAMS += unittest_texttable
 
+check_SCRIPTS += test/pybind/test_ceph_argparse.py
+
 if WITH_RADOSGW
 ceph_test_cors_SOURCES = test/test_cors.cc
 ceph_test_cors_LDADD = \
diff --git a/src/test/pybind/test_ceph_argparse.py b/src/test/pybind/test_ceph_argparse.py
new file mode 100755 (executable)
index 0000000..4e091da
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/nosetests --nocapture
+# -*- mode:python; tab-width:4; indent-tabs-mode:t -*-
+# vim: ts=4 sw=4 smarttab expandtab
+#
+# Ceph - scalable distributed file system
+#
+# Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+#
+# Author: Loic Dachary <loic@dachary.org>
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+
+from nose.tools import eq_ as eq
+from nose.tools import *
+
+from ceph_argparse import validate_command, parse_json_funcsigs
+
+import os
+import re
+import json
+
+def get_command_descriptions(what):
+    buffer = os.popen("./get_command_descriptions " + "--" + what
+                                         + " 2>&1 | grep cmd000").read()
+    return re.sub(r'^.*?(\{.*\})', '\g<1>', buffer)
+
+def test_parse_json_funcsigs():
+    commands = get_command_descriptions("all")
+    cmd_json = parse_json_funcsigs(commands, 'cli')
+
+    # syntax error https://github.com/ceph/ceph/pull/585
+    commands = get_command_descriptions("pull585")
+    assert_raises(TypeError, parse_json_funcsigs, commands, 'cli')
+
+# Local Variables:
+# compile-command: "cd ../.. ; make -j4 && 
+#  PYTHONPATH=pybind nosetests --stop \
+#  test/pybind/test_ceph_argparse.py # test_ceph_argparse.py:TestOSD.test_rm"
+# End: