Skip to content
Commits on Source (2)
dist: xenial
language: python
python:
- "2.7"
- "3.6"
- "3.7"
install:
- "pip install pytest-cov coveralls"
- "pip install -e ."
- "pip install pytest-cov coveralls pyparsing==2.3.1"
- "pip install -e .[test]"
script:
- python -m pytest --cov snuggs --cov-report term-missing
after_success:
......
Changes
=======
1.4.5 (2019-05-14)
------------------
- Replace custom integer and real parsers with pyparsing_common's number (#19).
1.4.4 (2019-05-14)
------------------
- Fix for a reported bug in parsing negative real numbers (#16) and for an
unreported bug in parsing numbers in exponential notation (thank you,
hypothesis!).
- Add a "test" dependency on hypothesis.
1.4.3 (2019-02-25)
------------------
- Add LICENSE to distributions (#11).
......
......@@ -29,6 +29,6 @@ setup(
packages=find_packages(exclude=["ez_setup", "examples", "tests"]),
include_package_data=True,
zip_safe=False,
install_requires=["numpy", "pyparsing"],
extras_require={"test": ["pytest"]},
install_requires=["numpy", "pyparsing>=2.1.6"],
extras_require={"test": ["pytest", "hypothesis"]},
)
......@@ -16,7 +16,7 @@ import numpy
__all__ = ['eval']
__version__ = "1.4.3"
__version__ = "1.4.5"
# Python 2-3 compatibility
string_types = (str,) if sys.version_info[0] >= 3 else (basestring,) # flake8: noqa
......@@ -121,15 +121,6 @@ def resolve_var(s, l, t):
var = name.setParseAction(resolve_var)
integer = Combine(
Optional(sign) +
number).setParseAction(lambda s, l, t: int(t[0]))
real = Combine(
integer +
decimal + Optional(number) +
Optional(e + integer)).setParseAction(lambda s, l, t: float(t[0]))
string = QuotedString("'") | QuotedString('"')
lparen = Literal('(').suppress()
......@@ -159,7 +150,7 @@ func_expr = Forward()
higher_func_expr = Forward()
expr = higher_func_expr | func_expr
operand = higher_func_expr | func_expr | nil | var | real | integer | string
operand = higher_func_expr | func_expr | nil | var | pyparsing_common.number | string
func_expr << Group(
lparen +
......
from collections import OrderedDict
from hypothesis import given
from hypothesis.strategies import floats, integers
import numpy
import pytest
import snuggs
# Fixtures follow the tests. See the end of the file.
@pytest.fixture
def ones():
return numpy.ones((2, 2))
@pytest.fixture
def truetrue():
return numpy.array([True, True])
@pytest.fixture
def truefalse():
return numpy.array([True, False])
def test_integer():
assert list(snuggs.integer.parseString('1')) == [1]
@given(integers())
def test_integer_operand(num):
assert list(snuggs.operand.parseString(str(num))) == [num]
def test_real():
assert list(snuggs.real.parseString('1.1')) == [1.1]
@given(floats(allow_infinity=False, allow_nan=False))
def test_real_operand(num):
assert list(snuggs.operand.parseString(str(num))) == [num]
def test_int_expr():
......@@ -225,17 +242,6 @@ def test_type_error():
snuggs.eval("(+ 1 'bogus')")
# Fixtures.
@pytest.fixture
def ones():
return numpy.ones((2, 2))
@pytest.fixture
def truetrue():
return numpy.array([True, True])
@pytest.fixture
def truefalse():
return numpy.array([True, False])
def test_negative_decimal():
"""Negative decimals parse correctly"""
assert snuggs.eval("(< -0.9 0)")