forked from pool/python-jmespath
Accepting request 898270 from home:pgajdos:python
- use github tarball to use upstream tests - %check: use %pyunittest rpm macro to test the package - deleted sources - test_hypothesis.py (not needed) OBS-URL: https://build.opensuse.org/request/show/898270 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-jmespath?expand=0&rev=40
This commit is contained in:
parent
6399d876cb
commit
07eff4af45
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9
|
oid sha256:999b0ef13b798cf04de5451a51201d63a6feaf07c3fdcfbab4e5bca2b4ac653e
|
||||||
size 21607
|
size 81860
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Mon May 31 08:00:06 UTC 2021 - pgajdos@suse.com
|
||||||
|
|
||||||
|
- use github tarball to use upstream tests
|
||||||
|
- %check: use %pyunittest rpm macro to test the package
|
||||||
|
- deleted sources
|
||||||
|
- test_hypothesis.py (not needed)
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Jun 2 16:21:51 UTC 2020 - Dirk Mueller <dmueller@suse.com>
|
Tue Jun 2 16:21:51 UTC 2020 - Dirk Mueller <dmueller@suse.com>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package python-jmespath
|
# spec file for package python-jmespath
|
||||||
#
|
#
|
||||||
# Copyright (c) 2020 SUSE LLC
|
# Copyright (c) 2021 SUSE LLC
|
||||||
#
|
#
|
||||||
# All modifications and additions to the file contributed by third parties
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@ -24,8 +24,7 @@ Summary: Python module for declarative JSON document element extraction
|
|||||||
License: MIT
|
License: MIT
|
||||||
Group: Development/Languages/Python
|
Group: Development/Languages/Python
|
||||||
URL: https://github.com/jmespath/jmespath.py
|
URL: https://github.com/jmespath/jmespath.py
|
||||||
Source: https://files.pythonhosted.org/packages/source/j/jmespath/jmespath-%{version}.tar.gz
|
Source: https://github.com/jmespath/jmespath.py/archive/refs/tags/%{version}.tar.gz#/jmespath-%{version}.tar.gz
|
||||||
Source1: https://raw.githubusercontent.com/jmespath/jmespath.py/develop/extra/test_hypothesis.py
|
|
||||||
# Testing
|
# Testing
|
||||||
BuildRequires: %{python_module hypothesis}
|
BuildRequires: %{python_module hypothesis}
|
||||||
BuildRequires: %{python_module nose}
|
BuildRequires: %{python_module nose}
|
||||||
@ -37,7 +36,7 @@ BuildRequires: python-rpm-macros
|
|||||||
Requires: python-ply >= 3.4
|
Requires: python-ply >= 3.4
|
||||||
Requires: python-simplejson
|
Requires: python-simplejson
|
||||||
Requires(post): update-alternatives
|
Requires(post): update-alternatives
|
||||||
Requires(postun): update-alternatives
|
Requires(postun):update-alternatives
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
%python_subpackages
|
%python_subpackages
|
||||||
|
|
||||||
@ -73,8 +72,7 @@ The * can also be used for hash types:
|
|||||||
The expression: foo.*.name will return ["one", "two"].
|
The expression: foo.*.name will return ["one", "two"].
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -n jmespath-%{version}
|
%setup -q -n jmespath.py-%{version}
|
||||||
cp %{SOURCE1} .
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%python_build
|
%python_build
|
||||||
@ -86,9 +84,11 @@ mv %{buildroot}%{_bindir}/jp.py %{buildroot}%{_bindir}/jp
|
|||||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||||
|
|
||||||
%check
|
%check
|
||||||
%{python_expand $python setup.py test
|
%if 0%{?suse_version} > 1500
|
||||||
$python test_hypothesis.py
|
%pyunittest discover -v
|
||||||
}
|
%else
|
||||||
|
%python_exec setup.py test
|
||||||
|
%endif
|
||||||
|
|
||||||
%post
|
%post
|
||||||
%python_install_alternative jp
|
%python_install_alternative jp
|
||||||
|
@ -1,142 +0,0 @@
|
|||||||
# Test suite using hypothesis to generate test cases.
|
|
||||||
# This is in a standalone module so that these tests
|
|
||||||
# can a) be run separately and b) allow for customization
|
|
||||||
# via env var for longer runs in travis.
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import numbers
|
|
||||||
|
|
||||||
from nose.plugins.skip import SkipTest
|
|
||||||
from hypothesis import given, settings, assume, HealthCheck
|
|
||||||
import hypothesis.strategies as st
|
|
||||||
|
|
||||||
from jmespath import lexer
|
|
||||||
from jmespath import parser
|
|
||||||
from jmespath import exceptions
|
|
||||||
from jmespath.functions import Functions
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[:2] == (2, 6):
|
|
||||||
raise RuntimeError("Hypothesis tests are not supported on python2.6. "
|
|
||||||
"Use python2.7, or python3.3 and greater.")
|
|
||||||
|
|
||||||
|
|
||||||
JSON_NUMBERS = (st.integers() | st.floats(allow_nan=False,
|
|
||||||
allow_infinity=False))
|
|
||||||
|
|
||||||
RANDOM_JSON = st.recursive(
|
|
||||||
JSON_NUMBERS | st.booleans() | st.text() | st.none(),
|
|
||||||
lambda children: st.lists(children) | st.dictionaries(st.text(), children)
|
|
||||||
)
|
|
||||||
|
|
||||||
MAX_EXAMPLES = int(os.environ.get('JP_MAX_EXAMPLES', 1000))
|
|
||||||
BASE_SETTINGS = {
|
|
||||||
'max_examples': MAX_EXAMPLES,
|
|
||||||
'suppress_health_check': [HealthCheck.too_slow,
|
|
||||||
HealthCheck.filter_too_much,
|
|
||||||
HealthCheck.data_too_large],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# For all of these tests they verify these properties:
|
|
||||||
# either the operation succeeds or it raises a JMESPathError.
|
|
||||||
# If any other exception is raised then we error out.
|
|
||||||
@settings(**BASE_SETTINGS)
|
|
||||||
@given(st.text())
|
|
||||||
def test_lexer_api(expr):
|
|
||||||
try:
|
|
||||||
tokens = list(lexer.Lexer().tokenize(expr))
|
|
||||||
except exceptions.EmptyExpressionError:
|
|
||||||
return
|
|
||||||
except exceptions.LexerError as e:
|
|
||||||
assert e.lex_position >= 0, e.lex_position
|
|
||||||
assert e.lex_position < len(expr), e.lex_position
|
|
||||||
if expr:
|
|
||||||
assert expr[e.lex_position] == e.token_value[0], (
|
|
||||||
"Lex position does not match first token char.\n"
|
|
||||||
"Expression: %s\n%s != %s" % (expr, expr[e.lex_position],
|
|
||||||
e.token_value[0])
|
|
||||||
)
|
|
||||||
return
|
|
||||||
except Exception as e:
|
|
||||||
raise AssertionError("Non JMESPathError raised: %s" % e)
|
|
||||||
assert isinstance(tokens, list)
|
|
||||||
# Token starting positions must be unique, can't have two
|
|
||||||
# tokens with the same start position.
|
|
||||||
start_locations = [t['start'] for t in tokens]
|
|
||||||
assert len(set(start_locations)) == len(start_locations), (
|
|
||||||
"Tokens must have unique starting locations.")
|
|
||||||
# Starting positions must be increasing (i.e sorted).
|
|
||||||
assert sorted(start_locations) == start_locations, (
|
|
||||||
"Tokens must have increasing start locations.")
|
|
||||||
# Last token is always EOF.
|
|
||||||
assert tokens[-1]['type'] == 'eof'
|
|
||||||
|
|
||||||
|
|
||||||
@settings(**BASE_SETTINGS)
|
|
||||||
@given(st.text())
|
|
||||||
def test_parser_api_from_str(expr):
|
|
||||||
# Same a lexer above with the assumption that we're parsing
|
|
||||||
# a valid sequence of tokens.
|
|
||||||
try:
|
|
||||||
list(lexer.Lexer().tokenize(expr))
|
|
||||||
except exceptions.JMESPathError as e:
|
|
||||||
# We want to try to parse things that tokenize
|
|
||||||
# properly.
|
|
||||||
assume(False)
|
|
||||||
try:
|
|
||||||
ast = parser.Parser().parse(expr)
|
|
||||||
except exceptions.JMESPathError as e:
|
|
||||||
return
|
|
||||||
except Exception as e:
|
|
||||||
raise AssertionError("Non JMESPathError raised: %s" % e)
|
|
||||||
assert isinstance(ast.parsed, dict)
|
|
||||||
assert 'type' in ast.parsed
|
|
||||||
assert 'children' in ast.parsed
|
|
||||||
assert isinstance(ast.parsed['children'], list)
|
|
||||||
|
|
||||||
|
|
||||||
@settings(**BASE_SETTINGS)
|
|
||||||
@given(expr=st.text(), data=RANDOM_JSON)
|
|
||||||
def test_search_api(expr, data):
|
|
||||||
try:
|
|
||||||
ast = parser.Parser().parse(expr)
|
|
||||||
except exceptions.JMESPathError as e:
|
|
||||||
# We want to try to parse things that tokenize
|
|
||||||
# properly.
|
|
||||||
assume(False)
|
|
||||||
try:
|
|
||||||
ast.search(data)
|
|
||||||
except exceptions.JMESPathError as e:
|
|
||||||
return
|
|
||||||
except Exception as e:
|
|
||||||
raise AssertionError("Non JMESPathError raised: %s" % e)
|
|
||||||
|
|
||||||
|
|
||||||
# Additional property tests for functions.
|
|
||||||
|
|
||||||
@given(arg=JSON_NUMBERS)
|
|
||||||
def test_abs(arg):
|
|
||||||
assert Functions().call_function('abs', [arg]) >= 0
|
|
||||||
|
|
||||||
|
|
||||||
@given(arg=st.lists(JSON_NUMBERS))
|
|
||||||
def test_avg(arg):
|
|
||||||
result = Functions().call_function('avg', [arg])
|
|
||||||
if result is not None:
|
|
||||||
assert isinstance(result, numbers.Number)
|
|
||||||
|
|
||||||
|
|
||||||
@given(arg=st.lists(st.floats() | st.booleans() | st.text() | st.none(),
|
|
||||||
min_size=1))
|
|
||||||
def test_not_null(arg):
|
|
||||||
result = Functions().call_function('not_null', arg)
|
|
||||||
if result is not None:
|
|
||||||
assert result in arg
|
|
||||||
|
|
||||||
|
|
||||||
@given(arg=RANDOM_JSON)
|
|
||||||
def test_to_number(arg):
|
|
||||||
result = Functions().call_function('to_number', [arg])
|
|
||||||
if result is not None:
|
|
||||||
assert isinstance(result, numbers.Number)
|
|
Loading…
x
Reference in New Issue
Block a user