From 7928675be0b6607376cb9f3fce5f3835725df135 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 13 Dec 2021 22:23:17 +0530 Subject: [PATCH 1/6] Update test_validators.py Updated and fixed the float validator test case added by the user for the PR #384 --- tests/searchcommands/test_validators.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/searchcommands/test_validators.py b/tests/searchcommands/test_validators.py index 8532fa42..f9aeea80 100755 --- a/tests/searchcommands/test_validators.py +++ b/tests/searchcommands/test_validators.py @@ -208,9 +208,10 @@ def test(integer): def test_float(self): # Float validator test + import random - maxsize = sys.maxsize - minsize = -(sys.maxsize - 1) + maxsize = random.random() + 1 + minsize = random.random() - 1 validator = validators.Float() @@ -240,27 +241,25 @@ def test(float_val): self.assertEqual(validator.__call__(0), 0) self.assertEqual(validator.__call__(1.154), 1.154) self.assertEqual(validator.__call__(888.51), 888.51) - self.assertEqual(validator.__call__(2 * maxsize), float(2 * maxsize)) + self.assertEqual(validator.__call__(2 * maxsize), (2 * maxsize)) self.assertRaises(ValueError, validator.__call__, -1) self.assertRaises(ValueError, validator.__call__, -1111.00578) self.assertRaises(ValueError, validator.__call__, -0.005) validator = validators.Float(minimum=1, maximum=maxsize) self.assertEqual(validator.__call__(1), float(1)) - self.assertEqual(validator.__call__(100.111), 100.111) - self.assertEqual(validator.__call__(9999.0), 9999.0) - self.assertEqual(validator.__call__(maxsize), float(maxsize)) + self.assertEqual(validator.__call__(maxsize), maxsize) self.assertRaises(ValueError, validator.__call__, 0) self.assertRaises(ValueError, validator.__call__, 0.9999) - self.assertRaises(ValueError, validator.__call__, -199) self.assertRaises(ValueError, validator.__call__, maxsize + 1) - validator = validators.Float(minimum=-1, maximum=1) - self.assertEqual(validator.__call__(0), float(0)) + validator = validators.Float(minimum=minsize, maximum=maxsize) + self.assertEqual(validator.__call__(minsize), minsize) self.assertEqual(validator.__call__(0.123456), 0.123456) + self.assertEqual(validator.__call__(0), float(0)) self.assertEqual(validator.__call__(-0.012), -0.012) - self.assertRaises(ValueError, validator.__call__, -1.1) - self.assertRaises(ValueError, validator.__call__, 100.123456) + self.assertEqual(validator.__call__(maxsize), maxsize) + self.assertRaises(ValueError, validator.__call__, minsize - 1) self.assertRaises(ValueError, validator.__call__, maxsize + 1) return From 03bcab1bb52d619d4a4a3910bee4f7c6bd57f01e Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 13 Dec 2021 22:41:19 +0530 Subject: [PATCH 2/6] Update test_decorators.py --- tests/searchcommands/test_decorators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/searchcommands/test_decorators.py b/tests/searchcommands/test_decorators.py index 082ab184..b9df0ef3 100755 --- a/tests/searchcommands/test_decorators.py +++ b/tests/searchcommands/test_decorators.py @@ -381,6 +381,7 @@ def test_option(self): validators.Fieldname: ('some.field_name', 'non-fieldname value'), validators.File: (__file__, 'non-existent file'), validators.Integer: ('100', 'non-integer value'), + validators.Float: ('99.9', 'non-float value'), validators.List: ('a,b,c', '"non-list value'), validators.Map: ('foo', 'non-existent map entry'), validators.Match: ('123-45-6789', 'not a social security number'), From 40ca0a2d8944edc12958a8c7587bd788a5d60b25 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 13 Dec 2021 22:58:05 +0530 Subject: [PATCH 3/6] Update test_decorators.py --- tests/searchcommands/test_decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/searchcommands/test_decorators.py b/tests/searchcommands/test_decorators.py index b9df0ef3..60e737c0 100755 --- a/tests/searchcommands/test_decorators.py +++ b/tests/searchcommands/test_decorators.py @@ -460,7 +460,7 @@ def test_option(self): self.assertEqual(expected[x.name], x.value.pattern) elif isinstance(x.value, TextIOWrapper): self.assertEqual(expected[x.name], "'%s'" % x.value.name) - elif not isinstance(x.value, (bool,) + (six.text_type,) + (six.binary_type,) + tuplewrap(six.integer_types)): + elif not isinstance(x.value, (bool,) + (float,) + (six.text_type,) + (six.binary_type,) + tuplewrap(six.integer_types)): self.assertEqual(expected[x.name], repr(x.value)) else: self.assertEqual(expected[x.name], x.value) From 529094684e4f3e92af5cb86c62f439c0e35ef1b2 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 13 Dec 2021 23:31:37 +0530 Subject: [PATCH 4/6] Update test_decorators.py --- tests/searchcommands/test_decorators.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/searchcommands/test_decorators.py b/tests/searchcommands/test_decorators.py index 60e737c0..73813251 100755 --- a/tests/searchcommands/test_decorators.py +++ b/tests/searchcommands/test_decorators.py @@ -467,13 +467,16 @@ def test_option(self): expected = ( 'foo="f" boolean="f" code="foo == \\"bar\\"" duration="24:59:59" fieldname="some.field_name" ' - 'file=' + json_encode_string(__file__) + ' integer="100" float="99.9" map="foo" match="123-45-6789" ' + 'file=' + json_encode_string(__file__) + ' float="99.9" integer="100" map="foo" match="123-45-6789" ' 'optionname="some_option_name" record="f" regularexpression="\\\\s+" required_boolean="f" ' 'required_code="foo == \\"bar\\"" required_duration="24:59:59" required_fieldname="some.field_name" ' - 'required_file=' + json_encode_string(__file__) + ' required_integer="100" required_float="99.9" required_map="foo" ' + 'required_file=' + json_encode_string(__file__) + ' required_float="99.9" required_integer="100" required_map="foo" ' 'required_match="123-45-6789" required_optionname="some_option_name" required_regularexpression="\\\\s+" ' 'required_set="bar" set="bar" show_configuration="f"') + print(command.options) + print() + print(expected) observed = six.text_type(command.options) self.assertEqual(observed, expected) From 9c8df4444da78c450b9e0b8cf12503f9617ef743 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Tue, 14 Dec 2021 00:09:49 +0530 Subject: [PATCH 5/6] Update test_validators.py --- tests/searchcommands/test_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/searchcommands/test_validators.py b/tests/searchcommands/test_validators.py index f9aeea80..38836c4a 100755 --- a/tests/searchcommands/test_validators.py +++ b/tests/searchcommands/test_validators.py @@ -222,7 +222,7 @@ def test(float_val): assert False for s in str(float_val), six.text_type(float_val): value = validator.__call__(s) - self.assertEqual(value, float_val) + self.assertAlmostEqual(value, float_val) self.assertIsInstance(value, float) self.assertEqual(validator.format(float_val), six.text_type(float_val)) From 87bb9207901b3bcacafb2c52a37ff61ed8379eb2 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Tue, 14 Dec 2021 10:41:48 +0530 Subject: [PATCH 6/6] Update test_decorators.py removed print statements --- tests/searchcommands/test_decorators.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/searchcommands/test_decorators.py b/tests/searchcommands/test_decorators.py index 73813251..dd65aa0a 100755 --- a/tests/searchcommands/test_decorators.py +++ b/tests/searchcommands/test_decorators.py @@ -474,9 +474,6 @@ def test_option(self): 'required_match="123-45-6789" required_optionname="some_option_name" required_regularexpression="\\\\s+" ' 'required_set="bar" set="bar" show_configuration="f"') - print(command.options) - print() - print(expected) observed = six.text_type(command.options) self.assertEqual(observed, expected)