blob: 3857401ca60fa609ad0ab8186567510c7a31404b [file] [log] [blame]
Tim Peters3230d5c2001-07-11 22:21:17 +00001'''
2Tests for fileinput module.
3Nick Mathewson
4'''
Benjamin Petersoneb462882011-03-15 09:50:18 -05005import os
6import sys
7import re
briancurtin906f0c42011-03-15 10:29:41 -04008import fileinput
9import collections
Florent Xiclunaa011e2b2011-11-07 19:43:07 +010010import builtins
Serhiy Storchaka5f48e262018-06-05 12:08:36 +030011import tempfile
Benjamin Petersoneb462882011-03-15 09:50:18 -050012import unittest
13
briancurtinf84f3c32011-03-18 13:03:17 -050014try:
15 import bz2
16except ImportError:
17 bz2 = None
Ezio Melottic3afbb92011-05-14 10:10:53 +030018try:
19 import gzip
20except ImportError:
21 gzip = None
briancurtinf84f3c32011-03-18 13:03:17 -050022
Serhiy Storchaka946cfc32014-05-14 21:08:33 +030023from io import BytesIO, StringIO
Benjamin Petersoneb462882011-03-15 09:50:18 -050024from fileinput import FileInput, hook_encoded
Roy Williams002665a2017-05-22 22:24:17 -070025from pathlib import Path
Benjamin Petersoneb462882011-03-15 09:50:18 -050026
Serhiy Storchaka597d15a2016-04-24 13:45:58 +030027from test.support import verbose, TESTFN, check_warnings
Benjamin Petersoneb462882011-03-15 09:50:18 -050028from test.support import unlink as safe_unlink
Martin Panter7978e102016-01-16 06:26:54 +000029from test import support
Serhiy Storchaka946cfc32014-05-14 21:08:33 +030030from unittest import mock
Benjamin Petersoneb462882011-03-15 09:50:18 -050031
Tim Peters3230d5c2001-07-11 22:21:17 +000032
33# The fileinput module has 2 interfaces: the FileInput class which does
34# all the work, and a few functions (input, etc.) that use a global _state
briancurtin906f0c42011-03-15 10:29:41 -040035# variable.
Tim Peters3230d5c2001-07-11 22:21:17 +000036
Serhiy Storchaka5f48e262018-06-05 12:08:36 +030037class BaseTests:
38 # Write a content (str or bytes) to temp file, and return the
39 # temp file's name.
40 def writeTmp(self, content, *, mode='w'): # opening in text mode is the default
41 fd, name = tempfile.mkstemp()
42 self.addCleanup(support.unlink, name)
43 with open(fd, mode) as f:
44 f.write(content)
45 return name
Tim Peters3230d5c2001-07-11 22:21:17 +000046
Serhiy Storchakacc2dbc52016-03-08 18:28:36 +020047class LineReader:
48
49 def __init__(self):
50 self._linesread = []
51
52 @property
53 def linesread(self):
54 try:
55 return self._linesread[:]
56 finally:
57 self._linesread = []
58
59 def openhook(self, filename, mode):
60 self.it = iter(filename.splitlines(True))
61 return self
62
63 def readline(self, size=None):
64 line = next(self.it, '')
65 self._linesread.append(line)
66 return line
67
68 def readlines(self, hint=-1):
69 lines = []
70 size = 0
71 while True:
72 line = self.readline()
73 if not line:
74 return lines
75 lines.append(line)
76 size += len(line)
77 if size >= hint:
78 return lines
79
80 def close(self):
81 pass
82
Serhiy Storchaka5f48e262018-06-05 12:08:36 +030083class BufferSizesTests(BaseTests, unittest.TestCase):
Guido van Rossumd8faa362007-04-27 19:54:29 +000084 def test_buffer_sizes(self):
85 # First, run the tests with default and teeny buffer size.
86 for round, bs in (0, 0), (1, 30):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +030087 t1 = self.writeTmp(''.join("Line %s of file 1\n" % (i+1) for i in range(15)))
88 t2 = self.writeTmp(''.join("Line %s of file 2\n" % (i+1) for i in range(10)))
89 t3 = self.writeTmp(''.join("Line %s of file 3\n" % (i+1) for i in range(5)))
90 t4 = self.writeTmp(''.join("Line %s of file 4\n" % (i+1) for i in range(1)))
91 if bs:
92 with self.assertWarns(DeprecationWarning):
Serhiy Storchaka674e2d02016-03-08 18:35:19 +020093 self.buffer_size_test(t1, t2, t3, t4, bs, round)
Serhiy Storchaka5f48e262018-06-05 12:08:36 +030094 else:
95 self.buffer_size_test(t1, t2, t3, t4, bs, round)
Tim Peters3230d5c2001-07-11 22:21:17 +000096
Guido van Rossumd8faa362007-04-27 19:54:29 +000097 def buffer_size_test(self, t1, t2, t3, t4, bs=0, round=0):
98 pat = re.compile(r'LINE (\d+) OF FILE (\d+)')
Tim Peters3230d5c2001-07-11 22:21:17 +000099
Guido van Rossumd8faa362007-04-27 19:54:29 +0000100 start = 1 + round*6
101 if verbose:
102 print('%s. Simple iteration (bs=%s)' % (start+0, bs))
103 fi = FileInput(files=(t1, t2, t3, t4), bufsize=bs)
Tim Peters3230d5c2001-07-11 22:21:17 +0000104 lines = list(fi)
Tim Peters3230d5c2001-07-11 22:21:17 +0000105 fi.close()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000106 self.assertEqual(len(lines), 31)
107 self.assertEqual(lines[4], 'Line 5 of file 1\n')
108 self.assertEqual(lines[30], 'Line 1 of file 4\n')
109 self.assertEqual(fi.lineno(), 31)
110 self.assertEqual(fi.filename(), t4)
Tim Peters3230d5c2001-07-11 22:21:17 +0000111
Guido van Rossumd8faa362007-04-27 19:54:29 +0000112 if verbose:
113 print('%s. Status variables (bs=%s)' % (start+1, bs))
114 fi = FileInput(files=(t1, t2, t3, t4), bufsize=bs)
115 s = "x"
116 while s and s != 'Line 6 of file 2\n':
117 s = fi.readline()
118 self.assertEqual(fi.filename(), t2)
119 self.assertEqual(fi.lineno(), 21)
120 self.assertEqual(fi.filelineno(), 6)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000121 self.assertFalse(fi.isfirstline())
122 self.assertFalse(fi.isstdin())
Tim Peters3230d5c2001-07-11 22:21:17 +0000123
Guido van Rossumd8faa362007-04-27 19:54:29 +0000124 if verbose:
125 print('%s. Nextfile (bs=%s)' % (start+2, bs))
126 fi.nextfile()
127 self.assertEqual(fi.readline(), 'Line 1 of file 3\n')
128 self.assertEqual(fi.lineno(), 22)
129 fi.close()
Tim Peters3230d5c2001-07-11 22:21:17 +0000130
Guido van Rossumd8faa362007-04-27 19:54:29 +0000131 if verbose:
132 print('%s. Stdin (bs=%s)' % (start+3, bs))
133 fi = FileInput(files=(t1, t2, t3, t4, '-'), bufsize=bs)
134 savestdin = sys.stdin
135 try:
136 sys.stdin = StringIO("Line 1 of stdin\nLine 2 of stdin\n")
137 lines = list(fi)
138 self.assertEqual(len(lines), 33)
139 self.assertEqual(lines[32], 'Line 2 of stdin\n')
140 self.assertEqual(fi.filename(), '<stdin>')
141 fi.nextfile()
142 finally:
143 sys.stdin = savestdin
Tim Peters3230d5c2001-07-11 22:21:17 +0000144
Guido van Rossumd8faa362007-04-27 19:54:29 +0000145 if verbose:
146 print('%s. Boundary conditions (bs=%s)' % (start+4, bs))
147 fi = FileInput(files=(t1, t2, t3, t4), bufsize=bs)
148 self.assertEqual(fi.lineno(), 0)
149 self.assertEqual(fi.filename(), None)
150 fi.nextfile()
151 self.assertEqual(fi.lineno(), 0)
152 self.assertEqual(fi.filename(), None)
Tim Peters3230d5c2001-07-11 22:21:17 +0000153
Guido van Rossumd8faa362007-04-27 19:54:29 +0000154 if verbose:
155 print('%s. Inplace (bs=%s)' % (start+5, bs))
156 savestdout = sys.stdout
157 try:
158 fi = FileInput(files=(t1, t2, t3, t4), inplace=1, bufsize=bs)
159 for line in fi:
160 line = line[:-1].upper()
161 print(line)
162 fi.close()
163 finally:
164 sys.stdout = savestdout
Tim Peters3230d5c2001-07-11 22:21:17 +0000165
Guido van Rossumd8faa362007-04-27 19:54:29 +0000166 fi = FileInput(files=(t1, t2, t3, t4), bufsize=bs)
167 for line in fi:
168 self.assertEqual(line[-1], '\n')
169 m = pat.match(line[:-1])
170 self.assertNotEqual(m, None)
171 self.assertEqual(int(m.group(1)), fi.filelineno())
172 fi.close()
Georg Brandle4662172006-02-19 09:51:27 +0000173
briancurtin906f0c42011-03-15 10:29:41 -0400174class UnconditionallyRaise:
175 def __init__(self, exception_type):
176 self.exception_type = exception_type
177 self.invoked = False
178 def __call__(self, *args, **kwargs):
179 self.invoked = True
180 raise self.exception_type()
181
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300182class FileInputTests(BaseTests, unittest.TestCase):
briancurtin906f0c42011-03-15 10:29:41 -0400183
Guido van Rossumd8faa362007-04-27 19:54:29 +0000184 def test_zero_byte_files(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300185 t1 = self.writeTmp("")
186 t2 = self.writeTmp("")
187 t3 = self.writeTmp("The only line there is.\n")
188 t4 = self.writeTmp("")
189 fi = FileInput(files=(t1, t2, t3, t4))
Georg Brandl67e9fb92006-02-19 13:56:17 +0000190
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300191 line = fi.readline()
192 self.assertEqual(line, 'The only line there is.\n')
193 self.assertEqual(fi.lineno(), 1)
194 self.assertEqual(fi.filelineno(), 1)
195 self.assertEqual(fi.filename(), t3)
Georg Brandlc029f872006-02-19 14:12:34 +0000196
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300197 line = fi.readline()
198 self.assertFalse(line)
199 self.assertEqual(fi.lineno(), 1)
200 self.assertEqual(fi.filelineno(), 0)
201 self.assertEqual(fi.filename(), t4)
202 fi.close()
Georg Brandlc98eeed2006-02-19 14:57:47 +0000203
Guido van Rossumd8faa362007-04-27 19:54:29 +0000204 def test_files_that_dont_end_with_newline(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300205 t1 = self.writeTmp("A\nB\nC")
206 t2 = self.writeTmp("D\nE\nF")
207 fi = FileInput(files=(t1, t2))
208 lines = list(fi)
209 self.assertEqual(lines, ["A\n", "B\n", "C", "D\n", "E\n", "F"])
210 self.assertEqual(fi.filelineno(), 3)
211 self.assertEqual(fi.lineno(), 6)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000212
Guido van Rossumc43e79f2007-06-18 18:26:36 +0000213## def test_unicode_filenames(self):
214## # XXX A unicode string is always returned by writeTmp.
215## # So is this needed?
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300216## t1 = self.writeTmp("A\nB")
217## encoding = sys.getfilesystemencoding()
218## if encoding is None:
219## encoding = 'ascii'
220## fi = FileInput(files=str(t1, encoding))
221## lines = list(fi)
222## self.assertEqual(lines, ["A\n", "B"])
Guido van Rossumd8faa362007-04-27 19:54:29 +0000223
224 def test_fileno(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300225 t1 = self.writeTmp("A\nB")
226 t2 = self.writeTmp("C\nD")
227 fi = FileInput(files=(t1, t2))
228 self.assertEqual(fi.fileno(), -1)
229 line = next(fi)
230 self.assertNotEqual(fi.fileno(), -1)
231 fi.nextfile()
232 self.assertEqual(fi.fileno(), -1)
233 line = list(fi)
234 self.assertEqual(fi.fileno(), -1)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000235
236 def test_opening_mode(self):
237 try:
238 # invalid mode, should raise ValueError
239 fi = FileInput(mode="w")
240 self.fail("FileInput should reject invalid mode argument")
241 except ValueError:
242 pass
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300243 # try opening in universal newline mode
244 t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb")
245 with check_warnings(('', DeprecationWarning)):
246 fi = FileInput(files=t1, mode="U")
247 with check_warnings(('', DeprecationWarning)):
248 lines = list(fi)
249 self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"])
Guido van Rossumd8faa362007-04-27 19:54:29 +0000250
Serhiy Storchaka946cfc32014-05-14 21:08:33 +0300251 def test_stdin_binary_mode(self):
252 with mock.patch('sys.stdin') as m_stdin:
253 m_stdin.buffer = BytesIO(b'spam, bacon, sausage, and spam')
254 fi = FileInput(files=['-'], mode='rb')
255 lines = list(fi)
256 self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])
257
R David Murray830207e2016-01-02 15:41:41 -0500258 def test_detached_stdin_binary_mode(self):
259 orig_stdin = sys.stdin
260 try:
261 sys.stdin = BytesIO(b'spam, bacon, sausage, and spam')
262 self.assertFalse(hasattr(sys.stdin, 'buffer'))
263 fi = FileInput(files=['-'], mode='rb')
264 lines = list(fi)
265 self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])
266 finally:
267 sys.stdin = orig_stdin
268
Guido van Rossume22905a2007-08-27 23:09:25 +0000269 def test_file_opening_hook(self):
270 try:
271 # cannot use openhook and inplace mode
272 fi = FileInput(inplace=1, openhook=lambda f, m: None)
273 self.fail("FileInput should raise if both inplace "
274 "and openhook arguments are given")
275 except ValueError:
276 pass
277 try:
278 fi = FileInput(openhook=1)
279 self.fail("FileInput should check openhook for being callable")
280 except ValueError:
281 pass
briancurtin906f0c42011-03-15 10:29:41 -0400282
283 class CustomOpenHook:
284 def __init__(self):
285 self.invoked = False
286 def __call__(self, *args):
287 self.invoked = True
288 return open(*args)
289
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300290 t = self.writeTmp("\n")
briancurtin906f0c42011-03-15 10:29:41 -0400291 custom_open_hook = CustomOpenHook()
292 with FileInput([t], openhook=custom_open_hook) as fi:
293 fi.readline()
294 self.assertTrue(custom_open_hook.invoked, "openhook not invoked")
Guido van Rossumd8faa362007-04-27 19:54:29 +0000295
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200296 def test_readline(self):
297 with open(TESTFN, 'wb') as f:
298 f.write(b'A\nB\r\nC\r')
299 # Fill TextIOWrapper buffer.
300 f.write(b'123456789\n' * 1000)
301 # Issue #20501: readline() shouldn't read whole file.
302 f.write(b'\x80')
303 self.addCleanup(safe_unlink, TESTFN)
304
305 with FileInput(files=TESTFN,
Serhiy Storchakacc2dbc52016-03-08 18:28:36 +0200306 openhook=hook_encoded('ascii')) as fi:
Serhiy Storchaka682ea5f2014-03-03 21:17:17 +0200307 try:
308 self.assertEqual(fi.readline(), 'A\n')
309 self.assertEqual(fi.readline(), 'B\n')
310 self.assertEqual(fi.readline(), 'C\n')
311 except UnicodeDecodeError:
312 self.fail('Read to end of file')
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200313 with self.assertRaises(UnicodeDecodeError):
314 # Read to the end of file.
315 list(fi)
Serhiy Storchaka314464d2015-11-01 16:43:58 +0200316 self.assertEqual(fi.readline(), '')
317 self.assertEqual(fi.readline(), '')
318
319 def test_readline_binary_mode(self):
320 with open(TESTFN, 'wb') as f:
321 f.write(b'A\nB\r\nC\rD')
322 self.addCleanup(safe_unlink, TESTFN)
323
324 with FileInput(files=TESTFN, mode='rb') as fi:
325 self.assertEqual(fi.readline(), b'A\n')
326 self.assertEqual(fi.readline(), b'B\r\n')
327 self.assertEqual(fi.readline(), b'C\rD')
328 # Read to the end of file.
329 self.assertEqual(fi.readline(), b'')
330 self.assertEqual(fi.readline(), b'')
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200331
Georg Brandl6cb7b652010-07-31 20:08:15 +0000332 def test_context_manager(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300333 t1 = self.writeTmp("A\nB\nC")
334 t2 = self.writeTmp("D\nE\nF")
335 with FileInput(files=(t1, t2)) as fi:
336 lines = list(fi)
337 self.assertEqual(lines, ["A\n", "B\n", "C", "D\n", "E\n", "F"])
338 self.assertEqual(fi.filelineno(), 3)
339 self.assertEqual(fi.lineno(), 6)
340 self.assertEqual(fi._files, ())
Georg Brandl6cb7b652010-07-31 20:08:15 +0000341
342 def test_close_on_exception(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300343 t1 = self.writeTmp("")
Georg Brandl6cb7b652010-07-31 20:08:15 +0000344 try:
Georg Brandl6cb7b652010-07-31 20:08:15 +0000345 with FileInput(files=t1) as fi:
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200346 raise OSError
347 except OSError:
Georg Brandl6cb7b652010-07-31 20:08:15 +0000348 self.assertEqual(fi._files, ())
Georg Brandl6cb7b652010-07-31 20:08:15 +0000349
briancurtin906f0c42011-03-15 10:29:41 -0400350 def test_empty_files_list_specified_to_constructor(self):
351 with FileInput(files=[]) as fi:
Brett Cannond47af532011-03-15 15:55:12 -0400352 self.assertEqual(fi._files, ('-',))
briancurtin906f0c42011-03-15 10:29:41 -0400353
Berker Peksag84a13fb2018-08-11 09:05:04 +0300354 @support.ignore_warnings(category=DeprecationWarning)
briancurtin906f0c42011-03-15 10:29:41 -0400355 def test__getitem__(self):
356 """Tests invoking FileInput.__getitem__() with the current
357 line number"""
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300358 t = self.writeTmp("line1\nline2\n")
briancurtin906f0c42011-03-15 10:29:41 -0400359 with FileInput(files=[t]) as fi:
360 retval1 = fi[0]
361 self.assertEqual(retval1, "line1\n")
362 retval2 = fi[1]
363 self.assertEqual(retval2, "line2\n")
364
Berker Peksag84a13fb2018-08-11 09:05:04 +0300365 def test__getitem___deprecation(self):
366 t = self.writeTmp("line1\nline2\n")
367 with self.assertWarnsRegex(DeprecationWarning,
368 r'Use iterator protocol instead'):
369 with FileInput(files=[t]) as fi:
370 self.assertEqual(fi[0], "line1\n")
371
372 @support.ignore_warnings(category=DeprecationWarning)
briancurtin906f0c42011-03-15 10:29:41 -0400373 def test__getitem__invalid_key(self):
374 """Tests invoking FileInput.__getitem__() with an index unequal to
375 the line number"""
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300376 t = self.writeTmp("line1\nline2\n")
briancurtin906f0c42011-03-15 10:29:41 -0400377 with FileInput(files=[t]) as fi:
378 with self.assertRaises(RuntimeError) as cm:
379 fi[1]
Brett Cannond47af532011-03-15 15:55:12 -0400380 self.assertEqual(cm.exception.args, ("accessing lines out of order",))
briancurtin906f0c42011-03-15 10:29:41 -0400381
Berker Peksag84a13fb2018-08-11 09:05:04 +0300382 @support.ignore_warnings(category=DeprecationWarning)
briancurtin906f0c42011-03-15 10:29:41 -0400383 def test__getitem__eof(self):
384 """Tests invoking FileInput.__getitem__() with the line number but at
385 end-of-input"""
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300386 t = self.writeTmp('')
briancurtin906f0c42011-03-15 10:29:41 -0400387 with FileInput(files=[t]) as fi:
388 with self.assertRaises(IndexError) as cm:
389 fi[0]
Brett Cannond47af532011-03-15 15:55:12 -0400390 self.assertEqual(cm.exception.args, ("end of input reached",))
briancurtin906f0c42011-03-15 10:29:41 -0400391
392 def test_nextfile_oserror_deleting_backup(self):
393 """Tests invoking FileInput.nextfile() when the attempt to delete
394 the backup file would raise OSError. This error is expected to be
395 silently ignored"""
396
397 os_unlink_orig = os.unlink
398 os_unlink_replacement = UnconditionallyRaise(OSError)
399 try:
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300400 t = self.writeTmp("\n")
401 self.addCleanup(support.unlink, t + '.bak')
briancurtin906f0c42011-03-15 10:29:41 -0400402 with FileInput(files=[t], inplace=True) as fi:
403 next(fi) # make sure the file is opened
404 os.unlink = os_unlink_replacement
405 fi.nextfile()
406 finally:
407 os.unlink = os_unlink_orig
408
409 # sanity check to make sure that our test scenario was actually hit
410 self.assertTrue(os_unlink_replacement.invoked,
411 "os.unlink() was not invoked")
412
413 def test_readline_os_fstat_raises_OSError(self):
414 """Tests invoking FileInput.readline() when os.fstat() raises OSError.
415 This exception should be silently discarded."""
416
417 os_fstat_orig = os.fstat
418 os_fstat_replacement = UnconditionallyRaise(OSError)
419 try:
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300420 t = self.writeTmp("\n")
briancurtin906f0c42011-03-15 10:29:41 -0400421 with FileInput(files=[t], inplace=True) as fi:
422 os.fstat = os_fstat_replacement
423 fi.readline()
424 finally:
425 os.fstat = os_fstat_orig
426
427 # sanity check to make sure that our test scenario was actually hit
428 self.assertTrue(os_fstat_replacement.invoked,
429 "os.fstat() was not invoked")
430
briancurtin906f0c42011-03-15 10:29:41 -0400431 def test_readline_os_chmod_raises_OSError(self):
432 """Tests invoking FileInput.readline() when os.chmod() raises OSError.
433 This exception should be silently discarded."""
434
435 os_chmod_orig = os.chmod
436 os_chmod_replacement = UnconditionallyRaise(OSError)
437 try:
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300438 t = self.writeTmp("\n")
briancurtin906f0c42011-03-15 10:29:41 -0400439 with FileInput(files=[t], inplace=True) as fi:
440 os.chmod = os_chmod_replacement
441 fi.readline()
442 finally:
443 os.chmod = os_chmod_orig
444
445 # sanity check to make sure that our test scenario was actually hit
446 self.assertTrue(os_chmod_replacement.invoked,
447 "os.fstat() was not invoked")
448
449 def test_fileno_when_ValueError_raised(self):
450 class FilenoRaisesValueError(UnconditionallyRaise):
451 def __init__(self):
452 UnconditionallyRaise.__init__(self, ValueError)
453 def fileno(self):
454 self.__call__()
455
456 unconditionally_raise_ValueError = FilenoRaisesValueError()
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300457 t = self.writeTmp("\n")
briancurtin906f0c42011-03-15 10:29:41 -0400458 with FileInput(files=[t]) as fi:
459 file_backup = fi._file
460 try:
461 fi._file = unconditionally_raise_ValueError
462 result = fi.fileno()
463 finally:
464 fi._file = file_backup # make sure the file gets cleaned up
465
466 # sanity check to make sure that our test scenario was actually hit
467 self.assertTrue(unconditionally_raise_ValueError.invoked,
468 "_file.fileno() was not invoked")
469
470 self.assertEqual(result, -1, "fileno() should return -1")
471
Serhiy Storchakacc2dbc52016-03-08 18:28:36 +0200472 def test_readline_buffering(self):
473 src = LineReader()
474 with FileInput(files=['line1\nline2', 'line3\n'],
475 openhook=src.openhook) as fi:
476 self.assertEqual(src.linesread, [])
477 self.assertEqual(fi.readline(), 'line1\n')
478 self.assertEqual(src.linesread, ['line1\n'])
479 self.assertEqual(fi.readline(), 'line2')
480 self.assertEqual(src.linesread, ['line2'])
481 self.assertEqual(fi.readline(), 'line3\n')
482 self.assertEqual(src.linesread, ['', 'line3\n'])
483 self.assertEqual(fi.readline(), '')
484 self.assertEqual(src.linesread, [''])
485 self.assertEqual(fi.readline(), '')
486 self.assertEqual(src.linesread, [])
487
488 def test_iteration_buffering(self):
489 src = LineReader()
490 with FileInput(files=['line1\nline2', 'line3\n'],
491 openhook=src.openhook) as fi:
492 self.assertEqual(src.linesread, [])
493 self.assertEqual(next(fi), 'line1\n')
494 self.assertEqual(src.linesread, ['line1\n'])
495 self.assertEqual(next(fi), 'line2')
496 self.assertEqual(src.linesread, ['line2'])
497 self.assertEqual(next(fi), 'line3\n')
498 self.assertEqual(src.linesread, ['', 'line3\n'])
499 self.assertRaises(StopIteration, next, fi)
500 self.assertEqual(src.linesread, [''])
501 self.assertRaises(StopIteration, next, fi)
502 self.assertEqual(src.linesread, [])
503
Roy Williams002665a2017-05-22 22:24:17 -0700504 def test_pathlib_file(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300505 t1 = Path(self.writeTmp("Pathlib file."))
506 with FileInput(t1) as fi:
507 line = fi.readline()
508 self.assertEqual(line, 'Pathlib file.')
509 self.assertEqual(fi.lineno(), 1)
510 self.assertEqual(fi.filelineno(), 1)
511 self.assertEqual(fi.filename(), os.fspath(t1))
Roy Williams002665a2017-05-22 22:24:17 -0700512
Zhiming Wang06de1ae2017-09-05 01:37:24 +0800513 def test_pathlib_file_inplace(self):
Serhiy Storchaka5f48e262018-06-05 12:08:36 +0300514 t1 = Path(self.writeTmp('Pathlib file.'))
515 with FileInput(t1, inplace=True) as fi:
516 line = fi.readline()
517 self.assertEqual(line, 'Pathlib file.')
518 print('Modified %s' % line)
519 with open(t1) as f:
520 self.assertEqual(f.read(), 'Modified Pathlib file.\n')
Zhiming Wang06de1ae2017-09-05 01:37:24 +0800521
Roy Williams002665a2017-05-22 22:24:17 -0700522
briancurtin906f0c42011-03-15 10:29:41 -0400523class MockFileInput:
524 """A class that mocks out fileinput.FileInput for use during unit tests"""
525
526 def __init__(self, files=None, inplace=False, backup="", bufsize=0,
527 mode="r", openhook=None):
528 self.files = files
529 self.inplace = inplace
530 self.backup = backup
531 self.bufsize = bufsize
532 self.mode = mode
533 self.openhook = openhook
534 self._file = None
535 self.invocation_counts = collections.defaultdict(lambda: 0)
536 self.return_values = {}
537
538 def close(self):
539 self.invocation_counts["close"] += 1
540
541 def nextfile(self):
542 self.invocation_counts["nextfile"] += 1
543 return self.return_values["nextfile"]
544
545 def filename(self):
546 self.invocation_counts["filename"] += 1
547 return self.return_values["filename"]
548
549 def lineno(self):
550 self.invocation_counts["lineno"] += 1
551 return self.return_values["lineno"]
552
553 def filelineno(self):
554 self.invocation_counts["filelineno"] += 1
555 return self.return_values["filelineno"]
556
557 def fileno(self):
558 self.invocation_counts["fileno"] += 1
559 return self.return_values["fileno"]
560
561 def isfirstline(self):
562 self.invocation_counts["isfirstline"] += 1
563 return self.return_values["isfirstline"]
564
565 def isstdin(self):
566 self.invocation_counts["isstdin"] += 1
567 return self.return_values["isstdin"]
568
569class BaseFileInputGlobalMethodsTest(unittest.TestCase):
570 """Base class for unit tests for the global function of
571 the fileinput module."""
572
573 def setUp(self):
574 self._orig_state = fileinput._state
575 self._orig_FileInput = fileinput.FileInput
576 fileinput.FileInput = MockFileInput
577
578 def tearDown(self):
579 fileinput.FileInput = self._orig_FileInput
580 fileinput._state = self._orig_state
581
582 def assertExactlyOneInvocation(self, mock_file_input, method_name):
583 # assert that the method with the given name was invoked once
584 actual_count = mock_file_input.invocation_counts[method_name]
585 self.assertEqual(actual_count, 1, method_name)
586 # assert that no other unexpected methods were invoked
587 actual_total_count = len(mock_file_input.invocation_counts)
588 self.assertEqual(actual_total_count, 1)
589
590class Test_fileinput_input(BaseFileInputGlobalMethodsTest):
591 """Unit tests for fileinput.input()"""
592
593 def test_state_is_not_None_and_state_file_is_not_None(self):
594 """Tests invoking fileinput.input() when fileinput._state is not None
595 and its _file attribute is also not None. Expect RuntimeError to
596 be raised with a meaningful error message and for fileinput._state
597 to *not* be modified."""
598 instance = MockFileInput()
599 instance._file = object()
600 fileinput._state = instance
601 with self.assertRaises(RuntimeError) as cm:
602 fileinput.input()
603 self.assertEqual(("input() already active",), cm.exception.args)
604 self.assertIs(instance, fileinput._state, "fileinput._state")
605
606 def test_state_is_not_None_and_state_file_is_None(self):
607 """Tests invoking fileinput.input() when fileinput._state is not None
608 but its _file attribute *is* None. Expect it to create and return
609 a new fileinput.FileInput object with all method parameters passed
610 explicitly to the __init__() method; also ensure that
611 fileinput._state is set to the returned instance."""
612 instance = MockFileInput()
613 instance._file = None
614 fileinput._state = instance
615 self.do_test_call_input()
616
617 def test_state_is_None(self):
618 """Tests invoking fileinput.input() when fileinput._state is None
619 Expect it to create and return a new fileinput.FileInput object
620 with all method parameters passed explicitly to the __init__()
621 method; also ensure that fileinput._state is set to the returned
622 instance."""
623 fileinput._state = None
624 self.do_test_call_input()
625
626 def do_test_call_input(self):
627 """Tests that fileinput.input() creates a new fileinput.FileInput
628 object, passing the given parameters unmodified to
629 fileinput.FileInput.__init__(). Note that this test depends on the
630 monkey patching of fileinput.FileInput done by setUp()."""
631 files = object()
632 inplace = object()
633 backup = object()
634 bufsize = object()
635 mode = object()
636 openhook = object()
637
638 # call fileinput.input() with different values for each argument
639 result = fileinput.input(files=files, inplace=inplace, backup=backup,
640 bufsize=bufsize,
641 mode=mode, openhook=openhook)
642
643 # ensure fileinput._state was set to the returned object
644 self.assertIs(result, fileinput._state, "fileinput._state")
645
646 # ensure the parameters to fileinput.input() were passed directly
647 # to FileInput.__init__()
648 self.assertIs(files, result.files, "files")
649 self.assertIs(inplace, result.inplace, "inplace")
650 self.assertIs(backup, result.backup, "backup")
651 self.assertIs(bufsize, result.bufsize, "bufsize")
652 self.assertIs(mode, result.mode, "mode")
653 self.assertIs(openhook, result.openhook, "openhook")
654
655class Test_fileinput_close(BaseFileInputGlobalMethodsTest):
656 """Unit tests for fileinput.close()"""
657
658 def test_state_is_None(self):
659 """Tests that fileinput.close() does nothing if fileinput._state
660 is None"""
661 fileinput._state = None
662 fileinput.close()
663 self.assertIsNone(fileinput._state)
664
665 def test_state_is_not_None(self):
666 """Tests that fileinput.close() invokes close() on fileinput._state
667 and sets _state=None"""
668 instance = MockFileInput()
669 fileinput._state = instance
670 fileinput.close()
671 self.assertExactlyOneInvocation(instance, "close")
672 self.assertIsNone(fileinput._state)
673
674class Test_fileinput_nextfile(BaseFileInputGlobalMethodsTest):
675 """Unit tests for fileinput.nextfile()"""
676
677 def test_state_is_None(self):
678 """Tests fileinput.nextfile() when fileinput._state is None.
679 Ensure that it raises RuntimeError with a meaningful error message
680 and does not modify fileinput._state"""
681 fileinput._state = None
682 with self.assertRaises(RuntimeError) as cm:
683 fileinput.nextfile()
684 self.assertEqual(("no active input()",), cm.exception.args)
685 self.assertIsNone(fileinput._state)
686
687 def test_state_is_not_None(self):
688 """Tests fileinput.nextfile() when fileinput._state is not None.
689 Ensure that it invokes fileinput._state.nextfile() exactly once,
690 returns whatever it returns, and does not modify fileinput._state
691 to point to a different object."""
692 nextfile_retval = object()
693 instance = MockFileInput()
694 instance.return_values["nextfile"] = nextfile_retval
695 fileinput._state = instance
696 retval = fileinput.nextfile()
697 self.assertExactlyOneInvocation(instance, "nextfile")
698 self.assertIs(retval, nextfile_retval)
699 self.assertIs(fileinput._state, instance)
700
701class Test_fileinput_filename(BaseFileInputGlobalMethodsTest):
702 """Unit tests for fileinput.filename()"""
703
704 def test_state_is_None(self):
705 """Tests fileinput.filename() when fileinput._state is None.
706 Ensure that it raises RuntimeError with a meaningful error message
707 and does not modify fileinput._state"""
708 fileinput._state = None
709 with self.assertRaises(RuntimeError) as cm:
710 fileinput.filename()
711 self.assertEqual(("no active input()",), cm.exception.args)
712 self.assertIsNone(fileinput._state)
713
714 def test_state_is_not_None(self):
715 """Tests fileinput.filename() when fileinput._state is not None.
716 Ensure that it invokes fileinput._state.filename() exactly once,
717 returns whatever it returns, and does not modify fileinput._state
718 to point to a different object."""
719 filename_retval = object()
720 instance = MockFileInput()
721 instance.return_values["filename"] = filename_retval
722 fileinput._state = instance
723 retval = fileinput.filename()
724 self.assertExactlyOneInvocation(instance, "filename")
725 self.assertIs(retval, filename_retval)
726 self.assertIs(fileinput._state, instance)
727
728class Test_fileinput_lineno(BaseFileInputGlobalMethodsTest):
729 """Unit tests for fileinput.lineno()"""
730
731 def test_state_is_None(self):
732 """Tests fileinput.lineno() when fileinput._state is None.
733 Ensure that it raises RuntimeError with a meaningful error message
734 and does not modify fileinput._state"""
735 fileinput._state = None
736 with self.assertRaises(RuntimeError) as cm:
737 fileinput.lineno()
738 self.assertEqual(("no active input()",), cm.exception.args)
739 self.assertIsNone(fileinput._state)
740
741 def test_state_is_not_None(self):
742 """Tests fileinput.lineno() when fileinput._state is not None.
743 Ensure that it invokes fileinput._state.lineno() exactly once,
744 returns whatever it returns, and does not modify fileinput._state
745 to point to a different object."""
746 lineno_retval = object()
747 instance = MockFileInput()
748 instance.return_values["lineno"] = lineno_retval
749 fileinput._state = instance
750 retval = fileinput.lineno()
751 self.assertExactlyOneInvocation(instance, "lineno")
752 self.assertIs(retval, lineno_retval)
753 self.assertIs(fileinput._state, instance)
754
755class Test_fileinput_filelineno(BaseFileInputGlobalMethodsTest):
756 """Unit tests for fileinput.filelineno()"""
757
758 def test_state_is_None(self):
759 """Tests fileinput.filelineno() when fileinput._state is None.
760 Ensure that it raises RuntimeError with a meaningful error message
761 and does not modify fileinput._state"""
762 fileinput._state = None
763 with self.assertRaises(RuntimeError) as cm:
764 fileinput.filelineno()
765 self.assertEqual(("no active input()",), cm.exception.args)
766 self.assertIsNone(fileinput._state)
767
768 def test_state_is_not_None(self):
769 """Tests fileinput.filelineno() when fileinput._state is not None.
770 Ensure that it invokes fileinput._state.filelineno() exactly once,
771 returns whatever it returns, and does not modify fileinput._state
772 to point to a different object."""
773 filelineno_retval = object()
774 instance = MockFileInput()
775 instance.return_values["filelineno"] = filelineno_retval
776 fileinput._state = instance
777 retval = fileinput.filelineno()
778 self.assertExactlyOneInvocation(instance, "filelineno")
779 self.assertIs(retval, filelineno_retval)
780 self.assertIs(fileinput._state, instance)
781
782class Test_fileinput_fileno(BaseFileInputGlobalMethodsTest):
783 """Unit tests for fileinput.fileno()"""
784
785 def test_state_is_None(self):
786 """Tests fileinput.fileno() when fileinput._state is None.
787 Ensure that it raises RuntimeError with a meaningful error message
788 and does not modify fileinput._state"""
789 fileinput._state = None
790 with self.assertRaises(RuntimeError) as cm:
791 fileinput.fileno()
792 self.assertEqual(("no active input()",), cm.exception.args)
793 self.assertIsNone(fileinput._state)
794
795 def test_state_is_not_None(self):
796 """Tests fileinput.fileno() when fileinput._state is not None.
797 Ensure that it invokes fileinput._state.fileno() exactly once,
798 returns whatever it returns, and does not modify fileinput._state
799 to point to a different object."""
800 fileno_retval = object()
801 instance = MockFileInput()
802 instance.return_values["fileno"] = fileno_retval
803 instance.fileno_retval = fileno_retval
804 fileinput._state = instance
805 retval = fileinput.fileno()
806 self.assertExactlyOneInvocation(instance, "fileno")
807 self.assertIs(retval, fileno_retval)
808 self.assertIs(fileinput._state, instance)
809
810class Test_fileinput_isfirstline(BaseFileInputGlobalMethodsTest):
811 """Unit tests for fileinput.isfirstline()"""
812
813 def test_state_is_None(self):
814 """Tests fileinput.isfirstline() when fileinput._state is None.
815 Ensure that it raises RuntimeError with a meaningful error message
816 and does not modify fileinput._state"""
817 fileinput._state = None
818 with self.assertRaises(RuntimeError) as cm:
819 fileinput.isfirstline()
820 self.assertEqual(("no active input()",), cm.exception.args)
821 self.assertIsNone(fileinput._state)
822
823 def test_state_is_not_None(self):
824 """Tests fileinput.isfirstline() when fileinput._state is not None.
825 Ensure that it invokes fileinput._state.isfirstline() exactly once,
826 returns whatever it returns, and does not modify fileinput._state
827 to point to a different object."""
828 isfirstline_retval = object()
829 instance = MockFileInput()
830 instance.return_values["isfirstline"] = isfirstline_retval
831 fileinput._state = instance
832 retval = fileinput.isfirstline()
833 self.assertExactlyOneInvocation(instance, "isfirstline")
834 self.assertIs(retval, isfirstline_retval)
835 self.assertIs(fileinput._state, instance)
836
837class Test_fileinput_isstdin(BaseFileInputGlobalMethodsTest):
838 """Unit tests for fileinput.isstdin()"""
839
840 def test_state_is_None(self):
841 """Tests fileinput.isstdin() when fileinput._state is None.
842 Ensure that it raises RuntimeError with a meaningful error message
843 and does not modify fileinput._state"""
844 fileinput._state = None
845 with self.assertRaises(RuntimeError) as cm:
846 fileinput.isstdin()
847 self.assertEqual(("no active input()",), cm.exception.args)
848 self.assertIsNone(fileinput._state)
849
850 def test_state_is_not_None(self):
851 """Tests fileinput.isstdin() when fileinput._state is not None.
852 Ensure that it invokes fileinput._state.isstdin() exactly once,
853 returns whatever it returns, and does not modify fileinput._state
854 to point to a different object."""
855 isstdin_retval = object()
856 instance = MockFileInput()
857 instance.return_values["isstdin"] = isstdin_retval
858 fileinput._state = instance
859 retval = fileinput.isstdin()
860 self.assertExactlyOneInvocation(instance, "isstdin")
861 self.assertIs(retval, isstdin_retval)
862 self.assertIs(fileinput._state, instance)
863
864class InvocationRecorder:
865 def __init__(self):
866 self.invocation_count = 0
867 def __call__(self, *args, **kwargs):
868 self.invocation_count += 1
869 self.last_invocation = (args, kwargs)
870
871class Test_hook_compressed(unittest.TestCase):
872 """Unit tests for fileinput.hook_compressed()"""
873
874 def setUp(self):
875 self.fake_open = InvocationRecorder()
876
877 def test_empty_string(self):
878 self.do_test_use_builtin_open("", 1)
879
880 def test_no_ext(self):
881 self.do_test_use_builtin_open("abcd", 2)
882
Ezio Melottic3afbb92011-05-14 10:10:53 +0300883 @unittest.skipUnless(gzip, "Requires gzip and zlib")
briancurtin5eb35912011-03-15 10:59:36 -0400884 def test_gz_ext_fake(self):
briancurtin906f0c42011-03-15 10:29:41 -0400885 original_open = gzip.open
886 gzip.open = self.fake_open
887 try:
888 result = fileinput.hook_compressed("test.gz", 3)
889 finally:
890 gzip.open = original_open
891
892 self.assertEqual(self.fake_open.invocation_count, 1)
893 self.assertEqual(self.fake_open.last_invocation, (("test.gz", 3), {}))
894
briancurtinf84f3c32011-03-18 13:03:17 -0500895 @unittest.skipUnless(bz2, "Requires bz2")
briancurtin5eb35912011-03-15 10:59:36 -0400896 def test_bz2_ext_fake(self):
briancurtin906f0c42011-03-15 10:29:41 -0400897 original_open = bz2.BZ2File
898 bz2.BZ2File = self.fake_open
899 try:
900 result = fileinput.hook_compressed("test.bz2", 4)
901 finally:
902 bz2.BZ2File = original_open
903
904 self.assertEqual(self.fake_open.invocation_count, 1)
905 self.assertEqual(self.fake_open.last_invocation, (("test.bz2", 4), {}))
906
907 def test_blah_ext(self):
908 self.do_test_use_builtin_open("abcd.blah", 5)
909
briancurtin5eb35912011-03-15 10:59:36 -0400910 def test_gz_ext_builtin(self):
briancurtin906f0c42011-03-15 10:29:41 -0400911 self.do_test_use_builtin_open("abcd.Gz", 6)
912
briancurtin5eb35912011-03-15 10:59:36 -0400913 def test_bz2_ext_builtin(self):
briancurtin906f0c42011-03-15 10:29:41 -0400914 self.do_test_use_builtin_open("abcd.Bz2", 7)
915
916 def do_test_use_builtin_open(self, filename, mode):
917 original_open = self.replace_builtin_open(self.fake_open)
918 try:
919 result = fileinput.hook_compressed(filename, mode)
920 finally:
921 self.replace_builtin_open(original_open)
922
923 self.assertEqual(self.fake_open.invocation_count, 1)
924 self.assertEqual(self.fake_open.last_invocation,
925 ((filename, mode), {}))
926
927 @staticmethod
928 def replace_builtin_open(new_open_func):
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100929 original_open = builtins.open
930 builtins.open = new_open_func
briancurtin906f0c42011-03-15 10:29:41 -0400931 return original_open
932
933class Test_hook_encoded(unittest.TestCase):
934 """Unit tests for fileinput.hook_encoded()"""
935
936 def test(self):
937 encoding = object()
Serhiy Storchakab2752102016-04-27 23:13:46 +0300938 errors = object()
939 result = fileinput.hook_encoded(encoding, errors=errors)
briancurtin906f0c42011-03-15 10:29:41 -0400940
941 fake_open = InvocationRecorder()
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100942 original_open = builtins.open
943 builtins.open = fake_open
briancurtin906f0c42011-03-15 10:29:41 -0400944 try:
945 filename = object()
946 mode = object()
947 open_result = result(filename, mode)
948 finally:
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100949 builtins.open = original_open
briancurtin906f0c42011-03-15 10:29:41 -0400950
951 self.assertEqual(fake_open.invocation_count, 1)
952
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100953 args, kwargs = fake_open.last_invocation
briancurtin906f0c42011-03-15 10:29:41 -0400954 self.assertIs(args[0], filename)
955 self.assertIs(args[1], mode)
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100956 self.assertIs(kwargs.pop('encoding'), encoding)
Serhiy Storchakab2752102016-04-27 23:13:46 +0300957 self.assertIs(kwargs.pop('errors'), errors)
Florent Xiclunaa011e2b2011-11-07 19:43:07 +0100958 self.assertFalse(kwargs)
Georg Brandl6cb7b652010-07-31 20:08:15 +0000959
Serhiy Storchakab2752102016-04-27 23:13:46 +0300960 def test_errors(self):
961 with open(TESTFN, 'wb') as f:
962 f.write(b'\x80abc')
963 self.addCleanup(safe_unlink, TESTFN)
964
965 def check(errors, expected_lines):
966 with FileInput(files=TESTFN, mode='r',
967 openhook=hook_encoded('utf-8', errors=errors)) as fi:
968 lines = list(fi)
969 self.assertEqual(lines, expected_lines)
970
971 check('ignore', ['abc'])
972 with self.assertRaises(UnicodeDecodeError):
973 check('strict', ['abc'])
974 check('replace', ['\ufffdabc'])
975 check('backslashreplace', ['\\x80abc'])
976
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200977 def test_modes(self):
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200978 with open(TESTFN, 'wb') as f:
Serhiy Storchaka682ea5f2014-03-03 21:17:17 +0200979 # UTF-7 is a convenient, seldom used encoding
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200980 f.write(b'A\nB\r\nC\rD+IKw-')
981 self.addCleanup(safe_unlink, TESTFN)
982
983 def check(mode, expected_lines):
984 with FileInput(files=TESTFN, mode=mode,
985 openhook=hook_encoded('utf-7')) as fi:
986 lines = list(fi)
987 self.assertEqual(lines, expected_lines)
988
989 check('r', ['A\n', 'B\n', 'C\n', 'D\u20ac'])
Serhiy Storchaka9fff8492014-02-26 21:03:19 +0200990 with self.assertWarns(DeprecationWarning):
991 check('rU', ['A\n', 'B\n', 'C\n', 'D\u20ac'])
992 with self.assertWarns(DeprecationWarning):
993 check('U', ['A\n', 'B\n', 'C\n', 'D\u20ac'])
Serhiy Storchaka517b7472014-02-26 20:59:43 +0200994 with self.assertRaises(ValueError):
995 check('rb', ['A\n', 'B\r\n', 'C\r', 'D\u20ac'])
996
Guido van Rossumd8faa362007-04-27 19:54:29 +0000997
Martin Panter7978e102016-01-16 06:26:54 +0000998class MiscTest(unittest.TestCase):
999
1000 def test_all(self):
Serhiy Storchaka674e2d02016-03-08 18:35:19 +02001001 support.check__all__(self, fileinput)
Martin Panter7978e102016-01-16 06:26:54 +00001002
1003
Guido van Rossumd8faa362007-04-27 19:54:29 +00001004if __name__ == "__main__":
Brett Cannon3e9a9ae2013-06-12 21:25:59 -04001005 unittest.main()