Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail when building with Cython >= 3 #919

Open
badshah400 opened this issue Sep 16, 2023 · 4 comments
Open

Tests fail when building with Cython >= 3 #919

badshah400 opened this issue Sep 16, 2023 · 4 comments

Comments

@badshah400
Copy link

Description

When building Mathics packages for openSUSE Tumbleweed, where the default Cython has already been upgraded to version 3.0.2, we find that a couple of tests fail when running pytest:

[  175s] =========================== short test summary info ============================
[  175s] FAILED test/test_main.py::test_cli - assert None
[  175s] FAILED test/test_returncode.py::test_returncode - AssertionError: assert 1 == 5
[  175s] = 2 failed, 1242 passed, 276 skipped, 16 deselected, 25 xfailed, 64 xpassed, 66 warnings in 158.97s (0:02:38) =

Neither test fails when using Cython version < 3.

How to Reproduce

Build Mathics against Cython >= 3 (version 3.0.2 in my case).

Expected behavior

pytest should pass.

Observed behaviour

[  175s] =================================== FAILURES ===================================
[  175s] ___________________________________ test_cli ___________________________________
[  175s] 
[  175s]     @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires Python 3.7 or higher")
[  175s]     def test_cli():
[  175s]         script_file = osp.join(get_testdir(), "data", "script.m")
[  175s]     
[  175s]         # asserts output contains 'Hello' and '2'
[  175s]         result = subprocess.run(
[  175s]             ["mathics", "-e", "Print[1+1];", "-script", script_file],
[  175s]             capture_output=True,
[  175s]         )
[  175s]     
[  175s] >       assert re.match(r"Hello\s+2", result.stdout.decode("utf-8"))
[  175s] E       assert None
[  175s] E        +  where None = <function match at 0x7f60a3e8a9d0>('Hello\\s+2', '')
[  175s] E        +    where <function match at 0x7f60a3e8a9d0> = re.match
[  175s] E        +    and   '' = <built-in method decode of bytes object at 0x7f60a3fe4d20>('utf-8')
[  175s] E        +      where <built-in method decode of bytes object at 0x7f60a3fe4d20> = b''.decode
[  175s] E        +        where b'' = CompletedProcess(args=['mathics', '-e', 'Print[1+1];', '-script', '/home/abuild/rpmbuild/BUILD/Mathics3-6.0.2/test/data/script.m'], returncode=1, stdout=b'', stderr=b'Traceback (most recent call last):\n  File "/home/abuild/rpmbuild/BUILD/Mathics3-6.0.2/build/flavorbin/mathics", line 33, in <module>\n    sys.exit(load_entry_point(\'Mathics3==6.0.2\', \'console_scripts\', \'mathics\')())\n  File "/usr/lib64/python3.9/site-packages/mathics/main.py", line 369, in main\n    definitions = Definitions(add_builtin=True, extension_modules=extension_modules)\n  File "/usr/lib64/python3.9/site-packages/mathics/core/definitions.py", line 146, in __init__\n    autoload_files(self, ROOT_DIR, "autoload")\n  File "/usr/lib64/python3.9/site-packages/mathics/core/definitions.py", line 55, in autoload_files\n    Expression(SymbolGet, String(path)).evaluate(Evaluation(defs))\n  File "mathics/core/expression.py", line 506, in mathics.core.expression.Expression.evaluate\n    expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)\n  File "mathics/core/expression.py", line 1274, in mathics.core.expression.Expression.rewrite_apply_eval_step\n    result = rule.apply(new, evaluation, fully=False)\n  File "mathics/core/rules.py", line 104, in mathics.core.rules.BaseRule.apply\n    self.pattern.match(yield_match, expression, {}, evaluation, fully=fully)\n  File "mathics/core/pattern.py", line 467, in mathics.core.pattern.ExpressionPattern.match\n    self.head.match(yield_head, expression.get_head(), vars, evaluation)\n  File "mathics/core/pattern.py", line 305, in mathics.core.pattern.AtomPattern.match_symbol\n    yield_func(vars, None)\n  File "mathics/core/pattern.py", line 457, in mathics.core.pattern.ExpressionPattern.match.yield_head\n    self.get_pre_choices(\n  File "mathics/core/pattern.py", line 648, in mathics.core.pattern.ExpressionPattern.get_pre_choices\n    yield_choice(vars)\n  File "mathics/core/pattern.py", line 435, in mathics.core.pattern.ExpressionPattern.match.yield_choice\n    self.match_element(\nTypeError: Argument \'rest_elements\' has incorrect type (expected tuple, got list)\n').stdout
[  175s] 
[  175s] test/test_main.py:25: AssertionError
[  175s] _______________________________ test_returncode ________________________________
[  175s] 
[  175s]     def test_returncode():
[  175s] >       assert subprocess.run(["mathics", "-e", "Quit[5]"]).returncode == 5
[  175s] E       AssertionError: assert 1 == 5
[  175s] E        +  where 1 = CompletedProcess(args=['mathics', '-e', 'Quit[5]'], returncode=1).returncode
[  175s] E        +    where CompletedProcess(args=['mathics', '-e', 'Quit[5]'], returncode=1) = <function run at 0x7f60a3931dc0>(['mathics', '-e', 'Quit[5]'])
[  175s] E        +      where <function run at 0x7f60a3931dc0> = subprocess.run
[  175s] 
[  175s] test/test_returncode.py:12: AssertionError
[  175s] ----------------------------- Captured stderr call -----------------------------
[  175s] Traceback (most recent call last):
[  175s]   File "/home/abuild/rpmbuild/BUILD/Mathics3-6.0.2/build/flavorbin/mathics", line 33, in <module>
[  175s]     sys.exit(load_entry_point('Mathics3==6.0.2', 'console_scripts', 'mathics')())
[  175s]   File "/usr/lib64/python3.9/site-packages/mathics/main.py", line 369, in main
[  175s]     definitions = Definitions(add_builtin=True, extension_modules=extension_modules)
[  175s]   File "/usr/lib64/python3.9/site-packages/mathics/core/definitions.py", line 146, in __init__
[  175s]     autoload_files(self, ROOT_DIR, "autoload")
[  175s]   File "/usr/lib64/python3.9/site-packages/mathics/core/definitions.py", line 55, in autoload_files
[  175s]     Expression(SymbolGet, String(path)).evaluate(Evaluation(defs))
[  175s]   File "mathics/core/expression.py", line 506, in mathics.core.expression.Expression.evaluate
[  175s]     expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)
[  175s]   File "mathics/core/expression.py", line 1274, in mathics.core.expression.Expression.rewrite_apply_eval_step
[  175s]     result = rule.apply(new, evaluation, fully=False)
[  175s]   File "mathics/core/rules.py", line 104, in mathics.core.rules.BaseRule.apply
[  175s]     self.pattern.match(yield_match, expression, {}, evaluation, fully=fully)
[  175s]   File "mathics/core/pattern.py", line 467, in mathics.core.pattern.ExpressionPattern.match
[  175s]     self.head.match(yield_head, expression.get_head(), vars, evaluation)
[  175s]   File "mathics/core/pattern.py", line 305, in mathics.core.pattern.AtomPattern.match_symbol
[  175s]     yield_func(vars, None)
[  175s]   File "mathics/core/pattern.py", line 457, in mathics.core.pattern.ExpressionPattern.match.yield_head
[  175s]     self.get_pre_choices(
[  175s]   File "mathics/core/pattern.py", line 648, in mathics.core.pattern.ExpressionPattern.get_pre_choices
[  175s]     yield_choice(vars)
[  175s]   File "mathics/core/pattern.py", line 435, in mathics.core.pattern.ExpressionPattern.match.yield_choice
[  175s]     self.match_element(
[  175s] TypeError: Argument 'rest_elements' has incorrect type (expected tuple, got list)

Your Environment

Desktop:

  • OS: Linux kernel 6.4, openSUSE Tumbleweed
  • Arch: x86_64

Software versions:

  • Mathics 6.0.2
  • Cython 3.0.2
  • Python 3.9/3.10
  • Numpy 1.25.2
  • Scipy 1.11.1
  • Sympy 1.12

Workarounds

Use cython < 3

Priority

NA

@rocky
Copy link
Member

rocky commented Sep 16, 2023

I will look at this when I get a chance.

Some remarks though.

Cython is optional. In fact is used with pyston it might even be slower than without. So for now you might be just as well omitting Cython as a dependency if you don't want to go with a back-level version.

To date, Cython hasn't given the speedup needed, and it was wishful or shallow thinking that it ever would fix deficiencies in the current implementation.

The only feature that uses this right now is compiling Mathics3 functions and I suspect that is not used all that much.

@badshah400
Copy link
Author

Thanks, good to know. I kind of guessed this and already pushed packages to the openSUSE repositories that do not use cython. Just wanted to keep you informed about the errors.

@rocky
Copy link
Member

rocky commented Sep 17, 2023

Thanks for the information and for packaging for openSUSE.

@rocky
Copy link
Member

rocky commented Oct 7, 2023

I just had a chance to look at. I do not think this has anything to do with Cython. These tests are failing because the results in one test and the return code in the other do not match what is expected. On ubuntu 23.04 I am seeing that things work as expected with Cython 3.0.3 installed.

Try running this and see whether you get the same output as I do:

$ mathics -e "Print[1+1];" -script data/script.m; echo $?
Hello
2
None

0
$ mathics -e "Quit[5];" ; echo $?
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants