diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -95,20 +95,45 @@ class CompileallTests(unittest.TestCase) os.path.isfile(self.bc_path2)) os.unlink(self.bc_path) os.unlink(self.bc_path2) # Test against bad files self.add_bad_source_file() self.assertFalse(compileall.compile_file(self.bad_source_path, force=False, quiet=2)) self.assertFalse(compileall.compile_dir(self.directory, force=False, quiet=2)) + def test_compile_pathlike_files(self): + # Test compiling a single file, and complete directory + for fn in (self.bc_path, self.bc_path2): + try: + os.unlink(fn) + except: + pass + self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path), + force=False, quiet=True)) + self.assertTrue(os.path.isfile(self.bc_path) and + not os.path.isfile(self.bc_path2)) + os.unlink(self.bc_path) + self.assertTrue(compileall.compile_dir(pathlib.Path(self.directory), + force=False, quiet=True)) + self.assertTrue(os.path.isfile(self.bc_path) and + os.path.isfile(self.bc_path2)) + os.unlink(self.bc_path) + os.unlink(self.bc_path2) + # Test against bad files + self.add_bad_source_file() + self.assertFalse(compileall.compile_file(pathlib.Path(self.bad_source_path), + force=False, quiet=2)) + self.assertFalse(compileall.compile_dir(pathlib.Path(self.directory), + force=False, quiet=2)) + def test_compile_path(self): # Exclude Lib/test/ which contains invalid Python files like # Lib/test/badsyntax_pep3120.py testdir = os.path.realpath(os.path.dirname(__file__)) if testdir in sys.path: self.addCleanup(setattr, sys, 'path', sys.path) sys.path = list(sys.path) try: sys.path.remove(testdir)