summaryrefslogtreecommitdiff
path: root/_test/test_json_numbers.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-01-22 21:22:33 +0100
committerAnthon van der Neut <anthon@mnt.org>2016-01-22 21:22:33 +0100
commitda73c8aa0d8db3d0f54d88740a0f7f621ac563df (patch)
tree7cbbfec9780ab9a33f09926e91cab343be049cdb /_test/test_json_numbers.py
parenta5f03a5e66daaea85af2730fa961d11c62d8cf17 (diff)
downloadruamel.yaml-da73c8aa0d8db3d0f54d88740a0f7f621ac563df.tar.gz
moved test to _test to prevent setuptools from including test/test_*.py0.10.17
although the package dirs were explicitly specified. This used to lead to half included, non-working test directory contents that have no place in a distribution. This fixes issue #17
Diffstat (limited to '_test/test_json_numbers.py')
-rw-r--r--_test/test_json_numbers.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/_test/test_json_numbers.py b/_test/test_json_numbers.py
new file mode 100644
index 0000000..db5bcaa
--- /dev/null
+++ b/_test/test_json_numbers.py
@@ -0,0 +1,48 @@
+
+from __future__ import print_function
+
+import pytest
+
+import ruamel.yaml
+import json
+
+def load(s, typ=float):
+ x = '{"low": %s }' % (s)
+ print('input: [%s]' % (s), repr(x))
+ # just to check it is loadable json
+ res = json.loads(x)
+ assert isinstance(res['low'], typ)
+ ret_val = ruamel.yaml.load(x, ruamel.yaml.RoundTripLoader)
+ print(ret_val)
+ return ret_val['low']
+
+class TestJSONNumbers:
+ # based on http://stackoverflow.com/a/30462009/1307905
+ # yaml number regex: http://yaml.org/spec/1.2/spec.html#id2804092
+ #
+ # -? [1-9] ( \. [0-9]* [1-9] )? ( e [-+] [1-9] [0-9]* )?
+ #
+ # which is not a superset of the JSON numbers
+ def test_json_number_float(self):
+ for x in (y.split('#')[0].strip() for y in """
+ 1.0 # should fail on YAML spec on 1-9 allowed as single digit
+ -1.0
+ 1e-06
+ 3.1e-5
+ 3.1e+5
+ 3.1e5 # should fail on YAML spec: no +- after e
+ """.splitlines()):
+ if not x:
+ continue
+ res = load(x)
+ assert isinstance(res, float)
+
+ def test_json_number_int(self):
+ for x in (y.split('#')[0].strip() for y in """
+ 42
+ """.splitlines()):
+ if not x:
+ continue
+ res = load(x, int)
+ assert isinstance(res, int)
+