def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) dump_all = '# __dump_all__' in src if testcase.name.endswith('python2'): python_version = defaults.PYTHON2_VERSION else: python_version = defaults.PYTHON3_VERSION messages, files, type_map = self.build(src, python_version) a = messages if files is None or type_map is None: if not a: a = [ 'Unknown compile error (likely syntax error in test case or fixture)' ] else: deps = defaultdict(set) # type: DefaultDict[str, Set[str]] for module in files: if module in dumped_modules or dump_all and module not in ( 'abc', 'typing', 'mypy_extensions'): new_deps = get_dependencies(files[module], type_map, python_version) for source in new_deps: deps[source].update(new_deps[source]) for source, targets in sorted(deps.items()): line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))
def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) if testcase.name.endswith('python2'): python_version = defaults.PYTHON2_VERSION else: python_version = defaults.PYTHON3_VERSION messages, files, type_map = self.build(src, python_version) a = messages if files is None or type_map is None: if not a: a = [ 'Unknown compile error (likely syntax error in test case or fixture)' ] else: deps = get_dependencies(files['__main__'], type_map, python_version) for source, targets in sorted(deps.items()): line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))
def update_dependencies(new_modules: Dict[str, MypyFile], deps: Dict[str, Set[str]], graph: Dict[str, State]) -> None: for id, node in new_modules.items(): module_deps = get_dependencies( prefix=id, node=node, type_map=graph[id].type_checker.type_map) for trigger, targets in module_deps.items(): deps.setdefault(trigger, set()).update(targets)
def update_dependencies(new_modules: Dict[str, MypyFile], deps: Dict[str, Set[str]], graph: Dict[str, State], options: Options) -> None: for id, node in new_modules.items(): module_deps = get_dependencies( target=node, type_map=graph[id].type_checker.type_map, python_version=options.python_version) for trigger, targets in module_deps.items(): deps.setdefault(trigger, set()).update(targets)
def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) messages, files, type_map = self.build(src) a = messages deps = get_dependencies('__main__', files['__main__'], type_map) for source, targets in sorted(deps.items()): line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))
def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) dump_all = '# __dump_all__' in src if testcase.name.endswith('python2'): python_version = defaults.PYTHON2_VERSION else: python_version = defaults.PYTHON3_VERSION options = parse_options(src, testcase, incremental_step=1) options.use_builtins_fixtures = True options.show_traceback = True options.cache_dir = os.devnull options.python_version = python_version options.export_types = True options.preserve_asts = True messages, files, type_map = self.build(src, options) a = messages if files is None or type_map is None: if not a: a = [ 'Unknown compile error (likely syntax error in test case or fixture)' ] else: deps = defaultdict(set) # type: DefaultDict[str, Set[str]] for module in files: if module in dumped_modules or dump_all and module not in ( 'abc', 'typing', 'mypy_extensions', 'typing_extensions', 'enum'): new_deps = get_dependencies(files[module], type_map, python_version, options) for source in new_deps: deps[source].update(new_deps[source]) TypeState.add_all_protocol_deps(deps) for source, targets in sorted(deps.items()): if source.startswith(('<enum', '<typing', '<mypy')): # Remove noise. continue line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))
def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) dump_all = '# __dump_all__' in src if testcase.name.endswith('python2'): python_version = defaults.PYTHON2_VERSION else: python_version = defaults.PYTHON3_VERSION options = parse_options(src, testcase, incremental_step=1) options.use_builtins_fixtures = True options.show_traceback = True options.cache_dir = os.devnull options.python_version = python_version options.export_types = True messages, files, type_map = self.build(src, options) a = messages if files is None or type_map is None: if not a: a = ['Unknown compile error (likely syntax error in test case or fixture)'] else: deps = defaultdict(set) # type: DefaultDict[str, Set[str]] for module in files: if module in dumped_modules or dump_all and module not in ('abc', 'typing', 'mypy_extensions', 'typing_extensions', 'enum'): new_deps = get_dependencies(files[module], type_map, python_version, options) for source in new_deps: deps[source].update(new_deps[source]) TypeState.add_all_protocol_deps(deps) for source, targets in sorted(deps.items()): if source.startswith('<enum.'): # Remove noise. continue line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))
def update_dependencies(new_modules: Mapping[str, Optional[MypyFile]], deps: Dict[str, Set[str]], graph: Dict[str, State], options: Options) -> None: for id, node in new_modules.items(): if node is None: continue if '/typeshed/' in node.path: # We don't track changes to typeshed -- the assumption is that they are only changed # as part of mypy updates, which will invalidate everything anyway. # # TODO: Not a reliable test, as we could have a package named typeshed. # TODO: Consider relaxing this -- maybe allow some typeshed changes to be tracked. continue module_deps = get_dependencies(target=node, type_map=graph[id].type_map(), python_version=options.python_version) for trigger, targets in module_deps.items(): deps.setdefault(trigger, set()).update(targets)
def run_case(self, testcase: DataDrivenTestCase) -> None: src = '\n'.join(testcase.input) if testcase.name.endswith('python2'): python_version = defaults.PYTHON2_VERSION else: python_version = defaults.PYTHON3_VERSION messages, files, type_map = self.build(src, python_version) a = messages if files is None or type_map is None: if not a: a = ['Unknown compile error (likely syntax error in test case or fixture)'] else: deps = get_dependencies(files['__main__'], type_map, python_version) for source, targets in sorted(deps.items()): line = '%s -> %s' % (source, ', '.join(sorted(targets))) # Clean up output a bit line = line.replace('__main__', 'm') a.append(line) assert_string_arrays_equal( testcase.output, a, 'Invalid output ({}, line {})'.format(testcase.file, testcase.line))