Skip to content

Commit

Permalink
Expand and correct
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Jun 20, 2021
1 parent ba76164 commit f9f17c1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install:
$(PYTHON) setup.py install

# Run tests
check: pytest doctest
check: pytest

#: Remove derived files
clean: clean-pyc
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pymathics/hello/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
::
In[2]:= PyMathics`Hello["World"]
In[2]:= Hello["World"]
Out[2]:= Hello, World!
In[3]:= PyMathics`$HelloUser
Out[3]:= $your-login-name$
"""

import os
from pymathics.hello.version import __version__
from pymathics.hello.__main__ import Hello # noqa

Expand Down
12 changes: 9 additions & 3 deletions pymathics/hello/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ class Hello(Builtin):
<dt>'Hello'[$person$]
<dd>An example function in a Python-importable Mathics module.
</dl>
>> 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())
3 changes: 1 addition & 2 deletions pymathics/hello/version.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import sys
import platform
import os
from setuptools import setup, find_namespace_packages

# Ensure user has the correct Python version
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/test_hello.py
Original file line number Diff line number Diff line change
@@ -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!")

0 comments on commit f9f17c1

Please sign in to comment.