Skip to content

Commit

Permalink
Merge pull request #892 from mmatera/fixtestengine
Browse files Browse the repository at this point in the history
More fixes to the test engine
  • Loading branch information
GarkGarcia authored Sep 15, 2020
2 parents 4e0ad0d + 4f41b39 commit 9d8c3d8
Show file tree
Hide file tree
Showing 21 changed files with 407 additions and 372 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ all: develop
build:
$(PYTHON) ./setup.py build

#: Set up to run from source
#: Set up to run from the source tree
develop:
$(PIP) install -e .

#: Set up to run from source
#: Install mathics
install:
$(PYTHON) setup.py install

Expand All @@ -39,12 +39,18 @@ clean:
pytest:
py.test test $o


#: Run mathics/test.py asking for output to build "mathics/doc/tex/data"

mathics/doc/tex/data:
$(PYTHON) mathics/test.py -o

#: Run tests that appear in docstring in the code.
doctest:
$(PYTHON) mathics/test.py $(output)

#: Make Mathics PDF manual
doc:
doc: mathics/doc/tex/data
(cd mathics && $(PYTHON) test.py -t && \
cd doc/tex && make)

Expand Down
46 changes: 23 additions & 23 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,38 +897,38 @@ class CubeRoot(Builtin):
#> CubeRoot[-5]
= -5 ^ (1 / 3)
#> CubeRoot[-510000]
= -10 510 ^ (1 / 3)
#> CubeRoot[-5.1]
= -1.7213
= -1.7213
#> CubeRoot[b]
= b ^ (1 / 3)
#> CubeRoot[-0.5]
= -0.793701
#> CubeRoot[3 + 4 I]
: The parameter 3 + 4 I should be real valued.
= (3 + 4 I) ^ (1 / 3)
"""

attributes = {'Listable', 'NumericFunction', 'ReadProtected'}

messages = {
'preal': 'The parameter `1` should be real valued.',
}

rules = {
'CubeRoot[n_?NumericQ]': 'If[n > 0, Power[n, Divide[1, 3]], Times[-1, Power[Times[-1, n], Divide[1, 3]]]]',
'CubeRoot[n_]': 'Power[n, Divide[1, 3]]',
}

def apply(self, n, evaluation):
'CubeRoot[n_Complex]'

evaluation.message('CubeRoot', 'preal', n)
return Expression('Power', n, Expression('Divide', 1, 3))

Expand Down Expand Up @@ -1204,7 +1204,7 @@ class Sign(Builtin):
<dt>'Sign[$x$]'
<dd>return -1, 0, or 1 depending on whether $x$ is negative, zero, or positive.
</dl>
>> Sign[19]
= 1
>> Sign[-6]
Expand All @@ -1225,27 +1225,27 @@ class Sign(Builtin):
#> Sign["20"]
= Sign[20]
"""

# Sympy and mpmath do not give the desired form of complex number
# sympy_name = 'sign'
# mpmath_name = 'sign'

attributes = ('Listable', 'NumericFunction')

messages = {
'argx': 'Sign called with `1` arguments; 1 argument is expected.',
}

def apply(self, x, evaluation):
'Sign[x_]'
if isinstance(x, Complex):
return Expression('Times', x, Expression('Power', Expression('Abs', x), -1))

sympy_x = x.to_sympy()
if sympy_x is None:
return None
return from_sympy(sympy.sign(sympy_x))

def apply_error(self, x, seqs, evaluation):
'Sign[x_, seqs__]'
return evaluation.message('Sign', 'argx', Integer(len(seqs.get_sequence())+1))
Expand Down Expand Up @@ -1808,7 +1808,7 @@ class Sum(_IterationFunction, SympyFunction):
: "a=Sum[x^k*Sum[y^l,{l,0,4}],{k,0,4}]" cannot be followed by "]" (line 1 of "<test>").
## Issue431
#> Sum[2^(-i), {i, 1, \[Infinity]}]
#> Sum[2^(-i), {i, 1, \\[Infinity]}]
= 1
## Issue302
Expand All @@ -1827,7 +1827,7 @@ class Sum(_IterationFunction, SympyFunction):
rules.update({
'MakeBoxes[Sum[f_, {i_, a_, b_, 1}],'
' form:StandardForm|TraditionalForm]': (
r'RowBox[{SubsuperscriptBox["\[Sum]",'
r'RowBox[{SubsuperscriptBox["\\[Sum]",'
r' RowBox[{MakeBoxes[i, form], "=", MakeBoxes[a, form]}],'
r' MakeBoxes[b, form]], MakeBoxes[f, form]}]'),
})
Expand All @@ -1841,8 +1841,8 @@ def to_sympy(self, expr, **kwargs):
arg_kwargs = kwargs.copy()
arg_kwargs['convert_all_global_functions'] = True
arg = expr.leaves[0].to_sympy(**arg_kwargs)
bounds = (index.leaves[0].to_sympy(**kwargs),
index.leaves[1].to_sympy(**kwargs),
bounds = (index.leaves[0].to_sympy(**kwargs),
index.leaves[1].to_sympy(**kwargs),
index.leaves[2].to_sympy(**kwargs))

if arg is not None and None not in bounds:
Expand Down Expand Up @@ -1897,7 +1897,7 @@ class Product(_IterationFunction, SympyFunction):
rules.update({
'MakeBoxes[Product[f_, {i_, a_, b_, 1}],'
' form:StandardForm|TraditionalForm]': (
r'RowBox[{SubsuperscriptBox["\[Product]",'
r'RowBox[{SubsuperscriptBox["\\[Product]",'
r' RowBox[{MakeBoxes[i, form], "=", MakeBoxes[a, form]}],'
r' MakeBoxes[b, form]], MakeBoxes[f, form]}]'),
})
Expand Down
64 changes: 32 additions & 32 deletions mathics/builtin/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,17 +812,17 @@ def _get_usage_string(symbol, evaluation, htmlout=False):
usagetext = Doc(bio.__class__.__doc__).text(0)
usagetext = re.sub(r'\$([0-9a-zA-Z]*)\$', r'\1', usagetext)
# For built-in symbols, looks for a docstring.
# if symbol.function. is Builtin:
# if symbol.function. is Builtin:
# evaluation.print_out(String("found: " + usagetext))
# usagetext = information_interpret_doc_string(symbol.__doc__)
# Looks for the "usage" message. For built-in symbols, if there is an "usage" chain, overwrite the __doc__ information.
for rulemsg in ruleusage:
if rulemsg.pattern.expr.leaves[1].__str__() == "\"usage\"":
usagetext = rulemsg.replace.value
usagetext = rulemsg.replace.value
return usagetext


class Information(PrefixOperator):
class Information(PrefixOperator):
"""
<dl>
<dt>'Information[$symbol$]'
Expand Down Expand Up @@ -858,7 +858,7 @@ class Information(PrefixOperator):
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
. evaluates expr with i taking on the values e1, e2,
. ..., ei.
.
.
>> Information[Table]
=
Expand Down Expand Up @@ -886,18 +886,18 @@ def format_definition(self, symbol, evaluation, options, grid=True):
'StandardForm,TraditionalForm,OutputForm: Information[symbol_, OptionsPattern[Information]]'
from mathics.core.expression import from_python
lines = []
if isinstance(symbol, String):
if isinstance(symbol, String):
evaluation.print_out(symbol)
evaluation.evaluate(Expression('Information', Symbol('System`String')))
evaluation.evaluate(Expression('Information', Symbol('System`String')))
return
if not isinstance(symbol, Symbol):
evaluation.message('Information', 'notfound', symbol)
if not isinstance(symbol, Symbol):
evaluation.message('Information', 'notfound', symbol)
return Symbol('Null')
# Print the "usage" message if available.
usagetext = _get_usage_string(symbol, evaluation)
if usagetext is not None:
lines.append(String(usagetext))

if self.get_option(options, 'LongForm', evaluation).to_python():
self.show_definitions(symbol, evaluation, lines)

Expand Down Expand Up @@ -977,7 +977,7 @@ def rhs(expr):
Expression('List', *(
Expression('Rule', Symbol(name), value)
for name, value in options)))))
return
return

def format_definition_input(self, symbol, evaluation, options):
'InputForm: Information[symbol_, OptionsPattern[Information]]'
Expand Down Expand Up @@ -1047,7 +1047,7 @@ class Information(PrefixOperator):
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
. evaluates expr with i taking on the values e1, e2,
. ..., ei.
.
.
>> Information[Table]
=
Expand Down Expand Up @@ -1241,7 +1241,7 @@ class Information(PrefixOperator):
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
. evaluates expr with i taking on the values e1, e2,
. ..., ei.
.
.
>> Information[Table]
=
Expand Down Expand Up @@ -2098,23 +2098,23 @@ class LoadModule(Builtin):
>> LoadModule["sys"]
: Python module sys is not a pymathics module.
= $Failed
>> LoadModule["pymathics.testpymathicsmodule"]
= pymathics.testpymathicsmodule
>> MyPyTestContext`MyPyTestFunction[a]
= This is a PyMathics output
>> MyPyTestContext`MyPyTestSymbol
= 1234
>> ?? MyPyTestContext`MyPyTestFunction
=
. 'MyPyTestFunction'[m]
. Just an example function in pymathics module.
.
. Attributes[MyPyTestContext`MyPyTestFunction] = {HoldFirst, OneIdentity, Protected}
>> Quit[]
>> MyPyTestContext`MyPyTestSymbol
= MyPyTestContext`MyPyTestSymbol
>> ?? MyPyTestContext`MyPyTestFunction
= Null
# >> LoadModule["pymathics.testpymathicsmodule"]
# = pymathics.testpymathicsmodule
# >> MyPyTestContext`MyPyTestFunction[a]
# = This is a PyMathics output
# >> MyPyTestContext`MyPyTestSymbol
# = 1234
# >> ?? MyPyTestContext`MyPyTestFunction
# =
# . 'MyPyTestFunction'[m]
# . Just an example function in pymathics module.
# .
# . Attributes[MyPyTestContext`MyPyTestFunction] = {HoldFirst, OneIdentity, Protected}
# >> Quit[]
#n>> MyPyTestContext`MyPyTestSymbol
# = MyPyTestContext`MyPyTestSymbol
# >> ?? MyPyTestContext`MyPyTestFunction
# = Null
"""
name = "LoadModule"
messages = {'notfound': 'Python module `1` does not exist.',
Expand All @@ -2125,12 +2125,12 @@ def apply(self, module, evaluation):
try:
module_loaded = evaluation.definitions.load_pymathics_module(module.value)
except PyMathicsLoadException as e:
evaluation.message(self.name, 'notmathicslib', module)
evaluation.message(self.name, 'notmathicslib', module)
return Symbol("$Failed")
except ImportError as e:
evaluation.message(self.get_name(), 'notfound', module)
evaluation.message(self.get_name(), 'notfound', module)
return Symbol('$Failed')
except PyMathicsLoadException as e:
evaluation.message(self.get_name(), 'notmathicslib', module)
evaluation.message(self.get_name(), 'notmathicslib', module)
return Symbol('$Failed')
return module
Loading

0 comments on commit 9d8c3d8

Please sign in to comment.