def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options(sys.argv[1:]) if options.pdb: set_drop_into_pdb(True) if options.show_traceback: set_show_tb(True) f = sys.stdout try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: f = sys.stderr if a: for m in a: f.write(m + "\n") sys.exit(1)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options(sys.argv[1:]) if options.pdb: set_drop_into_pdb(True) if options.show_traceback: set_show_tb(True) f = sys.stdout try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: f = sys.stderr if a: for m in a: f.write(m + '\n') sys.exit(1)
def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: find_module_clear_caches() original_program_text = "\n".join(testcase.input) module_data = self.parse_module(original_program_text, incremental) options = self.parse_options(original_program_text, testcase) options.use_builtins_fixtures = True set_show_tb(True) # Show traceback on crash. if incremental: options.incremental = True if incremental == 1: # In run 1, copy program text to program file. for module_name, program_path, program_text in module_data: if module_name == "__main__": with open(program_path, "w") as f: f.write(program_text) break elif incremental == 2: # In run 2, copy *.py.next files to *.py files. for dn, dirs, files in os.walk(os.curdir): for file in files: if file.endswith(".py.next"): full = os.path.join(dn, file) target = full[:-5] shutil.copy(full, target) # In some systems, mtime has a resolution of 1 second which can cause # annoying-to-debug issues when a file has the same size after a # change. We manually set the mtime to circumvent this. new_time = os.stat(target).st_mtime + 1 os.utime(target, times=(new_time, new_time)) sources = [] for module_name, program_path, program_text in module_data: # Always set to none so we're forced to reread the module in incremental mode program_text = None if incremental else program_text sources.append(BuildSource(program_path, module_name, program_text)) try: res = build.build(sources=sources, options=options, alt_lib_path=test_temp_dir) a = res.errors except CompileError as e: res = None a = e.messages a = normalize_error_messages(a) # Make sure error messages match if incremental == 0: msg = "Invalid type checker output ({}, line {})" output = testcase.output elif incremental == 1: msg = "Invalid type checker output in incremental, run 1 ({}, line {})" output = testcase.output elif incremental == 2: msg = "Invalid type checker output in incremental, run 2 ({}, line {})" output = testcase.output2 else: raise AssertionError() if output != a and self.update_data: update_testcase_output(testcase, a) assert_string_arrays_equal(output, a, msg.format(testcase.file, testcase.line)) if incremental and res: if not options.silent_imports and testcase.output is None: self.verify_cache(module_data, a, res.manager) if incremental == 2: self.check_module_equivalence( "rechecked", testcase.expected_rechecked_modules, res.manager.rechecked_modules ) self.check_module_equivalence("stale", testcase.expected_stale_modules, res.manager.stale_modules)
def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: find_module_clear_caches() original_program_text = '\n'.join(testcase.input) module_data = self.parse_module(original_program_text, incremental) options = self.parse_options(original_program_text) options.use_builtins_fixtures = True options.python_version = testcase_pyversion(testcase.file, testcase.name) set_show_tb(True) # Show traceback on crash. output = testcase.output if incremental: options.incremental = True if incremental == 1: # In run 1, copy program text to program file. output = [] for module_name, program_path, program_text in module_data: if module_name == '__main__': with open(program_path, 'w') as f: f.write(program_text) break elif incremental == 2: # In run 2, copy *.py.next files to *.py files. for dn, dirs, files in os.walk(os.curdir): for file in files: if file.endswith('.py.next'): full = os.path.join(dn, file) target = full[:-5] shutil.copy(full, target) # In some systems, mtime has a resolution of 1 second which can cause # annoying-to-debug issues when a file has the same size after a # change. We manually set the mtime to circumvent this. new_time = os.stat(target).st_mtime + 1 os.utime(target, times=(new_time, new_time)) sources = [] for module_name, program_path, program_text in module_data: # Always set to none so we're forced to reread the module in incremental mode program_text = None if incremental else program_text sources.append(BuildSource(program_path, module_name, program_text)) try: res = build.build(sources=sources, options=options, alt_lib_path=test_temp_dir) a = res.errors except CompileError as e: res = None a = e.messages a = normalize_error_messages(a) if output != a and self.update_data: update_testcase_output(testcase, a) assert_string_arrays_equal( output, a, 'Invalid type checker output ({}, line {})'.format( testcase.file, testcase.line)) if incremental and res: if not options.silent_imports: self.verify_cache(module_data, a, res.manager) if testcase.expected_stale_modules is not None and incremental == 2: assert_string_arrays_equal( list(sorted(testcase.expected_stale_modules)), list(sorted(res.manager.stale_modules.difference({"__main__"}))), 'Set of stale modules does not match expected set')
def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: find_module_clear_caches() original_program_text = '\n'.join(testcase.input) module_data = self.parse_module(original_program_text, incremental) options = self.parse_options(original_program_text, testcase) options.use_builtins_fixtures = True set_show_tb(True) # Show traceback on crash. if incremental: options.incremental = True if incremental == 1: # In run 1, copy program text to program file. for module_name, program_path, program_text in module_data: if module_name == '__main__': with open(program_path, 'w') as f: f.write(program_text) break elif incremental == 2: # In run 2, copy *.py.next files to *.py files. for dn, dirs, files in os.walk(os.curdir): for file in files: if file.endswith('.py.next'): full = os.path.join(dn, file) target = full[:-5] shutil.copy(full, target) # In some systems, mtime has a resolution of 1 second which can cause # annoying-to-debug issues when a file has the same size after a # change. We manually set the mtime to circumvent this. new_time = os.stat(target).st_mtime + 1 os.utime(target, times=(new_time, new_time)) sources = [] for module_name, program_path, program_text in module_data: # Always set to none so we're forced to reread the module in incremental mode program_text = None if incremental else program_text sources.append(BuildSource(program_path, module_name, program_text)) try: res = build.build(sources=sources, options=options, alt_lib_path=test_temp_dir) a = res.errors except CompileError as e: res = None a = e.messages a = normalize_error_messages(a) # Make sure error messages match if incremental == 0: msg = 'Invalid type checker output ({}, line {})' output = testcase.output elif incremental == 1: msg = 'Invalid type checker output in incremental, run 1 ({}, line {})' output = testcase.output elif incremental == 2: msg = 'Invalid type checker output in incremental, run 2 ({}, line {})' output = testcase.output2 else: raise AssertionError() if output != a and self.update_data: update_testcase_output(testcase, a) assert_string_arrays_equal(output, a, msg.format(testcase.file, testcase.line)) if incremental and res: if not options.silent_imports and testcase.output is None: self.verify_cache(module_data, a, res.manager) if incremental == 2: self.check_module_equivalence( 'rechecked', testcase.expected_rechecked_modules, res.manager.rechecked_modules) self.check_module_equivalence('stale', testcase.expected_stale_modules, res.manager.stale_modules)