diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc792d3 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +# A GNU Makefile to run various tasks - compatibility for us old-timers. + +# Note: This makefile include remake-style target comments. +# These comments before the targets start with #: +# remake --tasks to shows the targets and the comments + +GIT2CL ?= admin-tools/git2cl +PYTHON ?= python +PIP ?= $(PYTHON) -m pip +RM ?= rm + + +.PHONY: all build \ + check clean \ + develop dist doc doc-data \ + pypi-setup \ + pytest \ + rmChangeLog \ + test + +#: Default target - same as "develop" +all: develop + +#: build everything needed to install +build: pypi-setup + $(PYTHON) ./setup.py build + +#: Check Python version, and install PyPI dependencies +pypi-setup: + $(PIP) install -e . + +#: Set up to run from the source tree +develop: pypi-setup + +#: Make distirbution: wheels, eggs, tarball +dist: + ./admin-tools/make-dist.sh + +#: Install pymathics.graph +install: pypi-setup + $(PYTHON) setup.py install + +# Run tests +test check: pytest doctest + +#: Remove derived files +clean: clean-pyc + +#: Remove old PYC files +clean-pyc: + @find . -name "*.pyc" -type f -delete + +#: Run py.test tests. Use environment variable "o" for pytest options +pytest: + MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m pytest $(PYTEST_WORKERS) test $o + + +# #: Create data that is used to in Django docs and to build TeX PDF +# doc-data mathics/doc/tex/data: mathics/builtin/*.py mathics/doc/documentation/*.mdoc mathics/doc/documentation/images/* +# $(PYTHON) mathics/test.py -ot -k + +#: Run tests that appear in docstring in the code. +doctest: + MATHICS_CHARACTER_ENCODING="ASCII" $(PYTHON) -m mathics.docpipeline -l pymathics.language -c "Pymathics Language" $o + +# #: Make Mathics PDF manual +# doc mathics.pdf: mathics/doc/tex/data +# (cd mathics/doc/tex && $(MAKE) mathics.pdf) + +#: Remove ChangeLog +rmChangeLog: + $(RM) ChangeLog || true + +#: Create a ChangeLog from git via git log and git2cl +ChangeLog: rmChangeLog + git log --pretty --numstat --summary | $(GIT2CL) >$@ + + +#: Run pytest consistency and style checks +check-consistency-and-style: + MATHICS_LINT=t $(PYTHON) -m pytest test/consistency-and-style diff --git a/pymathics/language/__main__.py b/pymathics/language/__main__.py index f3813b7..062c92a 100644 --- a/pymathics/language/__main__.py +++ b/pymathics/language/__main__.py @@ -13,7 +13,7 @@ from typing import List, Optional from mathics.core.atoms import String -from mathics.core.base import Builtin +from mathics.core.builtin import Builtin from mathics.core.convert.expression import to_mathics_list availableLocales = Locale.getAvailableLocales() diff --git a/test/test_language.py b/test/test_language.py new file mode 100644 index 0000000..785e0c8 --- /dev/null +++ b/test/test_language.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from mathics.core.load_builtin import import_and_load_builtins +from mathics.session import MathicsSession + +import_and_load_builtins() + +session = MathicsSession(character_encoding="ASCII") + + +def check_evaluation(str_expr: str, expected: str, message=""): + """Helper function to test that a Mathics expression against + its results""" + result = session.evaluate(str_expr).value + + if message: + assert result == expected, f"{message}: got: {result}" + else: + assert result == expected + + +def test_hello(): + session.evaluate('LoadModule["pymathics.language"]') == "pymathics.language" + check_evaluation('Alphabet["es"]//Length', 33)