From: Loic Dachary Date: Wed, 11 Sep 2013 16:33:52 +0000 (+0200) Subject: pybind: unit tests for ceph_argparse::parse_json_funcsigs X-Git-Tag: v0.71~89^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f0bb2f02fa7c6acd7ee624f13ce6f172e3d68b0;p=ceph.git pybind: unit tests for ceph_argparse::parse_json_funcsigs 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 Reviewed-by: Joao Eduardo Luis Signed-off-by: Loic Dachary --- diff --git a/ceph.spec.in b/ceph.spec.in index 851ee7acfd50..a60d87ad8147 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -37,6 +37,7 @@ BuildRequires: perl BuildRequires: gdbm BuildRequires: pkgconfig BuildRequires: python +BuildRequires: python-nose BuildRequires: libaio-devel BuildRequires: libcurl-devel BuildRequires: libxml2-devel diff --git a/debian/control b/debian/control index 44ee725efd42..1aec592c9f89 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 6c127615b427..5b709d248a81 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -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 index 000000000000..4e091da3d9f1 --- /dev/null +++ b/src/test/pybind/test_ceph_argparse.py @@ -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 +# +# Author: Loic Dachary +# +# 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: