MCPcopy
hub / github.com/django/django / test_file_move_ensure_truncation

Method test_file_move_ensure_truncation

tests/files/tests.py:502–521  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

500 os.close(handle_c)
501
502 def test_file_move_ensure_truncation(self):
503 with tempfile.NamedTemporaryFile(delete=False) as src:
504 src.write(b"content")
505 src_name = src.name
506 self.addCleanup(
507 lambda: os.remove(src_name) if os.path.exists(src_name) else None
508 )
509
510 with tempfile.NamedTemporaryFile(delete=False) as dest:
511 dest.write(b"This is a longer content.")
512 dest_name = dest.name
513 self.addCleanup(os.remove, dest_name)
514
515 with mock.patch("django.core.files.move.os.rename", side_effect=OSError()):
516 file_move_safe(src_name, dest_name, allow_overwrite=True)
517
518 with open(dest_name, "rb") as f:
519 content = f.read()
520
521 self.assertEqual(content, b"content")
522
523
524class SpooledTempTests(unittest.TestCase):

Callers

nothing calls this directly

Calls 6

file_move_safeFunction · 0.90
writeMethod · 0.45
removeMethod · 0.45
existsMethod · 0.45
patchMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected