def test_builtins_generation_mode_stores_all_skeletons_in_same_cache_directory(self): self.run_generator(builtins=True) builtins_hash = generator3.module_hash('sys', None) builtins_cache_dir = os.path.join(self.temp_cache_dir, builtins_hash) self.assertTrue(os.path.isdir(builtins_cache_dir)) builtin_mod_skeletons = os.listdir(builtins_cache_dir) self.assertIn('_ast.py', builtin_mod_skeletons) self.assertIn('sys.py', builtin_mod_skeletons)
def test_layout_for_builtin_module(self): self.run_generator(mod_qname='_ast') self.assertDirLayoutEquals(os.path.join(self.temp_dir, self.PYTHON_STUBS_DIR), """ cache/ {hash}/ _ast.py sdk_skeletons/ _ast.py """.format(hash=generator3.module_hash('_ast', None)))
def test_layout_for_toplevel_physical_module(self): mod_path = os.path.join(self.test_data_dir, 'mod.py') self.run_generator(mod_qname='mod', mod_path=mod_path) self.assertDirLayoutEquals(os.path.join(self.temp_dir, self.PYTHON_STUBS_DIR), """ cache/ {hash}/ mod.py sdk_skeletons/ mod.py """.format(hash=generator3.module_hash('mod', mod_path)))
def test_pregenerated_skeletons_mode_for_builtin_module(self): self.run_generator('sys', builtins=True, extra_env={ 'IS_PREGENERATED_SKELETONS': '1' }) sys_cached_skeleton_path = os.path.join(self.temp_cache_dir, generator3.module_hash('sys', None), 'sys.py') self.assertTrue(os.path.exists(sys_cached_skeleton_path)) with open(sys_cached_skeleton_path, 'r') as f: self.assertTrue('# from (pre-generated)\n' in f.read()) sys_skeleton_path = os.path.join(self.temp_skeletons_dir, 'sys.py') self.assertTrue(os.path.exists(sys_skeleton_path)) with open(sys_skeleton_path, 'r') as f: self.assertTrue('# from (built-in)\n' in f.read())
def test_origin_stamp_for_pregenerated_builtins_is_updated(self): mod_hash = generator3.module_hash('_abc', None) template = textwrap.dedent("""\ # encoding: utf-8 # module _ast # from {origin} # by generator 1000.0 """) cache_entry_dir = os.path.join(self.temp_cache_dir, mod_hash) mkdir(cache_entry_dir) with open(os.path.join(cache_entry_dir, '_ast.py'), 'w') as f: f.write(template.format(origin='(pre-generated)')) self.run_generator('_ast', None, True) with open(os.path.join(self.temp_skeletons_dir, '_ast.py')) as f: self.assertEquals(template.format(origin='(built-in)'), f.read())
def test_layout_for_physical_module_inside_package(self): mod_path = self.get_test_data_path('pkg/subpkg/mod.py') self.run_generator(mod_qname='pkg.subpkg.mod', mod_path=mod_path) self.assertDirLayoutEquals(os.path.join(self.temp_dir, self.PYTHON_STUBS_DIR), """ cache/ {hash}/ pkg/ __init__.py subpkg/ __init__.py mod.py sdk_skeletons/ pkg/ __init__.py subpkg/ __init__.py mod.py """.format(hash=generator3.module_hash('mod', mod_path)))