blob: 2a42238755c72e35aa171725a9b139f5498455ad [file] [log] [blame]
Martin v. Löwis4b003072010-03-16 13:19:21 +00001import sys
Brett Cannonbefb14f2009-02-10 02:10:16 +00002import compileall
Brett Cannon7822e122013-06-14 23:04:02 -04003import importlib.util
Brett Cannonbefb14f2009-02-10 02:10:16 +00004import os
5import py_compile
6import shutil
7import struct
Brett Cannonbefb14f2009-02-10 02:10:16 +00008import tempfile
R. David Murray650f1472010-11-20 21:18:51 +00009import time
Brett Cannonbefb14f2009-02-10 02:10:16 +000010import unittest
Martin v. Löwis4b003072010-03-16 13:19:21 +000011import io
Brett Cannonbefb14f2009-02-10 02:10:16 +000012
R. David Murray95333e32010-12-14 22:32:50 +000013from test import support, script_helper
Brett Cannonbefb14f2009-02-10 02:10:16 +000014
15class CompileallTests(unittest.TestCase):
16
17 def setUp(self):
18 self.directory = tempfile.mkdtemp()
19 self.source_path = os.path.join(self.directory, '_test.py')
Brett Cannon7822e122013-06-14 23:04:02 -040020 self.bc_path = importlib.util.cache_from_source(self.source_path)
Brett Cannonbefb14f2009-02-10 02:10:16 +000021 with open(self.source_path, 'w') as file:
22 file.write('x = 123\n')
Matthias Klosec33b9022010-03-16 00:36:26 +000023 self.source_path2 = os.path.join(self.directory, '_test2.py')
Brett Cannon7822e122013-06-14 23:04:02 -040024 self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
Matthias Klosec33b9022010-03-16 00:36:26 +000025 shutil.copyfile(self.source_path, self.source_path2)
Georg Brandl45438462011-02-07 12:36:54 +000026 self.subdirectory = os.path.join(self.directory, '_subdir')
27 os.mkdir(self.subdirectory)
28 self.source_path3 = os.path.join(self.subdirectory, '_test3.py')
29 shutil.copyfile(self.source_path, self.source_path3)
Brett Cannonbefb14f2009-02-10 02:10:16 +000030
31 def tearDown(self):
32 shutil.rmtree(self.directory)
33
34 def data(self):
35 with open(self.bc_path, 'rb') as file:
36 data = file.read(8)
37 mtime = int(os.stat(self.source_path).st_mtime)
Brett Cannon7822e122013-06-14 23:04:02 -040038 compare = struct.pack('<4sl', importlib.util.MAGIC_NUMBER, mtime)
Brett Cannonbefb14f2009-02-10 02:10:16 +000039 return data, compare
40
Serhiy Storchaka43767632013-11-03 21:31:38 +020041 @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()')
Brett Cannonbefb14f2009-02-10 02:10:16 +000042 def recreation_check(self, metadata):
43 """Check that compileall recreates bytecode when the new metadata is
44 used."""
Brett Cannonbefb14f2009-02-10 02:10:16 +000045 py_compile.compile(self.source_path)
46 self.assertEqual(*self.data())
47 with open(self.bc_path, 'rb') as file:
48 bc = file.read()[len(metadata):]
49 with open(self.bc_path, 'wb') as file:
50 file.write(metadata)
51 file.write(bc)
52 self.assertNotEqual(*self.data())
53 compileall.compile_dir(self.directory, force=False, quiet=True)
54 self.assertTrue(*self.data())
55
56 def test_mtime(self):
57 # Test a change in mtime leads to a new .pyc.
Brett Cannon7822e122013-06-14 23:04:02 -040058 self.recreation_check(struct.pack('<4sl', importlib.util.MAGIC_NUMBER,
59 1))
Brett Cannonbefb14f2009-02-10 02:10:16 +000060
61 def test_magic_number(self):
62 # Test a change in mtime leads to a new .pyc.
63 self.recreation_check(b'\0\0\0\0')
64
Matthias Klosec33b9022010-03-16 00:36:26 +000065 def test_compile_files(self):
66 # Test compiling a single file, and complete directory
67 for fn in (self.bc_path, self.bc_path2):
68 try:
69 os.unlink(fn)
70 except:
71 pass
72 compileall.compile_file(self.source_path, force=False, quiet=True)
Barry Warsaw28a691b2010-04-17 00:19:56 +000073 self.assertTrue(os.path.isfile(self.bc_path) and
74 not os.path.isfile(self.bc_path2))
Matthias Klosec33b9022010-03-16 00:36:26 +000075 os.unlink(self.bc_path)
76 compileall.compile_dir(self.directory, force=False, quiet=True)
Barry Warsaw28a691b2010-04-17 00:19:56 +000077 self.assertTrue(os.path.isfile(self.bc_path) and
78 os.path.isfile(self.bc_path2))
Matthias Klosec33b9022010-03-16 00:36:26 +000079 os.unlink(self.bc_path)
80 os.unlink(self.bc_path2)
Brett Cannonbefb14f2009-02-10 02:10:16 +000081
Barry Warsawc8a99de2010-04-29 18:43:10 +000082 def test_no_pycache_in_non_package(self):
83 # Bug 8563 reported that __pycache__ directories got created by
84 # compile_file() for non-.py files.
85 data_dir = os.path.join(self.directory, 'data')
86 data_file = os.path.join(data_dir, 'file')
87 os.mkdir(data_dir)
88 # touch data/file
89 with open(data_file, 'w'):
90 pass
91 compileall.compile_file(data_file)
92 self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
93
Georg Brandl8334fd92010-12-04 10:26:46 +000094 def test_optimize(self):
95 # make sure compiling with different optimization settings than the
96 # interpreter's creates the correct file names
97 optimize = 1 if __debug__ else 0
98 compileall.compile_dir(self.directory, quiet=True, optimize=optimize)
Brett Cannon7822e122013-06-14 23:04:02 -040099 cached = importlib.util.cache_from_source(self.source_path,
100 debug_override=not optimize)
Georg Brandl8334fd92010-12-04 10:26:46 +0000101 self.assertTrue(os.path.isfile(cached))
Brett Cannon7822e122013-06-14 23:04:02 -0400102 cached2 = importlib.util.cache_from_source(self.source_path2,
103 debug_override=not optimize)
Georg Brandl45438462011-02-07 12:36:54 +0000104 self.assertTrue(os.path.isfile(cached2))
Brett Cannon7822e122013-06-14 23:04:02 -0400105 cached3 = importlib.util.cache_from_source(self.source_path3,
106 debug_override=not optimize)
Georg Brandl45438462011-02-07 12:36:54 +0000107 self.assertTrue(os.path.isfile(cached3))
Georg Brandl8334fd92010-12-04 10:26:46 +0000108
Barry Warsaw28a691b2010-04-17 00:19:56 +0000109
Martin v. Löwis4b003072010-03-16 13:19:21 +0000110class EncodingTest(unittest.TestCase):
Barry Warsaw28a691b2010-04-17 00:19:56 +0000111 """Issue 6716: compileall should escape source code when printing errors
112 to stdout."""
Martin v. Löwis4b003072010-03-16 13:19:21 +0000113
114 def setUp(self):
115 self.directory = tempfile.mkdtemp()
116 self.source_path = os.path.join(self.directory, '_test.py')
117 with open(self.source_path, 'w', encoding='utf-8') as file:
118 file.write('# -*- coding: utf-8 -*-\n')
119 file.write('print u"\u20ac"\n')
120
121 def tearDown(self):
122 shutil.rmtree(self.directory)
123
124 def test_error(self):
125 try:
126 orig_stdout = sys.stdout
127 sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
128 compileall.compile_dir(self.directory)
129 finally:
130 sys.stdout = orig_stdout
131
Barry Warsawc8a99de2010-04-29 18:43:10 +0000132
Barry Warsaw28a691b2010-04-17 00:19:56 +0000133class CommandLineTests(unittest.TestCase):
R. David Murray650f1472010-11-20 21:18:51 +0000134 """Test compileall's CLI."""
Barry Warsaw28a691b2010-04-17 00:19:56 +0000135
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400136 def _get_run_args(self, args):
137 interp_args = ['-S']
138 if sys.flags.optimize:
139 interp_args.append({1 : '-O', 2 : '-OO'}[sys.flags.optimize])
140 return interp_args + ['-m', 'compileall'] + list(args)
141
R. David Murray5317e9c2010-12-16 19:08:51 +0000142 def assertRunOK(self, *args, **env_vars):
143 rc, out, err = script_helper.assert_python_ok(
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400144 *self._get_run_args(args), **env_vars)
R. David Murray95333e32010-12-14 22:32:50 +0000145 self.assertEqual(b'', err)
146 return out
147
R. David Murray5317e9c2010-12-16 19:08:51 +0000148 def assertRunNotOK(self, *args, **env_vars):
R. David Murray95333e32010-12-14 22:32:50 +0000149 rc, out, err = script_helper.assert_python_failure(
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400150 *self._get_run_args(args), **env_vars)
R. David Murray95333e32010-12-14 22:32:50 +0000151 return rc, out, err
152
153 def assertCompiled(self, fn):
Brett Cannon7822e122013-06-14 23:04:02 -0400154 path = importlib.util.cache_from_source(fn)
155 self.assertTrue(os.path.exists(path))
R. David Murray95333e32010-12-14 22:32:50 +0000156
157 def assertNotCompiled(self, fn):
Brett Cannon7822e122013-06-14 23:04:02 -0400158 path = importlib.util.cache_from_source(fn)
159 self.assertFalse(os.path.exists(path))
R. David Murray95333e32010-12-14 22:32:50 +0000160
Barry Warsaw28a691b2010-04-17 00:19:56 +0000161 def setUp(self):
162 self.addCleanup(self._cleanup)
163 self.directory = tempfile.mkdtemp()
164 self.pkgdir = os.path.join(self.directory, 'foo')
165 os.mkdir(self.pkgdir)
R. David Murray95333e32010-12-14 22:32:50 +0000166 self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__')
167 # Create the __init__.py and a package module.
168 self.initfn = script_helper.make_script(self.pkgdir, '__init__', '')
169 self.barfn = script_helper.make_script(self.pkgdir, 'bar', '')
Barry Warsaw28a691b2010-04-17 00:19:56 +0000170
171 def _cleanup(self):
172 support.rmtree(self.directory)
R. David Murray5317e9c2010-12-16 19:08:51 +0000173
174 def test_no_args_compiles_path(self):
175 # Note that -l is implied for the no args case.
176 bazfn = script_helper.make_script(self.directory, 'baz', '')
177 self.assertRunOK(PYTHONPATH=self.directory)
178 self.assertCompiled(bazfn)
179 self.assertNotCompiled(self.initfn)
180 self.assertNotCompiled(self.barfn)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000181
R David Murray8a1d1e62013-12-15 20:49:38 -0500182 def test_no_args_respects_force_flag(self):
183 bazfn = script_helper.make_script(self.directory, 'baz', '')
184 self.assertRunOK(PYTHONPATH=self.directory)
R David Murray755d5ea2013-12-15 20:56:00 -0500185 pycpath = importlib.util.cache_from_source(bazfn)
R David Murray8a1d1e62013-12-15 20:49:38 -0500186 # Set atime/mtime backward to avoid file timestamp resolution issues
187 os.utime(pycpath, (time.time()-60,)*2)
188 mtime = os.stat(pycpath).st_mtime
189 # Without force, no recompilation
190 self.assertRunOK(PYTHONPATH=self.directory)
191 mtime2 = os.stat(pycpath).st_mtime
192 self.assertEqual(mtime, mtime2)
193 # Now force it.
194 self.assertRunOK('-f', PYTHONPATH=self.directory)
195 mtime2 = os.stat(pycpath).st_mtime
196 self.assertNotEqual(mtime, mtime2)
197
198 def test_no_args_respects_quiet_flag(self):
199 script_helper.make_script(self.directory, 'baz', '')
200 noisy = self.assertRunOK(PYTHONPATH=self.directory)
201 self.assertIn(b'Listing ', noisy)
202 quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
203 self.assertNotIn(b'Listing ', quiet)
204
Georg Brandl1463a3f2010-10-14 07:42:27 +0000205 # Ensure that the default behavior of compileall's CLI is to create
206 # PEP 3147 pyc/pyo files.
207 for name, ext, switch in [
208 ('normal', 'pyc', []),
209 ('optimize', 'pyo', ['-O']),
Éric Araujo31717e82010-11-26 00:39:59 +0000210 ('doubleoptimize', 'pyo', ['-OO']),
Georg Brandl1463a3f2010-10-14 07:42:27 +0000211 ]:
212 def f(self, ext=ext, switch=switch):
R. David Murray95333e32010-12-14 22:32:50 +0000213 script_helper.assert_python_ok(*(switch +
214 ['-m', 'compileall', '-q', self.pkgdir]))
Georg Brandl1463a3f2010-10-14 07:42:27 +0000215 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000216 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
Brett Cannon7822e122013-06-14 23:04:02 -0400217 expected = sorted(base.format(sys.implementation.cache_tag, ext)
218 for base in ('__init__.{}.{}', 'bar.{}.{}'))
R. David Murray95333e32010-12-14 22:32:50 +0000219 self.assertEqual(sorted(os.listdir(self.pkgdir_cachedir)), expected)
Georg Brandl1463a3f2010-10-14 07:42:27 +0000220 # Make sure there are no .pyc files in the source directory.
R. David Murray95333e32010-12-14 22:32:50 +0000221 self.assertFalse([fn for fn in os.listdir(self.pkgdir)
222 if fn.endswith(ext)])
Georg Brandl1463a3f2010-10-14 07:42:27 +0000223 locals()['test_pep3147_paths_' + name] = f
Barry Warsaw28a691b2010-04-17 00:19:56 +0000224
225 def test_legacy_paths(self):
226 # Ensure that with the proper switch, compileall leaves legacy
227 # pyc/pyo files, and no __pycache__ directory.
R. David Murray95333e32010-12-14 22:32:50 +0000228 self.assertRunOK('-b', '-q', self.pkgdir)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000229 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000230 self.assertFalse(os.path.exists(self.pkgdir_cachedir))
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400231 opt = 'c' if __debug__ else 'o'
232 expected = sorted(['__init__.py', '__init__.py' + opt, 'bar.py',
233 'bar.py' + opt])
Barry Warsaw28a691b2010-04-17 00:19:56 +0000234 self.assertEqual(sorted(os.listdir(self.pkgdir)), expected)
235
Barry Warsawc04317f2010-04-26 15:59:03 +0000236 def test_multiple_runs(self):
237 # Bug 8527 reported that multiple calls produced empty
238 # __pycache__/__pycache__ directories.
R. David Murray95333e32010-12-14 22:32:50 +0000239 self.assertRunOK('-q', self.pkgdir)
Barry Warsawc04317f2010-04-26 15:59:03 +0000240 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000241 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
242 cachecachedir = os.path.join(self.pkgdir_cachedir, '__pycache__')
Barry Warsawc04317f2010-04-26 15:59:03 +0000243 self.assertFalse(os.path.exists(cachecachedir))
244 # Call compileall again.
R. David Murray95333e32010-12-14 22:32:50 +0000245 self.assertRunOK('-q', self.pkgdir)
246 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
Barry Warsawc04317f2010-04-26 15:59:03 +0000247 self.assertFalse(os.path.exists(cachecachedir))
248
R. David Murray650f1472010-11-20 21:18:51 +0000249 def test_force(self):
R. David Murray95333e32010-12-14 22:32:50 +0000250 self.assertRunOK('-q', self.pkgdir)
Brett Cannon7822e122013-06-14 23:04:02 -0400251 pycpath = importlib.util.cache_from_source(self.barfn)
R. David Murray650f1472010-11-20 21:18:51 +0000252 # set atime/mtime backward to avoid file timestamp resolution issues
253 os.utime(pycpath, (time.time()-60,)*2)
R. David Murray95333e32010-12-14 22:32:50 +0000254 mtime = os.stat(pycpath).st_mtime
255 # without force, no recompilation
256 self.assertRunOK('-q', self.pkgdir)
257 mtime2 = os.stat(pycpath).st_mtime
258 self.assertEqual(mtime, mtime2)
259 # now force it.
260 self.assertRunOK('-q', '-f', self.pkgdir)
261 mtime2 = os.stat(pycpath).st_mtime
262 self.assertNotEqual(mtime, mtime2)
R. David Murray650f1472010-11-20 21:18:51 +0000263
R. David Murray95333e32010-12-14 22:32:50 +0000264 def test_recursion_control(self):
265 subpackage = os.path.join(self.pkgdir, 'spam')
266 os.mkdir(subpackage)
267 subinitfn = script_helper.make_script(subpackage, '__init__', '')
268 hamfn = script_helper.make_script(subpackage, 'ham', '')
269 self.assertRunOK('-q', '-l', self.pkgdir)
270 self.assertNotCompiled(subinitfn)
271 self.assertFalse(os.path.exists(os.path.join(subpackage, '__pycache__')))
272 self.assertRunOK('-q', self.pkgdir)
273 self.assertCompiled(subinitfn)
274 self.assertCompiled(hamfn)
R. David Murray650f1472010-11-20 21:18:51 +0000275
276 def test_quiet(self):
R. David Murray95333e32010-12-14 22:32:50 +0000277 noisy = self.assertRunOK(self.pkgdir)
278 quiet = self.assertRunOK('-q', self.pkgdir)
279 self.assertNotEqual(b'', noisy)
280 self.assertEqual(b'', quiet)
R. David Murray650f1472010-11-20 21:18:51 +0000281
282 def test_regexp(self):
R David Murrayee1a7cb2011-07-01 14:55:43 -0400283 self.assertRunOK('-q', '-x', r'ba[^\\/]*$', self.pkgdir)
R. David Murray95333e32010-12-14 22:32:50 +0000284 self.assertNotCompiled(self.barfn)
285 self.assertCompiled(self.initfn)
R. David Murray650f1472010-11-20 21:18:51 +0000286
R. David Murray95333e32010-12-14 22:32:50 +0000287 def test_multiple_dirs(self):
288 pkgdir2 = os.path.join(self.directory, 'foo2')
289 os.mkdir(pkgdir2)
290 init2fn = script_helper.make_script(pkgdir2, '__init__', '')
291 bar2fn = script_helper.make_script(pkgdir2, 'bar2', '')
292 self.assertRunOK('-q', self.pkgdir, pkgdir2)
293 self.assertCompiled(self.initfn)
294 self.assertCompiled(self.barfn)
295 self.assertCompiled(init2fn)
296 self.assertCompiled(bar2fn)
297
298 def test_d_takes_exactly_one_dir(self):
299 rc, out, err = self.assertRunNotOK('-d', 'foo')
300 self.assertEqual(out, b'')
301 self.assertRegex(err, b'-d')
302 rc, out, err = self.assertRunNotOK('-d', 'foo', 'bar')
303 self.assertEqual(out, b'')
304 self.assertRegex(err, b'-d')
305
306 def test_d_compile_error(self):
307 script_helper.make_script(self.pkgdir, 'crunchyfrog', 'bad(syntax')
308 rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
309 self.assertRegex(out, b'File "dinsdale')
310
311 def test_d_runtime_error(self):
312 bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception')
313 self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)
314 fn = script_helper.make_script(self.pkgdir, 'bing', 'import baz')
Brett Cannon7822e122013-06-14 23:04:02 -0400315 pyc = importlib.util.cache_from_source(bazfn)
R. David Murray95333e32010-12-14 22:32:50 +0000316 os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc'))
317 os.remove(bazfn)
Victor Stinnere8785ff2013-10-12 14:44:01 +0200318 rc, out, err = script_helper.assert_python_failure(fn, __isolated=False)
R. David Murray95333e32010-12-14 22:32:50 +0000319 self.assertRegex(err, b'File "dinsdale')
320
321 def test_include_bad_file(self):
322 rc, out, err = self.assertRunNotOK(
323 '-i', os.path.join(self.directory, 'nosuchfile'), self.pkgdir)
324 self.assertRegex(out, b'rror.*nosuchfile')
325 self.assertNotRegex(err, b'Traceback')
Brett Cannon7822e122013-06-14 23:04:02 -0400326 self.assertFalse(os.path.exists(importlib.util.cache_from_source(
R. David Murray95333e32010-12-14 22:32:50 +0000327 self.pkgdir_cachedir)))
328
329 def test_include_file_with_arg(self):
330 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
331 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
332 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
333 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
334 with open(os.path.join(self.directory, 'l1'), 'w') as l1:
335 l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
336 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
337 self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
338 self.assertCompiled(f1)
339 self.assertCompiled(f2)
340 self.assertNotCompiled(f3)
341 self.assertCompiled(f4)
342
343 def test_include_file_no_arg(self):
344 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
345 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
346 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
347 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
348 with open(os.path.join(self.directory, 'l1'), 'w') as l1:
349 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
350 self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
351 self.assertNotCompiled(f1)
352 self.assertCompiled(f2)
353 self.assertNotCompiled(f3)
354 self.assertNotCompiled(f4)
355
356 def test_include_on_stdin(self):
357 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
358 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
359 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
360 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400361 p = script_helper.spawn_python(*(self._get_run_args(()) + ['-i', '-']))
R. David Murray95333e32010-12-14 22:32:50 +0000362 p.stdin.write((f3+os.linesep).encode('ascii'))
363 script_helper.kill_python(p)
364 self.assertNotCompiled(f1)
365 self.assertNotCompiled(f2)
366 self.assertCompiled(f3)
367 self.assertNotCompiled(f4)
368
369 def test_compiles_as_much_as_possible(self):
370 bingfn = script_helper.make_script(self.pkgdir, 'bing', 'syntax(error')
371 rc, out, err = self.assertRunNotOK('nosuchfile', self.initfn,
372 bingfn, self.barfn)
R. David Murray5317e9c2010-12-16 19:08:51 +0000373 self.assertRegex(out, b'rror')
R. David Murray95333e32010-12-14 22:32:50 +0000374 self.assertNotCompiled(bingfn)
375 self.assertCompiled(self.initfn)
376 self.assertCompiled(self.barfn)
377
R. David Murray5317e9c2010-12-16 19:08:51 +0000378 def test_invalid_arg_produces_message(self):
379 out = self.assertRunOK('badfilename')
Victor Stinner53071262011-05-11 00:36:28 +0200380 self.assertRegex(out, b"Can't list 'badfilename'")
R. David Murray650f1472010-11-20 21:18:51 +0000381
Barry Warsaw28a691b2010-04-17 00:19:56 +0000382
Brett Cannonbefb14f2009-02-10 02:10:16 +0000383if __name__ == "__main__":
Brett Cannon7822e122013-06-14 23:04:02 -0400384 unittest.main()