This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository python-snuggs.
commit f8c30a1da9a96c292b02f653bae9b27ff4e58c84 Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Wed Jul 13 12:46:04 2016 +0200 Imported Upstream version 1.4.0 --- CHANGES.txt | 5 +++++ setup.py | 18 +++++++++--------- snuggs/__init__.py | 14 +++++++------- test_snuggs.py | 22 +++++++++++++++++++--- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8cd9018..d962261 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,11 @@ Changes ======= +1.4.0 (2016-07-12) +------------------ +- New feature: mathematical operators like + and * can take multiple arguments + as in Hy and other Lisps (#7). + 1.3.1 (2015-04-03) ------------------ - Revert to operator functions in op_map (#4). diff --git a/setup.py b/setup.py index dbb588a..21e75fd 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,15 @@ from setuptools import setup, find_packages with codecs_open('README.rst', encoding='utf-8') as f: long_description = f.read() +with open('snuggs/__init__.py') as f: + for line in f: + if line.startswith('__version__'): + version = line.split('=')[1] + version = version.strip().strip('"') + break setup(name='snuggs', - version='1.3.1', + version=version, description=u"Snuggs are s-expressions for Numpy", long_description=long_description, classifiers=[], @@ -20,11 +26,5 @@ setup(name='snuggs', packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=False, - install_requires=[ - 'click', - 'numpy', - 'pyparsing' - ], - extras_require={ - 'test': ['pytest'], - }) + install_requires=['click', 'numpy', 'pyparsing'], + extras_require={'test': ['pytest']}) diff --git a/snuggs/__init__.py b/snuggs/__init__.py index e91cf98..86ff1aa 100644 --- a/snuggs/__init__.py +++ b/snuggs/__init__.py @@ -17,7 +17,7 @@ import numpy __all__ = ['eval'] -__version__ = "1.3.1" +__version__ = "1.4.0" # Python 2-3 compatibility string_types = (str,) if sys.version_info[0] >= 3 else (basestring,) @@ -69,18 +69,18 @@ class ExpressionError(SyntaxError): lineno = 1 op_map = { - '*': operator.mul, - '+': operator.add, - '/': operator.truediv, - '-': operator.sub, + '*': lambda *args: functools.reduce(lambda x, y: operator.mul(x, y), args), + '+': lambda *args: functools.reduce(lambda x, y: operator.add(x, y), args), + '/': lambda *args: functools.reduce(lambda x, y: operator.truediv(x, y), args), + '-': lambda *args: functools.reduce(lambda x, y: operator.sub(x, y), args), + '&': lambda *args: functools.reduce(lambda x, y: operator.and_(x, y), args), + '|': lambda *args: functools.reduce(lambda x, y: operator.or_(x, y), args), '<': operator.lt, '<=': operator.le, '==': operator.eq, '!=': operator.ne, '>=': operator.ge, '>': operator.gt, - '&': operator.and_, - '|': operator.or_, } def asarray(*args): diff --git a/test_snuggs.py b/test_snuggs.py index ca5d074..bb148fa 100644 --- a/test_snuggs.py +++ b/test_snuggs.py @@ -18,6 +18,10 @@ def test_int_expr(): assert snuggs.eval('(+ 1 2)') == 3 +def test_int_mult_expr(): + assert snuggs.eval('(+ 1 2 3)') == 6 + + def test_real_expr(): assert round(snuggs.eval('(* 0.1 0.2)'), 3) == 0.02 @@ -130,6 +134,12 @@ def test_map_asarray(): assert list(result) == [2, 4, 6] +def test_multi_operator_array(ones): + result = snuggs.eval( + '(+ ones (/ ones 1 0.5) (* ones 1 3))', ones=ones) + assert list(result.flatten()) == [6.0] * 4 + + def test_nil(): assert snuggs.eval('(== nil nil)') assert not snuggs.eval('(== 1 nil)') @@ -151,7 +161,9 @@ def test_missing_closing_paren(): result = snuggs.eval("(+ 1 2") assert excinfo.value.lineno == 1 assert excinfo.value.offset == 7 - assert str(excinfo.value) == 'Expected ")"' + exception_options = ['expected a function or operator', + 'Expected {Forward: ... | Forward: ...}'] + assert str(excinfo.value) in exception_options def test_missing_func(): @@ -167,7 +179,9 @@ def test_missing_func2(): result = snuggs.eval("(# 1 2)") assert excinfo.value.lineno == 1 assert excinfo.value.offset == 2 - assert str(excinfo.value) == "expected a function or operator" + exception_options = ['expected a function or operator', + 'Expected {Forward: ... | Forward: ...}'] + assert str(excinfo.value) in exception_options def test_undefined_var(): @@ -183,7 +197,9 @@ def test_bogus_higher_order_func(): result = snuggs.eval("((bogus * 2) 2)") assert excinfo.value.lineno == 1 assert excinfo.value.offset == 3 - assert str(excinfo.value) == "expected a function or operator" + exception_options = ['expected a function or operator', + 'Expected {Forward: ... | Forward: ...}'] + assert str(excinfo.value) in exception_options def test_type_error(): -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-snuggs.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel