summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-11-20 21:18:51 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-11-20 21:18:51 (GMT)
commit650f147298873f2d7db046dbdfbb76c749c31d22 (patch)
treeac60a182da284d92c6126c460a2bf8e802c4bf18 /Lib/test
parenta78f74ce02f5092e4c385eb2aee709d00942d0ed (diff)
downloadcpython-650f147298873f2d7db046dbdfbb76c749c31d22.zip
cpython-650f147298873f2d7db046dbdfbb76c749c31d22.tar.gz
cpython-650f147298873f2d7db046dbdfbb76c749c31d22.tar.bz2
#10453: compileall now uses argparse instead of getopt, so -h works.
Patch by Michele OrrĂ¹.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_compileall.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index 1f8df38..4fd7ddf 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -7,6 +7,7 @@ import shutil
import struct
import subprocess
import tempfile
+import time
import unittest
import io
@@ -112,7 +113,7 @@ class EncodingTest(unittest.TestCase):
class CommandLineTests(unittest.TestCase):
- """Test some aspects of compileall's CLI."""
+ """Test compileall's CLI."""
def setUp(self):
self.addCleanup(self._cleanup)
@@ -184,6 +185,57 @@ class CommandLineTests(unittest.TestCase):
self.assertTrue(os.path.exists(cachedir))
self.assertFalse(os.path.exists(cachecachedir))
+ def test_force(self):
+ retcode = subprocess.call(
+ (sys.executable, '-m', 'compileall', '-q', self.pkgdir))
+ self.assertEqual(retcode, 0)
+ pycpath = imp.cache_from_source(os.path.join(self.pkgdir, 'bar.py'))
+ # set atime/mtime backward to avoid file timestamp resolution issues
+ os.utime(pycpath, (time.time()-60,)*2)
+ access = os.stat(pycpath).st_mtime
+ retcode = subprocess.call(
+ (sys.executable, '-m', 'compileall', '-q', '-f', self.pkgdir))
+ self.assertEqual(retcode, 0)
+ access2 = os.stat(pycpath).st_mtime
+ self.assertNotEqual(access, access2)
+
+ def test_legacy(self):
+ # create a new module
+ newpackage = os.path.join(self.pkgdir, 'spam')
+ os.mkdir(newpackage)
+ with open(os.path.join(newpackage, '__init__.py'), 'w'):
+ pass
+ with open(os.path.join(newpackage, 'ham.py'), 'w'):
+ pass
+ sourcefile = os.path.join(newpackage, 'ham.py')
+
+ retcode = subprocess.call(
+ (sys.executable, '-m', 'compileall', '-q', '-l', self.pkgdir))
+ self.assertEqual(retcode, 0)
+ self.assertFalse(os.path.exists(imp.cache_from_source(sourcefile)))
+
+ retcode = subprocess.call(
+ (sys.executable, '-m', 'compileall', '-q', self.pkgdir))
+ self.assertEqual(retcode, 0)
+ self.assertTrue(os.path.exists(imp.cache_from_source(sourcefile)))
+
+ def test_quiet(self):
+ noise = subprocess.getoutput('{} -m compileall {}'.format(
+ sys.executable, self.pkgdir))
+ quiet = subprocess.getoutput(('{} -m compileall {}'.format(
+ sys.executable, self.pkgdir)))
+ self.assertTrue(len(noise) > len(quiet))
+
+ def test_regexp(self):
+ retcode = subprocess.call(
+ (sys.executable, '-m', 'compileall', '-q', '-x', 'bar.*', self.pkgdir))
+ self.assertEqual(retcode, 0)
+
+ sourcefile = os.path.join(self.pkgdir, 'bar.py')
+ self.assertFalse(os.path.exists(imp.cache_from_source(sourcefile)))
+ sourcefile = os.path.join(self.pkgdir, '__init__.py')
+ self.assertTrue(os.path.exists(imp.cache_from_source(sourcefile)))
+
def test_main():
support.run_unittest(