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

Method testMethods

Lib/test/test_file.py:98–130  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

96 self.assertTrue(f.closed)
97
98 def testMethods(self):
99 methods = [('fileno', ()),
100 ('flush', ()),
101 ('isatty', ()),
102 ('__next__', ()),
103 ('read', ()),
104 ('write', (b"",)),
105 ('readline', ()),
106 ('readlines', ()),
107 ('seek', (0,)),
108 ('tell', ()),
109 ('write', (b"",)),
110 ('writelines', ([],)),
111 ('__iter__', ()),
112 ]
113 methods.append(('truncate', ()))
114
115 # __exit__ should close the file
116 self.f.__exit__(None, None, None)
117 self.assertTrue(self.f.closed)
118
119 for methodname, args in methods:
120 method = getattr(self.f, methodname)
121 # should raise on closed file
122 self.assertRaises(ValueError, method, *args)
123
124 # file is closed, __exit__ shouldn't do anything
125 self.assertEqual(self.f.__exit__(None, None, None), None)
126 # it must also return None if an exception was given
127 try:
128 1/0
129 except:
130 self.assertEqual(self.f.__exit__(*sys.exc_info()), None)
131
132 def testReadWhenWriting(self):
133 self.assertRaises(OSError, self.f.read)

Callers

nothing calls this directly

Calls 6

getattrFunction · 0.85
assertTrueMethod · 0.80
appendMethod · 0.45
__exit__Method · 0.45
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected