MCPcopy Index your code
hub / github.com/python/cpython / test_save_raises_if_file_found

Method test_save_raises_if_file_found

Lib/test/test_turtle.py:518–531  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

516 turtle.TurtleScreen.save(screen, os.path.join(parent, "a.ps"))
517
518 def test_save_raises_if_file_found(self) -> None:
519 screen = unittest.mock.Mock()
520
521 with tempfile.TemporaryDirectory() as tmpdir:
522 file_path = os.path.join(tmpdir, "some_file.ps")
523 with open(file_path, "w") as f:
524 f.write("some text")
525
526 msg = (
527 f"The file '{file_path}' already exists. To overwrite it use"
528 " the 'overwrite=True' argument of the save function."
529 )
530 with self.assertRaisesRegex(FileExistsError, re.escape(msg)):
531 turtle.TurtleScreen.save(screen, file_path)
532
533 def test_save_overwrites_if_specified(self) -> None:
534 screen = unittest.mock.Mock()

Callers

nothing calls this directly

Calls 6

assertRaisesRegexMethod · 0.80
escapeMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
writeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected