Skip to content

Commit

Permalink
fix invalid escape sequences in strings
Browse files Browse the repository at this point in the history
  • Loading branch information
joostvanzwieten committed Dec 19, 2023
1 parent 44e0a6f commit bf85057
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/cahnhilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit bf85057

Please sign in to comment.