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

Method test_text_mode

Lib/test/test_tempfile.py:1417–1447  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1415 f.errors
1416
1417 def test_text_mode(self):
1418 # Creating a SpooledTemporaryFile with a text mode should produce
1419 # a file object reading and writing (Unicode) text strings.
1420 f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
1421 encoding="utf-8")
1422 f.write("abc\n")
1423 f.seek(0)
1424 self.assertEqual(f.read(), "abc\n")
1425 f.write("def\n")
1426 f.seek(0)
1427 self.assertEqual(f.read(), "abc\ndef\n")
1428 self.assertFalse(f._rolled)
1429 self.assertEqual(f.mode, 'w+')
1430 self.assertIsNone(f.name)
1431 self.assertEqual(f.newlines, os.linesep)
1432 self.assertEqual(f.encoding, "utf-8")
1433 self.assertEqual(f.errors, "strict")
1434
1435 f.write("xyzzy\n")
1436 f.seek(0)
1437 self.assertEqual(f.read(), "abc\ndef\nxyzzy\n")
1438 # Check that Ctrl+Z doesn't truncate the file
1439 f.write("foo\x1abar\n")
1440 f.seek(0)
1441 self.assertEqual(f.read(), "abc\ndef\nxyzzy\nfoo\x1abar\n")
1442 self.assertTrue(f._rolled)
1443 self.assertEqual(f.mode, 'w+')
1444 self.assertIsNotNone(f.name)
1445 self.assertEqual(f.newlines, os.linesep)
1446 self.assertEqual(f.encoding, "utf-8")
1447 self.assertEqual(f.errors, "strict")
1448
1449 def test_text_newline_and_encoding(self):
1450 f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,

Callers

nothing calls this directly

Calls 8

writeMethod · 0.95
seekMethod · 0.95
readMethod · 0.95
assertFalseMethod · 0.80
assertIsNoneMethod · 0.80
assertTrueMethod · 0.80
assertIsNotNoneMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected