From da73c8aa0d8db3d0f54d88740a0f7f621ac563df Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Fri, 22 Jan 2016 21:22:33 +0100 Subject: moved test to _test to prevent setuptools from including test/test_*.py 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 --- _test/test_json_numbers.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 _test/test_json_numbers.py (limited to '_test/test_json_numbers.py') 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) + -- cgit v1.2.1