From bf850577c29ab3a822a79b92823afb649faf7c66 Mon Sep 17 00:00:00 2001 From: Joost van Zwieten Date: Tue, 19 Dec 2023 15:08:11 +0100 Subject: [PATCH] fix invalid escape sequences in strings --- examples/cahnhilliard.py | 2 +- tests/test_function.py | 8 ++++---- tests/test_solver.py | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/cahnhilliard.py b/examples/cahnhilliard.py index ec57c4826..bb1916e2b 100644 --- a/examples/cahnhilliard.py +++ b/examples/cahnhilliard.py @@ -62,7 +62,7 @@ def main(size: Length = parse('10cm'), energy: E(φ) := ∫_Ω ψ(φ) σ / ε + ∫_Ω .5 σ ε ‖∇φ‖² + ∫_Γ (σm + φ σd) - \ \ \ + ╲ ╲ ╲ mixing energy interface energy wall energy Proof: the time derivative of `E` followed by substitution of the strong form diff --git a/tests/test_function.py b/tests/test_function.py index 8ac995722..e2f21baa5 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -24,7 +24,7 @@ def test_cast_invalid_argument(self): function.Array.cast('132') def test_cast_different_shapes(self): - with self.assertRaisesRegex(ValueError, 'cannot convert \[\[1, 2, 3\], \[4, 5\]\] to Array: all input arrays must have the same shape'): + with self.assertRaisesRegex(ValueError, 'cannot convert \\[\\[1, 2, 3\\], \\[4, 5\\]\\] to Array: all input arrays must have the same shape'): function.Array.cast([[1,2,3],[4,5]]) def test_ndim(self): @@ -53,11 +53,11 @@ def test_iter_known(self): self.assertEqual(b.as_evaluable_array.eval(), 2) def test_binop_notimplemented(self): - with self.assertRaisesRegex(TypeError, '^operand type\(s\) all returned NotImplemented from __array_ufunc__'): + with self.assertRaisesRegex(TypeError, '^operand type\\(s\\) all returned NotImplemented from __array_ufunc__'): function.Argument('a', ()) + '1' def test_rbinop_notimplemented(self): - with self.assertRaisesRegex(TypeError, '^operand type\(s\) all returned NotImplemented from __array_ufunc__'): + with self.assertRaisesRegex(TypeError, '^operand type\\(s\\) all returned NotImplemented from __array_ufunc__'): '1' + function.Argument('a', ()) def test_different_argument_shapes(self): @@ -72,7 +72,7 @@ def test_index(self): self.assertEqual(function.Array.cast(2).__index__(), 2) with self.assertRaisesRegex(ValueError, "cannot convert non-constant array to index: arguments=foo"): function.Argument('foo', shape=(), dtype=int).__index__() - with self.assertRaisesRegex(ValueError, "cannot convert non-scalar array to index: shape=\(2,\)"): + with self.assertRaisesRegex(ValueError, "cannot convert non-scalar array to index: shape=\\(2,\\)"): function.Array.cast([2, 3]).__index__() with self.assertRaisesRegex(ValueError, "cannot convert non-integer array to index: dtype=float"): function.Array.cast(2.5).__index__() diff --git a/tests/test_solver.py b/tests/test_solver.py index ce525ffc4..68eb0f6a3 100644 --- a/tests/test_solver.py +++ b/tests/test_solver.py @@ -34,9 +34,9 @@ def _test_recursion_cache(testcase, solver_iter): with testcase.assertLogs('nutils', 'DEBUG') as cm: v = read(length) testcase.assertEqual(v, reference[:length]) - testcase.assertRegex('\n'.join(cm.output), '\[cache\.Recursion [0-9a-f]{40}\] start iterating') - testcase.assertRegex('\n'.join(cm.output), '\[cache\.Recursion [0-9a-f]{40}\.0000\] load' if i and max(lengths[:i]) > 0 - else '\[cache\.Recursion [0-9a-f]{40}\.0000\] cache exhausted') + testcase.assertRegex('\n'.join(cm.output), '\\[cache\\.Recursion [0-9a-f]{40}\\] start iterating') + testcase.assertRegex('\n'.join(cm.output), '\\[cache\\.Recursion [0-9a-f]{40}\\.0000\\] load' if i and max(lengths[:i]) > 0 + else '\\[cache\\.Recursion [0-9a-f]{40}\\.0000\\] cache exhausted') def _test_solve_cache(testcase, solver_gen): @@ -46,10 +46,10 @@ def _test_solve_cache(testcase, solver_gen): with testcase.assertLogs('nutils', 'DEBUG') as cm: v2, info = _edit(solver_gen().solve_withinfo(1e-5)) testcase.assertEqual(v1, v2) - testcase.assertRegex('\n'.join(cm.output), '\[cache\.function [0-9a-f]{40}\] load') + testcase.assertRegex('\n'.join(cm.output), '\\[cache\\.function [0-9a-f]{40}\\] load') with testcase.assertLogs('nutils', 'DEBUG') as cm: solver_gen().solve(1e-6) - testcase.assertRegex('\n'.join(cm.output), '\[cache\.function [0-9a-f]{40}\] failed to load') + testcase.assertRegex('\n'.join(cm.output), '\\[cache\\.function [0-9a-f]{40}\\] failed to load') class laplace(TestCase):