aboutsummaryrefslogtreecommitdiff
path: root/contrib/libucl/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libucl/python/tests')
-rw-r--r--contrib/libucl/python/tests/__init__.py0
-rw-r--r--contrib/libucl/python/tests/compat.py8
-rw-r--r--contrib/libucl/python/tests/test_dump.py66
-rw-r--r--contrib/libucl/python/tests/test_example.py59
-rw-r--r--contrib/libucl/python/tests/test_load.py122
-rw-r--r--contrib/libucl/python/tests/test_validation.py50
6 files changed, 0 insertions, 305 deletions
diff --git a/contrib/libucl/python/tests/__init__.py b/contrib/libucl/python/tests/__init__.py
deleted file mode 100644
index e69de29bb2d1..000000000000
--- a/contrib/libucl/python/tests/__init__.py
+++ /dev/null
diff --git a/contrib/libucl/python/tests/compat.py b/contrib/libucl/python/tests/compat.py
deleted file mode 100644
index 50138262e9b7..000000000000
--- a/contrib/libucl/python/tests/compat.py
+++ /dev/null
@@ -1,8 +0,0 @@
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-# Python 2.7 - 3.1
-if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
diff --git a/contrib/libucl/python/tests/test_dump.py b/contrib/libucl/python/tests/test_dump.py
deleted file mode 100644
index 369241468509..000000000000
--- a/contrib/libucl/python/tests/test_dump.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from .compat import unittest
-import ucl
-import sys
-
-class DumpTest(unittest.TestCase):
- def test_no_args(self):
- with self.assertRaises(TypeError):
- ucl.dump()
-
- def test_none(self):
- self.assertEqual(ucl.dump(None), None)
-
- def test_null(self):
- data = { "a" : None }
- valid = "a = null;\n"
- self.assertEqual(ucl.dump(data), valid)
-
- def test_int(self):
- data = { "a" : 1 }
- valid = "a = 1;\n"
- self.assertEqual(ucl.dump(data), valid)
-
- def test_nested_int(self):
- data = { "a" : { "b" : 1 } }
- valid = "a {\n b = 1;\n}\n"
- self.assertEqual(ucl.dump(data), valid)
-
- def test_int_array(self):
- data = { "a" : [1,2,3,4] }
- valid = "a [\n 1,\n 2,\n 3,\n 4,\n]\n"
- self.assertEqual(ucl.dump(data), valid)
-
- def test_str(self):
- data = { "a" : "b" }
- valid = "a = \"b\";\n"
- self.assertEqual(ucl.dump(data), valid)
-
- @unittest.skipIf(sys.version_info[0] > 2, "Python3 uses unicode only")
- def test_unicode(self):
- data = { unicode("a") : unicode("b") }
- valid = unicode("a = \"b\";\n")
- self.assertEqual(ucl.dump(data), valid)
-
- def test_float(self):
- data = { "a" : 1.1 }
- valid = "a = 1.100000;\n"
- self.assertEqual(ucl.dump(data), valid)
-
- def test_boolean(self):
- data = { "a" : True, "b" : False }
- valid = [
- "a = true;\nb = false;\n",
- "b = false;\na = true;\n"
- ]
- self.assertIn(ucl.dump(data), valid)
-
- def test_empty_ucl(self):
- self.assertEqual(ucl.dump({}), "")
-
- def test_json(self):
- data = { "a" : 1, "b": "bleh;" }
- valid = [
- '{\n "a": 1,\n "b": "bleh;"\n}',
- '{\n "b": "bleh;",\n "a": 1\n}'
- ]
- self.assertIn(ucl.dump(data, ucl.UCL_EMIT_JSON), valid)
diff --git a/contrib/libucl/python/tests/test_example.py b/contrib/libucl/python/tests/test_example.py
deleted file mode 100644
index f0785531f4e2..000000000000
--- a/contrib/libucl/python/tests/test_example.py
+++ /dev/null
@@ -1,59 +0,0 @@
-from .compat import unittest
-import json
-import ucl
-
-_ucl_inp = '''
-param = value;
-section {
- param = value;
- param1 = value1;
- flag = true;
- number = 10k;
- time = 0.2s;
- string = "something";
- subsection {
- host = {
- host = "hostname";
- port = 900;
- }
- host = {
- host = "hostname";
- port = 901;
- }
- }
-}
-'''
-
-_json_res = {
- 'param': 'value',
- 'section': {
- 'param': 'value',
- 'param1': 'value1',
- 'flag': True,
- 'number': 10000,
- 'time': '0.2s',
- 'string': 'something',
- 'subsection': {
- 'host': [
- {
- 'host': 'hostname',
- 'port': 900,
- },
- {
- 'host': 'hostname',
- 'port': 901,
- }
- ]
- }
- }
-}
-
-class TestExample(unittest.TestCase):
- def test_example(self):
- # load in sample UCL
- u = ucl.load(_ucl_inp)
-
- # Output and read back the JSON
- uj = json.loads(json.dumps(u))
-
- self.assertEqual(uj, _json_res)
diff --git a/contrib/libucl/python/tests/test_load.py b/contrib/libucl/python/tests/test_load.py
deleted file mode 100644
index 73d43188f3d5..000000000000
--- a/contrib/libucl/python/tests/test_load.py
+++ /dev/null
@@ -1,122 +0,0 @@
-from .compat import unittest
-import ucl
-
-class LoadTest(unittest.TestCase):
- def test_no_args(self):
- with self.assertRaises(TypeError):
- ucl.load()
-
- def test_multi_args(self):
- with self.assertRaises(TypeError):
- ucl.load(0,0)
-
- def test_none(self):
- self.assertEqual(ucl.load(None), None)
-
- def test_null(self):
- data = "a: null"
- valid = { "a" : None }
- self.assertEqual(ucl.load(data), valid)
-
- def test_int(self):
- data = "a : 1"
- valid = { "a" : 1 }
- self.assertEqual(ucl.load(data), valid)
-
- def test_braced_int(self):
- data = "{a : 1}"
- valid = { "a" : 1 }
- self.assertEqual(ucl.load(data), valid)
-
- def test_nested_int(self):
- data = "a : { b : 1 }"
- valid = { "a" : { "b" : 1 } }
- self.assertEqual(ucl.load(data), valid)
-
- def test_str(self):
- data = "a : b"
- valid = { "a" : "b" }
- self.assertEqual(ucl.load(data), valid)
-
- def test_float(self):
- data = "a : 1.1"
- valid = {"a" : 1.1}
- self.assertEqual(ucl.load(data), valid)
-
- def test_boolean(self):
- data = (
- "a : True;" \
- "b : False"
- )
- valid = { "a" : True, "b" : False }
- self.assertEqual(ucl.load(data), valid)
-
- def test_empty_ucl(self):
- self.assertEqual(ucl.load("{}"), {})
-
- def test_single_brace(self):
- self.assertEqual(ucl.load("{"), {})
-
- def test_single_back_brace(self):
- self.assertEqual(ucl.load("}"), {})
-
- def test_single_square_forward(self):
- self.assertEqual(ucl.load("["), [])
-
- def test_invalid_ucl(self):
- with self.assertRaisesRegex(ValueError, "unfinished key$"):
- ucl.load('{ "var"')
-
- def test_comment_ignored(self):
- self.assertEqual(ucl.load("{/*1*/}"), {})
-
- def test_1_in(self):
- valid = {
- 'key1': [
- 'value',
- 'value2',
- 'value;',
- 1.0,
- -0xdeadbeef,
- '0xdeadbeef.1',
- '0xreadbeef',
- -1e-10,
- 1,
- True,
- False,
- True,
- ]
- }
- with open("../tests/basic/1.in", "r") as in1:
- self.assertEqual(ucl.load(in1.read()), valid)
-
- def test_every_type(self):
- data = ("""{
- "key1": value;
- "key2": value2;
- "key3": "value;"
- "key4": 1.0,
- "key5": -0xdeadbeef
- "key6": 0xdeadbeef.1
- "key7": 0xreadbeef
- "key8": -1e-10,
- "key9": 1
- "key10": true
- "key11": no
- "key12": yes
- }""")
- valid = {
- 'key1': 'value',
- 'key2': 'value2',
- 'key3': 'value;',
- 'key4': 1.0,
- 'key5': -3735928559,
- 'key6': '0xdeadbeef.1',
- 'key7': '0xreadbeef',
- 'key8': -1e-10,
- 'key9': 1,
- 'key10': True,
- 'key11': False,
- 'key12': True,
- }
- self.assertEqual(ucl.load(data), valid)
diff --git a/contrib/libucl/python/tests/test_validation.py b/contrib/libucl/python/tests/test_validation.py
deleted file mode 100644
index f7c853ad69a7..000000000000
--- a/contrib/libucl/python/tests/test_validation.py
+++ /dev/null
@@ -1,50 +0,0 @@
-from .compat import unittest
-import ucl
-import json
-import os.path
-import glob
-import re
-
-TESTS_SCHEMA_FOLDER = '../tests/schema/*.json'
-
-comment_re = re.compile('\/\*((?!\*\/).)*?\*\/', re.DOTALL | re.MULTILINE)
-def json_remove_comments(content):
- return comment_re.sub('', content)
-
-class ValidationTest(unittest.TestCase):
- def validate(self, jsonfile):
- def perform_test(schema, data, valid, description):
- msg = '%s (valid=%r)' % (description, valid)
- if valid:
- self.assertTrue(ucl.validate(schema, data), msg)
- else:
- with self.assertRaises(ucl.SchemaError):
- ucl.validate(schema, data)
- self.fail(msg) # fail() will be called only if SchemaError is not raised
-
- with open(jsonfile) as f:
- try:
- # data = json.load(f)
- data = json.loads(json_remove_comments(f.read()))
- except ValueError as e:
- raise self.skipTest('Failed to load JSON: %s' % str(e))
-
- for testgroup in data:
- for test in testgroup['tests']:
- perform_test(testgroup['schema'], test['data'],
- test['valid'], test['description'])
-
- @classmethod
- def setupValidationTests(cls):
- """Creates each test dynamically from a folder"""
- def test_gen(filename):
- def run_test(self):
- self.validate(filename)
- return run_test
-
- for jsonfile in glob.glob(TESTS_SCHEMA_FOLDER):
- testname = os.path.splitext(os.path.basename(jsonfile))[0]
- setattr(cls, 'test_%s' % testname, test_gen(jsonfile))
-
-
-ValidationTest.setupValidationTests()