Skip to content

Commit 3d859da

Browse files
committed
Start testing
1 parent 2e4f60d commit 3d859da

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ develop: pypi-setup
4949
install: pypi-setup
5050
$(PYTHON) setup.py install
5151

52-
# Run tests
53-
check: pytest doctest
52+
#: Run tests
53+
check: pytest
5454

5555
#: Remove derived files
5656
clean: clean-pyc

admin-tools/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.python-version

test/__init__.py

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

test/helper.py

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

test/test_natlang.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
from .helper import session, check_evaluation
3+
4+
import sys
5+
from mathics.core.parser import parse, SingleLineFeeder
6+
from mathics.core.definitions import Definitions
7+
from mathics.core.evaluation import Evaluation
8+
import pytest
9+
10+
def test_natlang():
11+
12+
session.evaluate(
13+
"""
14+
LoadModule["pymathics.natlang"]
15+
"""
16+
)
17+
18+
for str_expr, str_expected, message in (
19+
(
20+
'WordCount["A long time ago"]',
21+
"4",
22+
"WordCount",
23+
),
24+
(
25+
'TextWords["Hickory, dickory, dock! The mouse ran up the clock."]',
26+
'System`List["Hickory", "dickory", "dock", "The", "mouse", "ran", "up", "the", "clock"]',
27+
"TextWords",
28+
),
29+
(
30+
'TextSentences["Night and day. Day and night."]',
31+
'System`List["Night and day.", "Day and night."]',
32+
"TextSentences",
33+
),
34+
(
35+
'TextSentences["Mr. Jones met Mrs. Jones."]',
36+
'System`List["Mr. Jones met Mrs. Jones."]',
37+
"TextSentences with Abbreviations",
38+
),
39+
(
40+
'DeleteStopwords[{"Somewhere", "over", "the", "rainbow"}]',
41+
'System`List["rainbow"]',
42+
"DeleteStopWords",
43+
),
44+
(
45+
'WordFrequency["Apple Tree", "apple", IgnoreCase -> True]',
46+
"0.5",
47+
"WordFrequency",
48+
),
49+
(
50+
'TextCases["I was in London last year.", "Pronoun"]',
51+
'System`List["I"]',
52+
"TextCases",
53+
),
54+
):
55+
check_evaluation(str_expr, str_expected, message)

0 commit comments

Comments
 (0)