Skip to content

Commit f9f17c1

Browse files
committed
Expand and correct
1 parent ba76164 commit f9f17c1

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ install:
3838
$(PYTHON) setup.py install
3939

4040
# Run tests
41-
check: pytest doctest
41+
check: pytest
4242

4343
#: Remove derived files
4444
clean: clean-pyc
@@ -52,14 +52,6 @@ pytest:
5252
py.test test $o
5353

5454

55-
# #: Create data that is used to in Django docs and to build TeX PDF
56-
# doc-data mathics/doc/tex/data: mathics/builtin/*.py mathics/doc/documentation/*.mdoc mathics/doc/documentation/images/*
57-
# $(PYTHON) mathics/test.py -ot -k
58-
59-
#: Run tests that appear in docstring in the code.
60-
doctest:
61-
$(PYTHON) mathics/test.py $o
62-
6355
# #: Make Mathics PDF manual
6456
# doc mathics.pdf: mathics/doc/tex/data
6557
# (cd mathics/doc/tex && $(MAKE) mathics.pdf)

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Then to the function ``Pymathics\`Hello[]`` and the variable ``PyMathics\`$Hello
2525
In[1]:= LoadModule["pymathics.hello"]
2626
Out[1]= pymathics.hello
2727

28-
In[2]:= PyMathics`Hello["World"]
28+
In[2]:= Hello["World"]
2929
Out[2]:= Hello, World!
3030

3131
In[3]:= PyMathics`$HelloUser

pymathics/hello/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
2020
::
2121
22-
In[2]:= PyMathics`Hello["World"]
22+
In[2]:= Hello["World"]
2323
Out[2]:= Hello, World!
2424
2525
In[3]:= PyMathics`$HelloUser
2626
Out[3]:= $your-login-name$
2727
2828
"""
2929

30-
import os
3130
from pymathics.hello.version import __version__
3231
from pymathics.hello.__main__ import Hello # noqa
3332

pymathics/hello/__main__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ class Hello(Builtin):
77
<dt>'Hello'[$person$]
88
<dd>An example function in a Python-importable Mathics module.
99
</dl>
10-
>> PyMathics`Hello["World"]
10+
>> Hello["World"]
1111
= Hello, World!
1212
"""
1313

14-
def apply(self, person, evaluation):
15-
"PyMathics`Hello[person_]"
14+
# The function below should start with "apply"
15+
def apply_with_name(self, person, evaluation):
16+
"%(name)s[person_String]"
17+
# %(name)s is just a more flexible way of writing "Hello".
18+
# If the class name changes, so will the above pattern.
19+
# The above pattern matches Hello with a single string argument.
20+
# See https://reference.wolfram.com/language/tutorial/Patterns.html#7301
21+
# and https://reference.wolfram.com/language/ref/Cases.html
1622
return String("Hello, %s!" % person.get_string_value())

pymathics/hello/version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env python3
21
# -*- coding: utf-8 -*-
32

43

54
# This file is suitable for sourcing inside POSIX shell as
65
# well as importing into Python. That's why there is no
76
# space around "=" below.
8-
__version__="1.0.0"
7+
__version__="1.0.1.dev0" # noqa

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import sys
55
import platform
6-
import os
76
from setuptools import setup, find_namespace_packages
87

98
# Ensure user has the correct Python version
@@ -20,7 +19,7 @@
2019
name="pymathics-hello",
2120
version=__version__,
2221
packages=find_namespace_packages(include=["pymathics.*"]),
23-
install_requires=["mathics3>=1.1.0"],
22+
install_requires=["Mathics3>=1.1.0"],
2423
# don't pack Mathics in egg because of media files, etc.
2524
zip_safe=False,
2625
# metadata for upload to PyPI

test/test_hello.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from mathics.session import MathicsSession
2+
3+
session = MathicsSession(add_builtin=True, catch_interrupt=False)
4+
5+
def check_evaluation(str_expr: str, expected: str, message=""):
6+
"""Helper function to test that a WL expression against
7+
its results"""
8+
result = session.evaluate(str_expr).value
9+
10+
if message:
11+
assert result == expected, "%s: got: %s" % (message, result)
12+
else:
13+
assert result == expected
14+
15+
16+
def test_hello():
17+
session.evaluate('LoadModule["pymathics.hello"]') == "pymathics.hello"
18+
check_evaluation('Hello["World"]', "Hello, World!")

0 commit comments

Comments
 (0)