Skip to content

Commit

Permalink
Skip tests with undecodable filename if not supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Apr 15, 2024
1 parent 66646e9 commit 45cab7f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Lib/test/test_capi/test_pyrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class PyRunTest(unittest.TestCase):
# cf_flags -- compile flags bitmap
# cf_feature_version -- compile flags feature version
def test_pyrun_fileexflags(self):
def run(*args, filename=TESTFN):
return _testcapi.run_fileexflags(filename, Py_file_input, *args)
def run(*args):
return _testcapi.run_fileexflags(TESTFN, Py_file_input, *args)

with open(TESTFN, 'w') as fp:
fp.write("a\n")
Expand All @@ -34,12 +34,6 @@ def run(*args, filename=TESTFN):
self.assertIsNone(run({}, UserDict(a=1)))
self.assertIsNone(run(dict(a=1), {}, 1)) # closeit = True

if TESTFN_UNDECODABLE is not None:
with open(TESTFN_UNDECODABLE, 'w') as fp:
fp.write("b\n")
self.addCleanup(unlink, TESTFN_UNDECODABLE)
self.assertIsNone(run(dict(b=1), filename=TESTFN_UNDECODABLE))

self.assertRaises(NameError, run, {})
self.assertRaises(NameError, run, {}, {})
self.assertRaises(TypeError, run, dict(a=1), [])
Expand All @@ -52,6 +46,17 @@ def run(*args, filename=TESTFN):
self.assertRaises(SystemError, run, UserDict(), {})
self.assertRaises(SystemError, run, UserDict(), dict(a=1))

@unittest.skipUnless(TESTFN_UNDECODABLE, "only works if there are undecodable paths")
def test_pyrun_fileexflags_with_undecodable_filename(self):
run = _testcapi.run_fileexflags
try:
with open(TESTFN_UNDECODABLE, 'w') as fp:
fp.write("b\n")
self.addCleanup(unlink, TESTFN_UNDECODABLE)
except OSError:
self.skipTest("undecodable paths are not supported")
self.assertIsNone(run(TESTFN_UNDECODABLE, Py_file_input, dict(b=1)))


if __name__ == "__main__":
unittest.main()

0 comments on commit 45cab7f

Please sign in to comment.