summaryrefslogtreecommitdiff
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2018-09-12 22:14:35 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2018-09-12 22:14:35 +0300
commit0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd (patch)
tree0adf66fd5134076264070c7cd2777eb310d38ae3 /Lib/test/test_os.py
parente5024517811ee990b770fca0ba7058742d00e032 (diff)
downloadcpython-git-0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd.tar.gz
bpo-31577: Fix a crash in os.utime() in case of a bad ns argument. (GH-3752)
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 6658a61ea2..0a8ba5cf95 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -635,6 +635,22 @@ class UtimeTests(unittest.TestCase):
with self.assertRaises(ValueError):
os.utime(self.fname, (5, 5), ns=(5, 5))
+ @support.cpython_only
+ def test_issue31577(self):
+ # The interpreter shouldn't crash in case utime() received a bad
+ # ns argument.
+ def get_bad_int(divmod_ret_val):
+ class BadInt:
+ def __divmod__(*args):
+ return divmod_ret_val
+ return BadInt()
+ with self.assertRaises(TypeError):
+ os.utime(self.fname, ns=(get_bad_int(42), 1))
+ with self.assertRaises(TypeError):
+ os.utime(self.fname, ns=(get_bad_int(()), 1))
+ with self.assertRaises(TypeError):
+ os.utime(self.fname, ns=(get_bad_int((1, 2, 3)), 1))
+
from test import mapping_tests