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

Ability to run the SymPy tests #10

Open
asmeurer opened this issue May 10, 2022 · 2 comments
Open

Ability to run the SymPy tests #10

asmeurer opened this issue May 10, 2022 · 2 comments

Comments

@asmeurer
Copy link
Member

It would be nice to be able to run the SymPy test suite, so that we can see how much of SymPy actually works.

Right now if you type

test()

it fails with

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 test()

File /lib/python3.10/site-packages/sympy/testing/runtests.py:486, in test(subprocess, rerun, *paths, **kwargs)
    484 for i in range(rerun, -1, -1):
    485     print_counter(i)
--> 486     ret = run_in_subprocess_with_hash_randomization("_test",
    487                 function_args=paths, function_kwargs=kwargs)
    488     if ret is False:
    489         break

File /lib/python3.10/site-packages/sympy/testing/runtests.py:243, in run_in_subprocess_with_hash_randomization(function, function_args, function_kwargs, command, module, force)
    237 cwd = get_sympy_dir()
    238 # Note, we must return False everywhere, not None, as subprocess.call will
    239 # sometimes return None.
    240 
    241 # First check if the Python version supports hash randomization
    242 # If it doesn't have this support, it won't recognize the -R flag
--> 243 p = subprocess.Popen([command, "-RV"], stdout=subprocess.PIPE,
    244                      stderr=subprocess.STDOUT, cwd=cwd)
    245 p.communicate()
    246 if p.returncode != 0:

File /lib/python3.10/subprocess.py:966, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    962         if self.text_mode:
    963             self.stderr = io.TextIOWrapper(self.stderr,
    964                     encoding=encoding, errors=errors)
--> 966     self._execute_child(args, executable, preexec_fn, close_fds,
    967                         pass_fds, cwd, env,
    968                         startupinfo, creationflags, shell,
    969                         p2cread, p2cwrite,
    970                         c2pread, c2pwrite,
    971                         errread, errwrite,
    972                         restore_signals,
    973                         gid, gids, uid, umask,
    974                         start_new_session)
    975 except:
    976     # Cleanup if the child failed starting.
    977     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File /lib/python3.10/subprocess.py:1775, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
   1773     fds_to_keep = set(pass_fds)
   1774     fds_to_keep.add(errpipe_write)
-> 1775     self.pid = _posixsubprocess.fork_exec(
   1776             args, executable_list,
   1777             close_fds, tuple(sorted(map(int, fds_to_keep))),
   1778             cwd, env_list,
   1779             p2cread, p2cwrite, c2pread, c2pwrite,
   1780             errread, errwrite,
   1781             errpipe_read, errpipe_write,
   1782             restore_signals, start_new_session,
   1783             gid, gids, uid, umask,
   1784             preexec_fn)
   1785     self._child_created = True
   1786 finally:
   1787     # be sure the FD is closed no matter what

OSError: [Errno 52] Function not implemented

because it wants to run the tests in a subprocess. If you do

test(subprocess=False)

It fails with

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 test(subprocess=False)

File /lib/python3.10/site-packages/sympy/testing/runtests.py:498, in test(subprocess, rerun, *paths, **kwargs)
    496 for i in range(rerun, -1, -1):
    497     print_counter(i)
--> 498     val = not bool(_test(*paths, **kwargs))
    499     if not val or i == 0:
    500         return val

File /lib/python3.10/site-packages/sympy/testing/runtests.py:568, in _test(verbose, tb, kw, pdb, colors, force_colors, sort, seed, timeout, fail_on_timeout, slow, enhance_asserts, split, time_balance, blacklist, fast_threshold, slow_threshold, *paths)
    564     matched = split_list(matched, split, density=density)
    566 t._testfiles.extend(matched)
--> 568 return int(not t.test(sort=sort, timeout=timeout, slow=slow,
    569     enhance_asserts=enhance_asserts, fail_on_timeout=fail_on_timeout))

File /lib/python3.10/site-packages/sympy/testing/runtests.py:1134, in SymPyTests.test(self, sort, timeout, slow, enhance_asserts, fail_on_timeout)
   1132     random.seed(self._seed)
   1133     random.shuffle(self._testfiles)
-> 1134 self._reporter.start(self._seed)
   1135 for f in self._testfiles:
   1136     try:

File /lib/python3.10/site-packages/sympy/testing/runtests.py:2157, in PyTestReporter.start(self, seed, msg)
   2156 def start(self, seed=None, msg="test process starts"):
-> 2157     self.write_center(msg)
   2158     executable = sys.executable
   2159     v = tuple(sys.version_info)

File /lib/python3.10/site-packages/sympy/testing/runtests.py:2148, in PyTestReporter.write_center(self, text, delim)
   2146 idx = (width - len(text)) // 2
   2147 t = delim*idx + text + delim*(width - idx - len(text))
-> 2148 self.write(t + "\n")

File /lib/python3.10/site-packages/sympy/testing/runtests.py:2124, in PyTestReporter.write(self, text, color, align, width, force_colors)
   2122 if IS_WINDOWS:
   2123     text = text.encode('raw_unicode_escape').decode('utf8', 'ignore')
-> 2124 elif not sys.stdout.encoding.lower().startswith('utf'):
   2125     text = text.encode(sys.stdout.encoding, 'backslashreplace'
   2126                       ).decode(sys.stdout.encoding)
   2128 if color == "":

AttributeError: 'LiteStream' object has no attribute 'encoding

Presumably some improvements could be made to pyiodide and/or jupyterlite here. If that is hard to do, we can fix the SymPy test function to work around these issues, or monkeypatch for the online shell.

@asmeurer
Copy link
Member Author

Actually it looks like the tests aren't even shipped with the package. That's probably a good thing, since it reduces the size considerably, but there should be some way to include them so that we can run the tests. Is it possible to not ship each tests submodule by default but automatically load them when they are imported (which would only happen if the tests are actually run)?

@agriyakhetarpal
Copy link
Collaborator

agriyakhetarpal commented Jan 2, 2025

Hi Aaron, the tests have indeed been removed from the package to reduce the wheel size. To include them—which I would not recommend—the SymPy recipe needs to have the build/unvendor-tests: key set to false.

I think sympy/sympy#27183 is the right candidate to have closed this issue, with which the test suite runs in CI in a Pyodide/WASM runtime.

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