MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_seek0

Method test_seek0

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

Source from the content-addressed store, hash-verified

2919
2920class BomTest(unittest.TestCase):
2921 def test_seek0(self):
2922 data = "1234567890"
2923 tests = ("utf-16",
2924 "utf-16-le",
2925 "utf-16-be",
2926 "utf-32",
2927 "utf-32-le",
2928 "utf-32-be")
2929 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
2930 for encoding in tests:
2931 # Check if the BOM is written only once
2932 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2933 f.write(data)
2934 f.write(data)
2935 f.seek(0)
2936 self.assertEqual(f.read(), data * 2)
2937 f.seek(0)
2938 self.assertEqual(f.read(), data * 2)
2939
2940 # Check that the BOM is written after a seek(0)
2941 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2942 f.write(data[0])
2943 self.assertNotEqual(f.tell(), 0)
2944 f.seek(0)
2945 f.write(data)
2946 f.seek(0)
2947 self.assertEqual(f.read(), data)
2948
2949 # (StreamWriter) Check that the BOM is written after a seek(0)
2950 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2951 f.writer.write(data[0])
2952 self.assertNotEqual(f.writer.tell(), 0)
2953 f.writer.seek(0)
2954 f.writer.write(data)
2955 f.seek(0)
2956 self.assertEqual(f.read(), data)
2957
2958 # Check that the BOM is not written after a seek() at a position
2959 # different than the start
2960 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2961 f.write(data)
2962 f.seek(f.tell())
2963 f.write(data)
2964 f.seek(0)
2965 self.assertEqual(f.read(), data * 2)
2966
2967 # (StreamWriter) Check that the BOM is not written after a seek()
2968 # at a position different than the start
2969 with codecs_open_no_warn(os_helper.TESTFN, 'w+', encoding=encoding) as f:
2970 f.writer.write(data)
2971 f.writer.seek(f.writer.tell())
2972 f.writer.write(data)
2973 f.seek(0)
2974 self.assertEqual(f.read(), data * 2)
2975
2976
2977bytes_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