def test_only_new_files(self): """ When calling a second time gen_filenames with only_new = True, only files from newly loaded modules should be given. """ dirname = tempfile.mkdtemp() filename = os.path.join(dirname, 'test_only_new_module.py') self.addCleanup(shutil.rmtree, dirname) with open(filename, 'w'): pass # Test uncached access self.clear_autoreload_caches() filenames = set(autoreload.gen_filenames(only_new=True)) filenames_reference = set(autoreload.gen_filenames()) self.assertEqual(filenames, filenames_reference) # Test cached access: no changes filenames = set(autoreload.gen_filenames(only_new=True)) self.assertEqual(filenames, set()) # Test cached access: add a module with extend_sys_path(dirname): import_module('test_only_new_module') filenames = set(autoreload.gen_filenames(only_new=True)) self.assertEqual(filenames, {filename})
def test_paths_are_native_strings(self): for filename in autoreload.gen_filenames(): self.assertIsInstance(filename, str)
def assertFileFoundOnlyNew(self, filename): self.clear_autoreload_caches() # Test uncached access self.assertIn(filename, autoreload.gen_filenames(only_new=True)) # Test cached access self.assertNotIn(filename, autoreload.gen_filenames(only_new=True))
def assertFileNotFound(self, filename): self.clear_autoreload_caches() # Test uncached access self.assertNotIn(filename, autoreload.gen_filenames()) # Test cached access self.assertNotIn(filename, autoreload.gen_filenames())