From 5cf6d5fc44258f26031faf61f7587812a4c0bb9d Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 24 Apr 2024 23:59:03 -0400 Subject: [PATCH] test: Update the test to work with python 3.8 and 3.11 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. --- codejail/tests/test_jail_code.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/codejail/tests/test_jail_code.py b/codejail/tests/test_jail_code.py index 104d57a1..f11fde9e 100644 --- a/codejail/tests/test_jail_code.py +++ b/codejail/tests/test_jail_code.py @@ -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 - raise Exception('FAIL') + + regex = textwrap.dedent(""" + (?m)Traceback [(]most recent call last[)]: + File "(/.*?/)?jailed_code", line 1, in + 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(