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

Method test_seek0

Lib/test/test_codecs.py:2910–2963  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2908
2909class BomTest(unittest.TestCase):
2910 def test_seek0(self):
2911 data = "1234567890"
2912 tests = ("utf-16",
2913 "utf-16-le",
2914 "utf-16-be",
2915 "utf-32",
2916 "utf-32-le",
2917 "utf-32-be")
2918 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
2919 for encoding in tests:
2920 # Check if the BOM is written only once
2921 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2922 f.write(data)
2923 f.write(data)
2924 f.seek(0)
2925 self.assertEqual(f.read(), data * 2)
2926 f.seek(0)
2927 self.assertEqual(f.read(), data * 2)
2928
2929 # Check that the BOM is written after a seek(0)
2930 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2931 f.write(data[0])
2932 self.assertNotEqual(f.tell(), 0)
2933 f.seek(0)
2934 f.write(data)
2935 f.seek(0)
2936 self.assertEqual(f.read(), data)
2937
2938 # (StreamWriter) Check that the BOM is written after a seek(0)
2939 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2940 f.writer.write(data[0])
2941 self.assertNotEqual(f.writer.tell(), 0)
2942 f.writer.seek(0)
2943 f.writer.write(data)
2944 f.seek(0)
2945 self.assertEqual(f.read(), data)
2946
2947 # Check that the BOM is not written after a seek() at a position
2948 # different than the start
2949 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2950 f.write(data)
2951 f.seek(f.tell())
2952 f.write(data)
2953 f.seek(0)
2954 self.assertEqual(f.read(), data * 2)
2955
2956 # (StreamWriter) Check that the BOM is not written after a seek()
2957 # at a position different than the start
2958 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2959 f.writer.write(data)
2960 f.writer.seek(f.writer.tell())
2961 f.writer.write(data)
2962 f.seek(0)
2963 self.assertEqual(f.read(), data * 2)
2964
2965
2966bytes_transform_encodings = [

Callers

nothing calls this directly

Calls 8

codecs_open_no_warnFunction · 0.85
addCleanupMethod · 0.80
assertNotEqualMethod · 0.80
writeMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45
tellMethod · 0.45

Tested by

no test coverage detected