Skip to content

Commit

Permalink
test: Update the test to work with python 3.8 and 3.11
Browse files Browse the repository at this point in the history
The traceback has more details in the newer version of python including
the full filepath for the jailed_code file which includes the generated
temp path.  That path is random each time so we use a regex to deal with
it instead of hardcoding the test message.
  • Loading branch information
feanil committed Apr 25, 2024
1 parent 17fdabd commit 5cf6d5f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions codejail/tests/test_jail_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ def test_ends_with_exception(self):
res = jailpy(code="""raise Exception('FAIL')""")
self.assertNotEqual(res.status, 0)
self.assertEqual(res.stdout, b"")
self.assertEqual(res.stderr, bytes(textwrap.dedent("""\
Traceback (most recent call last):
File "jailed_code", line 1, in <module>
raise Exception('FAIL')

regex = textwrap.dedent("""
(?m)Traceback [(]most recent call last[)]:
File "(/.*?/)?jailed_code", line 1, in <module>
raise Exception[(]'FAIL'[)]
Exception: FAIL
"""), 'utf-8'))
""").strip() + "\n"
self.assertRegex(res.stderr.decode('utf-8'), regex)

def test_stdin_is_provided(self):
res = jailpy(
Expand Down

0 comments on commit 5cf6d5f

Please sign in to comment.