From 57147a724aa2237a1a88e2b16e845f1853c7dbd7 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 10 Sep 2025 06:24:49 +0300 Subject: [PATCH 1/2] Workaround support for multiple statements in CLI Closes #996 --- mpmath/__main__.py | 2 +- mpmath/tests/test_cli.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mpmath/__main__.py b/mpmath/__main__.py index 004f281e..827a5228 100644 --- a/mpmath/__main__.py +++ b/mpmath/__main__.py @@ -131,7 +131,7 @@ del ip source += "\n" try: - code = self.compile(source, filename, symbol) + code = self.compile(source, filename, 'exec') except (OverflowError, SyntaxError, ValueError): if sys.version_info >= (3, 13): self.showsyntaxerror(filename, source=source) diff --git a/mpmath/tests/test_cli.py b/mpmath/tests/test_cli.py index b0cc661f..56af362a 100644 --- a/mpmath/tests/test_cli.py +++ b/mpmath/tests/test_cli.py @@ -17,9 +17,13 @@ if platform.python_implementation() == 'PyPy': class Console(pexpect.spawn): """Spawned console for testing.""" - def __init__(self, command, timeout=60): + def __init__(self, command, timeout=60, _dumb=True): env = os.environ.copy() - env['TERM'] = 'dumb' + if _dumb: + env['TERM'] = 'dumb' + else: + env['TERM'] = 'xterm' + env['NO_COLOR'] = '1' super().__init__(command, timeout=timeout, encoding='utf-8', env=env) def __del__(self): @@ -122,19 +126,23 @@ def test_bare_console_wrap_floats(): assert c.expect_exact("mpf('2.0')\r\n>>> ") == 0 +@pytest.mark.skipif(sys.version_info < (3, 13), + reason="XXX: uses new REPL") def test_bare_console_pretty(): c = Console(f'{sys.executable} -m mpmath --simple-prompt --no-ipython --prec 100 ' - "--colors 'NoColor'") + "--colors 'NoColor'", _dumb=False) - assert c.expect_exact('>>> ') == 0 + assert c.expect('>>> ') == 0 assert c.send("10.9\r\n") == 6 - assert c.expect_exact("10.899999999999999999999999999995\r\n>>> ") == 0 + assert c.expect("10.899999999999999999999999999995") == 0 assert c.send("def f():\r\n x = ?\r\n\r\n") == 21 assert c.expect('SyntaxError:') == 0 - assert c.send('def f():\r\n x = 1.1\n return x + 1\n\r\n\n') == 42 - assert c.expect_exact('>>> ') == 0 + assert c.send('def f():\r\n return 1.1\r\n\r\n') == 26 + assert c.expect('>>> ') == 0 assert c.send("f()\r\n") == 5 - assert c.expect_exact('2.0999999999999999999999999999987\r\n>>> ') == 0 + assert c.expect('1.1000000000000000000000000000003') == 0 + assert c.send("a = 2.1; a\r\n") == 12 + assert c.expect('2.0999999999999999999999999999987') == 0 def test_mpmath_version(): From 4247f6a7eaa9feff2a57c35da7794ac10c6f8632 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 2 Oct 2025 08:21:06 +0300 Subject: [PATCH 2/2] Pin pytest-cov (<7) See pytest-dev/pytest-cov#720 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fd9f58a3..f3bee8ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ Documentation = 'http://mpmath.org/doc/current/' [project.optional-dependencies] tests = ['pytest>=6', 'numpy', 'packaging', 'pytest-timeout', 'matplotlib', 'pexpect', 'ipython', 'hypothesis'] -develop = ['mpmath[tests]', 'flake518>=1.5', 'pytest-cov', 'wheel', 'build'] +develop = ['mpmath[tests]', 'flake518>=1.5', 'pytest-cov<7', 'wheel', 'build'] gmpy2 = ['gmpy2>=2.3.0a1'] gmpy = ['mpmath[gmpy2]'] gmp = ['python-gmp>=0.4']