From f9f17c106d18ebb2cd4bc8db9bd1f3927e44d9a4 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 20 Jun 2021 16:42:10 -0400 Subject: [PATCH] Expand and correct --- Makefile | 10 +--------- README.rst | 2 +- pymathics/hello/__init__.py | 3 +-- pymathics/hello/__main__.py | 12 +++++++++--- pymathics/hello/version.py | 3 +-- setup.py | 3 +-- test/test_hello.py | 18 ++++++++++++++++++ 7 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 test/test_hello.py diff --git a/Makefile b/Makefile index 1d1a34d..98858b4 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ install: $(PYTHON) setup.py install # Run tests -check: pytest doctest +check: pytest #: Remove derived files clean: clean-pyc @@ -52,14 +52,6 @@ pytest: py.test 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: - $(PYTHON) mathics/test.py $o - # #: Make Mathics PDF manual # doc mathics.pdf: mathics/doc/tex/data # (cd mathics/doc/tex && $(MAKE) mathics.pdf) diff --git a/README.rst b/README.rst index 94838a6..e8d33f4 100644 --- a/README.rst +++ b/README.rst @@ -25,7 +25,7 @@ Then to the function ``Pymathics\`Hello[]`` and the variable ``PyMathics\`$Hello In[1]:= LoadModule["pymathics.hello"] Out[1]= pymathics.hello - In[2]:= PyMathics`Hello["World"] + In[2]:= Hello["World"] Out[2]:= Hello, World! In[3]:= PyMathics`$HelloUser diff --git a/pymathics/hello/__init__.py b/pymathics/hello/__init__.py index eeb9191..1f46612 100644 --- a/pymathics/hello/__init__.py +++ b/pymathics/hello/__init__.py @@ -19,7 +19,7 @@ :: - In[2]:= PyMathics`Hello["World"] + In[2]:= Hello["World"] Out[2]:= Hello, World! In[3]:= PyMathics`$HelloUser @@ -27,7 +27,6 @@ """ -import os from pymathics.hello.version import __version__ from pymathics.hello.__main__ import Hello # noqa diff --git a/pymathics/hello/__main__.py b/pymathics/hello/__main__.py index a60984f..690789d 100644 --- a/pymathics/hello/__main__.py +++ b/pymathics/hello/__main__.py @@ -7,10 +7,16 @@ class Hello(Builtin):
'Hello'[$person$]
An example function in a Python-importable Mathics module. - >> PyMathics`Hello["World"] + >> Hello["World"] = Hello, World! """ - def apply(self, person, evaluation): - "PyMathics`Hello[person_]" + # The function below should start with "apply" + def apply_with_name(self, person, evaluation): + "%(name)s[person_String]" + # %(name)s is just a more flexible way of writing "Hello". + # If the class name changes, so will the above pattern. + # The above pattern matches Hello with a single string argument. + # See https://reference.wolfram.com/language/tutorial/Patterns.html#7301 + # and https://reference.wolfram.com/language/ref/Cases.html return String("Hello, %s!" % person.get_string_value()) diff --git a/pymathics/hello/version.py b/pymathics/hello/version.py index b14a045..c0fcf70 100644 --- a/pymathics/hello/version.py +++ b/pymathics/hello/version.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is suitable for sourcing inside POSIX shell as # well as importing into Python. That's why there is no # space around "=" below. -__version__="1.0.0" +__version__="1.0.1.dev0" # noqa diff --git a/setup.py b/setup.py index ad6104c..34090fc 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import sys import platform -import os from setuptools import setup, find_namespace_packages # Ensure user has the correct Python version @@ -20,7 +19,7 @@ name="pymathics-hello", version=__version__, packages=find_namespace_packages(include=["pymathics.*"]), - install_requires=["mathics3>=1.1.0"], + install_requires=["Mathics3>=1.1.0"], # don't pack Mathics in egg because of media files, etc. zip_safe=False, # metadata for upload to PyPI diff --git a/test/test_hello.py b/test/test_hello.py new file mode 100644 index 0000000..438a927 --- /dev/null +++ b/test/test_hello.py @@ -0,0 +1,18 @@ +from mathics.session import MathicsSession + +session = MathicsSession(add_builtin=True, catch_interrupt=False) + +def check_evaluation(str_expr: str, expected: str, message=""): + """Helper function to test that a WL expression against + its results""" + result = session.evaluate(str_expr).value + + if message: + assert result == expected, "%s: got: %s" % (message, result) + else: + assert result == expected + + +def test_hello(): + session.evaluate('LoadModule["pymathics.hello"]') == "pymathics.hello" + check_evaluation('Hello["World"]', "Hello, World!")