mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
#10719: restore messages generated on invalid compileall args
Before the introduction of filename arguments to compileall it gave semi useful messages about not being able to 'list' names that weren't valid directories. This fix restores that behavior. In addition to the test for this case, the patch also adds a test for the default behavior of compileall when no arguments are provided, and fixes a bug in one of the previously added tests.
This commit is contained in:
parent
20f0fb68aa
commit
5317e9cd8d
2 changed files with 22 additions and 13 deletions
|
@ -207,15 +207,15 @@ def main():
|
||||||
try:
|
try:
|
||||||
if compile_dests:
|
if compile_dests:
|
||||||
for dest in compile_dests:
|
for dest in compile_dests:
|
||||||
if os.path.isdir(dest):
|
if os.path.isfile(dest):
|
||||||
|
if not compile_file(dest, args.ddir, args.force, args.rx,
|
||||||
|
args.quiet, args.legacy):
|
||||||
|
success = False
|
||||||
|
else:
|
||||||
if not compile_dir(dest, args.maxlevels, args.ddir,
|
if not compile_dir(dest, args.maxlevels, args.ddir,
|
||||||
args.force, args.rx, args.quiet,
|
args.force, args.rx, args.quiet,
|
||||||
args.legacy):
|
args.legacy):
|
||||||
success = False
|
success = False
|
||||||
else:
|
|
||||||
if not compile_file(dest, args.ddir, args.force, args.rx,
|
|
||||||
args.quiet, args.legacy):
|
|
||||||
success = False
|
|
||||||
return success
|
return success
|
||||||
else:
|
else:
|
||||||
return compile_path(legacy=args.legacy)
|
return compile_path(legacy=args.legacy)
|
||||||
|
|
|
@ -124,14 +124,15 @@ class EncodingTest(unittest.TestCase):
|
||||||
class CommandLineTests(unittest.TestCase):
|
class CommandLineTests(unittest.TestCase):
|
||||||
"""Test compileall's CLI."""
|
"""Test compileall's CLI."""
|
||||||
|
|
||||||
def assertRunOK(self, *args):
|
def assertRunOK(self, *args, **env_vars):
|
||||||
rc, out, err = script_helper.assert_python_ok('-m', 'compileall', *args)
|
rc, out, err = script_helper.assert_python_ok(
|
||||||
|
'-m', 'compileall', *args, **env_vars)
|
||||||
self.assertEqual(b'', err)
|
self.assertEqual(b'', err)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def assertRunNotOK(self, *args):
|
def assertRunNotOK(self, *args, **env_vars):
|
||||||
rc, out, err = script_helper.assert_python_failure(
|
rc, out, err = script_helper.assert_python_failure(
|
||||||
'-m', 'compileall', *args)
|
'-m', 'compileall', *args, **env_vars)
|
||||||
return rc, out, err
|
return rc, out, err
|
||||||
|
|
||||||
def assertCompiled(self, fn):
|
def assertCompiled(self, fn):
|
||||||
|
@ -149,12 +150,17 @@ class CommandLineTests(unittest.TestCase):
|
||||||
# Create the __init__.py and a package module.
|
# Create the __init__.py and a package module.
|
||||||
self.initfn = script_helper.make_script(self.pkgdir, '__init__', '')
|
self.initfn = script_helper.make_script(self.pkgdir, '__init__', '')
|
||||||
self.barfn = script_helper.make_script(self.pkgdir, 'bar', '')
|
self.barfn = script_helper.make_script(self.pkgdir, 'bar', '')
|
||||||
sys.path.insert(0, self.directory)
|
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
support.rmtree(self.directory)
|
support.rmtree(self.directory)
|
||||||
assert sys.path[0] == self.directory, 'Missing path'
|
|
||||||
del sys.path[0]
|
def test_no_args_compiles_path(self):
|
||||||
|
# Note that -l is implied for the no args case.
|
||||||
|
bazfn = script_helper.make_script(self.directory, 'baz', '')
|
||||||
|
self.assertRunOK(PYTHONPATH=self.directory)
|
||||||
|
self.assertCompiled(bazfn)
|
||||||
|
self.assertNotCompiled(self.initfn)
|
||||||
|
self.assertNotCompiled(self.barfn)
|
||||||
|
|
||||||
# Ensure that the default behavior of compileall's CLI is to create
|
# Ensure that the default behavior of compileall's CLI is to create
|
||||||
# PEP 3147 pyc/pyo files.
|
# PEP 3147 pyc/pyo files.
|
||||||
|
@ -322,11 +328,14 @@ class CommandLineTests(unittest.TestCase):
|
||||||
bingfn = script_helper.make_script(self.pkgdir, 'bing', 'syntax(error')
|
bingfn = script_helper.make_script(self.pkgdir, 'bing', 'syntax(error')
|
||||||
rc, out, err = self.assertRunNotOK('nosuchfile', self.initfn,
|
rc, out, err = self.assertRunNotOK('nosuchfile', self.initfn,
|
||||||
bingfn, self.barfn)
|
bingfn, self.barfn)
|
||||||
self.assertRegex(b'rror', err)
|
self.assertRegex(out, b'rror')
|
||||||
self.assertNotCompiled(bingfn)
|
self.assertNotCompiled(bingfn)
|
||||||
self.assertCompiled(self.initfn)
|
self.assertCompiled(self.initfn)
|
||||||
self.assertCompiled(self.barfn)
|
self.assertCompiled(self.barfn)
|
||||||
|
|
||||||
|
def test_invalid_arg_produces_message(self):
|
||||||
|
out = self.assertRunOK('badfilename')
|
||||||
|
self.assertRegex(out, b"Can't list badfilename")
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue