diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-18 13:06:15 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-18 13:06:15 +0300 |
commit | 2994bba5ede76ddcd8ee1c6e07b1514fe2ea7818 (patch) | |
tree | 9c7361f369873b1d9ed923b03b759a642f7f5b3e | |
parent | 3624d9b1a100557ff43ed565d7076e0a1e5814b2 (diff) | |
download | ydb-2994bba5ede76ddcd8ee1c6e07b1514fe2ea7818.tar.gz |
intermediate changes
ref:fe53f16dfa3e8bb23272a86bce898eb0339e1ead
-rw-r--r-- | contrib/python/jmespath/py3/.dist-info/METADATA | 6 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/jmespath/__init__.py | 2 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/jmespath/parser.py | 2 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/jmespath/visitor.py | 16 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/patches/01-fix-tests.patch | 12 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/tests/__init__.py | 15 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/tests/test_compliance.py | 33 | ||||
-rw-r--r-- | contrib/python/jmespath/py3/tests/test_parser.py | 30 |
8 files changed, 75 insertions, 41 deletions
diff --git a/contrib/python/jmespath/py3/.dist-info/METADATA b/contrib/python/jmespath/py3/.dist-info/METADATA index 054beacb98..00fb771cc1 100644 --- a/contrib/python/jmespath/py3/.dist-info/METADATA +++ b/contrib/python/jmespath/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ -Metadata-Version: 2.0 +Metadata-Version: 2.1 Name: jmespath -Version: 1.0.0 +Version: 1.0.1 Summary: JSON Matching Expressions Home-page: https://github.com/jmespath/jmespath.py Author: James Saryerwinnie @@ -16,6 +16,8 @@ Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 +Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Requires-Python: >=3.7 diff --git a/contrib/python/jmespath/py3/jmespath/__init__.py b/contrib/python/jmespath/py3/jmespath/__init__.py index d444b3dea0..c2439e37d4 100644 --- a/contrib/python/jmespath/py3/jmespath/__init__.py +++ b/contrib/python/jmespath/py3/jmespath/__init__.py @@ -1,7 +1,7 @@ from jmespath import parser from jmespath.visitor import Options -__version__ = '1.0.0' +__version__ = '1.0.1' def compile(expression): diff --git a/contrib/python/jmespath/py3/jmespath/parser.py b/contrib/python/jmespath/py3/jmespath/parser.py index eeac38fa89..4706688040 100644 --- a/contrib/python/jmespath/py3/jmespath/parser.py +++ b/contrib/python/jmespath/py3/jmespath/parser.py @@ -489,7 +489,7 @@ class Parser(object): lex_position, actual_value, actual_type, message) def _free_cache_entries(self): - for key in random.sample(self._CACHE.keys(), int(self._MAX_SIZE / 2)): + for key in random.sample(list(self._CACHE.keys()), int(self._MAX_SIZE / 2)): self._CACHE.pop(key, None) @classmethod diff --git a/contrib/python/jmespath/py3/jmespath/visitor.py b/contrib/python/jmespath/py3/jmespath/visitor.py index b3e846b761..15fb1774e1 100644 --- a/contrib/python/jmespath/py3/jmespath/visitor.py +++ b/contrib/python/jmespath/py3/jmespath/visitor.py @@ -6,13 +6,13 @@ from numbers import Number def _equals(x, y): - if _is_special_integer_case(x, y): + if _is_special_number_case(x, y): return False else: return x == y -def _is_special_integer_case(x, y): +def _is_special_number_case(x, y): # We need to special case comparing 0 or 1 to # True/False. While normally comparing any # integer other than 0/1 to True/False will always @@ -29,10 +29,10 @@ def _is_special_integer_case(x, y): # Also need to consider that: # >>> 0 in [True, False] # True - if type(x) is int and (x == 0 or x == 1): - return y is True or y is False - elif type(y) is int and (y == 0 or y == 1): - return x is True or x is False + if _is_actual_number(x) and x in (0, 1): + return isinstance(y, bool) + elif _is_actual_number(y) and y in (0, 1): + return isinstance(x, bool) def _is_comparable(x): @@ -51,7 +51,7 @@ def _is_actual_number(x): # True # >>> isinstance(True, int) # True - if x is True or x is False: + if isinstance(x, bool): return False return isinstance(x, Number) @@ -257,7 +257,7 @@ class TreeInterpreter(Visitor): def visit_not_expression(self, node, value): original_result = self.visit(node['children'][0], value) - if type(original_result) is int and original_result == 0: + if _is_actual_number(original_result) and original_result == 0: # Special case for 0, !0 should be false, not true. # 0 is not a special cased integer in jmespath. return False diff --git a/contrib/python/jmespath/py3/patches/01-fix-tests.patch b/contrib/python/jmespath/py3/patches/01-fix-tests.patch new file mode 100644 index 0000000000..42d1697a93 --- /dev/null +++ b/contrib/python/jmespath/py3/patches/01-fix-tests.patch @@ -0,0 +1,12 @@ +--- contrib/python/jmespath/py3/tests/test_compliance.py (index) ++++ contrib/python/jmespath/py3/tests/test_compliance.py (working tree) +@@ -3,2 +3,2 @@ +-from tests import OrderedDict +-from tests import json ++from . import OrderedDict ++from . import json +--- contrib/python/jmespath/py3/tests/test_parser.py (index) ++++ contrib/python/jmespath/py3/tests/test_parser.py (working tree) +@@ -6,1 +6,1 @@ import re +-from tests import unittest, OrderedDict ++from . import unittest, OrderedDict diff --git a/contrib/python/jmespath/py3/tests/__init__.py b/contrib/python/jmespath/py3/tests/__init__.py index d86946ccda..61f6687575 100644 --- a/contrib/python/jmespath/py3/tests/__init__.py +++ b/contrib/python/jmespath/py3/tests/__init__.py @@ -1,18 +1,9 @@ import sys from jmespath import ast - -# The unittest module got a significant overhaul -# in 2.7, so if we're in 2.6 we can use the backported -# version unittest2. -if sys.version_info[:2] == (2, 6): - import unittest2 as unittest - import simplejson as json - from ordereddict import OrderedDict -else: - import unittest - import json - from collections import OrderedDict +import unittest +import json +from collections import OrderedDict # Helper method used to create an s-expression diff --git a/contrib/python/jmespath/py3/tests/test_compliance.py b/contrib/python/jmespath/py3/tests/test_compliance.py index 86e8297027..cff40b014c 100644 --- a/contrib/python/jmespath/py3/tests/test_compliance.py +++ b/contrib/python/jmespath/py3/tests/test_compliance.py @@ -1,9 +1,10 @@ import os -import pytest from pprint import pformat from . import OrderedDict from . import json +import pytest + from jmespath.visitor import Options @@ -14,7 +15,7 @@ NOT_SPECIFIED = object() OPTIONS = Options(dict_cls=OrderedDict) -def _load_all_cases(): +def _compliance_tests(requested_test_type): for full_path in _walk_files(): if full_path.endswith('.json'): for given, test_type, test_data in load_cases(full_path): @@ -22,10 +23,12 @@ def _load_all_cases(): # Benchmark tests aren't run as part of the normal # test suite, so we only care about 'result' and # 'error' test_types. - if test_type == 'result': - yield (given, t['expression'], t['result'], os.path.basename(full_path)) - elif test_type == 'error': - yield (given, t['expression'], t['error'], os.path.basename(full_path)) + if test_type == 'result' and test_type == requested_test_type: + yield (given, t['expression'], + t['result'], os.path.basename(full_path)) + elif test_type == 'error' and test_type == requested_test_type: + yield (given, t['expression'], + t['error'], os.path.basename(full_path)) def _walk_files(): @@ -61,14 +64,10 @@ def load_cases(full_path): @pytest.mark.parametrize( - 'given,expression,expected,filename', - list(_load_all_cases()) + 'given, expression, expected, filename', + _compliance_tests('result') ) -def test_compliance(given, expression, expected, filename): - _test_expression(given, expression, expected, filename) - - -def _test_expression(given, expression, expected, filename): +def test_expression(given, expression, expected, filename): import jmespath.parser try: parsed = jmespath.compile(expression) @@ -85,10 +84,14 @@ def _test_expression(given, expression, expected, filename): actual_repr, pformat(parsed.parsed), json.dumps(given, indent=4))) error_msg = error_msg.replace(r'\n', '\n') - assert actua == expected, error_msg + assert actual == expected, error_msg -def _test_error_expression(given, expression, error, filename): +@pytest.mark.parametrize( + 'given, expression, error, filename', + _compliance_tests('error') +) +def test_error_expression(given, expression, error, filename): import jmespath.parser if error not in ('syntax', 'invalid-type', 'unknown-function', 'invalid-arity', 'invalid-value'): diff --git a/contrib/python/jmespath/py3/tests/test_parser.py b/contrib/python/jmespath/py3/tests/test_parser.py index 121b4b79b2..264d272b0a 100644 --- a/contrib/python/jmespath/py3/tests/test_parser.py +++ b/contrib/python/jmespath/py3/tests/test_parser.py @@ -1,6 +1,8 @@ #!/usr/bin/env python - import re +import random +import string +import threading from . import unittest, OrderedDict from jmespath import parser @@ -167,7 +169,7 @@ class TestErrorMessages(unittest.TestCase): error_message = re.compile( r'Bad jmespath expression: ' r'Invalid \\uXXXX escape.*\\uAZ12', re.DOTALL) - with self.assertRaisesRegexp(exceptions.LexerError, error_message): + with self.assertRaisesRegex(exceptions.LexerError, error_message): self.parser.parse(r'"\uAZ12"') @@ -322,6 +324,30 @@ class TestParserCaching(unittest.TestCase): self.assertEqual(first.parsed, cached.parsed) + def test_thread_safety_of_cache(self): + errors = [] + expressions = [ + ''.join(random.choice(string.ascii_letters) for _ in range(3)) + for _ in range(2000) + ] + def worker(): + p = parser.Parser() + for expression in expressions: + try: + p.parse(expression) + except Exception as e: + errors.append(e) + + threads = [] + for i in range(10): + threads.append(threading.Thread(target=worker)) + for thread in threads: + thread.start() + for thread in threads: + thread.join() + + self.assertEqual(errors, []) + class TestParserAddsExpressionAttribute(unittest.TestCase): def test_expression_available_from_parser(self): |