diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-10-01 00:54:18 +0300 |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-10-01 00:54:18 +0300 |
commit | 812a2b65af1897aa9694ff65fc62516a4e10269c (patch) | |
tree | 5cb56a40cbef3dda1cc42953d8fae00ae7562df6 /Lib/test/test_compileall.py | |
parent | b4b55eb582e5a7c71bac90030ab3c46b5cd6d429 (diff) | |
download | cpython-git-812a2b65af1897aa9694ff65fc62516a4e10269c.tar.gz |
Issue #28226: compileall now supports pathlib
Diffstat (limited to 'Lib/test/test_compileall.py')
-rw-r--r-- | Lib/test/test_compileall.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index 1f05e78c23..30ca3feee4 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -102,6 +102,22 @@ class CompileallTests(unittest.TestCase): self.assertFalse(compileall.compile_dir(self.directory, force=False, quiet=2)) + def test_compile_file_pathlike(self): + self.assertFalse(os.path.isfile(self.bc_path)) + # we should also test the output + with support.captured_stdout() as stdout: + self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path))) + self.assertEqual(stdout.getvalue(), + "Compiling '{}'...\n".format(self.source_path)) + self.assertTrue(os.path.isfile(self.bc_path)) + + def test_compile_file_pathlike_ddir(self): + self.assertFalse(os.path.isfile(self.bc_path)) + self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path), + ddir=pathlib.Path('ddir_path'), + quiet=2)) + self.assertTrue(os.path.isfile(self.bc_path)) + def test_compile_path(self): with test.test_importlib.util.import_state(path=[self.directory]): self.assertTrue(compileall.compile_path(quiet=2)) @@ -138,6 +154,13 @@ class CompileallTests(unittest.TestCase): optimization=opt) self.assertTrue(os.path.isfile(cached3)) + def test_compile_dir_pathlike(self): + self.assertFalse(os.path.isfile(self.bc_path)) + with support.captured_stdout() as stdout: + compileall.compile_dir(pathlib.Path(self.directory)) + self.assertIn("Listing '{}'...".format(self.directory), stdout.getvalue()) + self.assertTrue(os.path.isfile(self.bc_path)) + @mock.patch('compileall.ProcessPoolExecutor') def test_compile_pool_called(self, pool_mock): compileall.compile_dir(self.directory, quiet=True, workers=5) |