summaryrefslogtreecommitdiff
path: root/tests/test-json.py
diff options
context:
space:
mode:
authorTerry Wilson <twilson@redhat.com>2018-10-09 11:31:32 -0500
committerBen Pfaff <blp@ovn.org>2018-10-11 15:00:46 -0700
commita7be68a4d77791bbe02c37f7ad8ae60b02e5679e (patch)
tree07aa0cbcbcffa7f7a80905d20c627481b768d244 /tests/test-json.py
parent39cc92aa651e209e246d6e1547662ba0cafb9f1d (diff)
downloadopenvswitch-a7be68a4d77791bbe02c37f7ad8ae60b02e5679e.tar.gz
Test the Python C JSON extension
The C JSON parser was added quite a while ago, but unless you configure with --enable-shared and have the Python 2/3 development libraries installed, and the resulting python-ovs module installed, 'make check' won't actually test it. This patch changes Python-based tests to run from the $builddir/python directory and makes the tests configurable to use both JSON backends. There are some unicode failures in the C JSON extension that I left unfixed in this patch to make it easy to show run the new tests on broken code. The next patch in this set works around the issue. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
Diffstat (limited to 'tests/test-json.py')
-rw-r--r--tests/test-json.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/test-json.py b/tests/test-json.py
index 582aa720a..d0db43331 100644
--- a/tests/test-json.py
+++ b/tests/test-json.py
@@ -18,6 +18,7 @@ import codecs
import getopt
import sys
+from ovs.db import error
import ovs.json
import six
@@ -66,15 +67,26 @@ def main(argv):
sys.stderr = codecs.getwriter("utf-8")(sys.stderr)
try:
- options, args = getopt.gnu_getopt(argv[1:], '', ['multiple'])
+ options, args = getopt.gnu_getopt(argv[1:], 'j:',
+ ['multiple', 'json-parser'])
except getopt.GetoptError as geo:
sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
sys.exit(1)
multiple = False
+ ORIG_PARSER = ovs.json.PARSER
+ ovs.json.PARSER = ovs.json.PARSER_PY
for key, value in options:
if key == '--multiple':
multiple = True
+ elif key in ('-j', '--json-parser'):
+ if value == "python":
+ ovs.json.PARSER = ovs.json.PARSER_PY
+ elif value in ('C', 'c'):
+ if ORIG_PARSER != ovs.json.PARSER_C:
+ raise error.Error("C parser selected, but not compiled")
+ else:
+ ovs.json.PARSER = ovs.json.PARSER_C
else:
sys.stderr.write("%s: unhandled option %s\n" % (argv0, key))
sys.exit(1)