(self, testcase: DataDrivenTestCase)
| 856 | self.run_case_inner(testcase) |
| 857 | |
| 858 | def run_case_inner(self, testcase: DataDrivenTestCase) -> None: |
| 859 | extra = [] # Extra command-line args |
| 860 | mods = [] # Module names to process |
| 861 | source = "\n".join(testcase.input) |
| 862 | for file, content in testcase.files + [("./main.py", source)]: |
| 863 | # Strip ./ prefix and .py suffix. |
| 864 | mod = file[2:-3].replace("/", ".") |
| 865 | if mod.endswith(".__init__"): |
| 866 | mod, _, _ = mod.rpartition(".") |
| 867 | mods.append(mod) |
| 868 | if "-p " not in source: |
| 869 | extra.extend(["-m", mod]) |
| 870 | with open(file, "w") as f: |
| 871 | f.write(content) |
| 872 | |
| 873 | options = self.parse_flags(source, extra) |
| 874 | if sys.version_info < options.pyversion: |
| 875 | pytest.skip() |
| 876 | modules = self.parse_modules(source) |
| 877 | out_dir = "out" |
| 878 | try: |
| 879 | try: |
| 880 | if testcase.name.endswith("_inspect"): |
| 881 | options.inspect = True |
| 882 | else: |
| 883 | if not testcase.name.endswith("_import"): |
| 884 | options.no_import = True |
| 885 | if not testcase.name.endswith("_semanal"): |
| 886 | options.parse_only = True |
| 887 | |
| 888 | generate_stubs(options) |
| 889 | a: list[str] = [] |
| 890 | for module in modules: |
| 891 | fnam = module_to_path(out_dir, module) |
| 892 | self.add_file(fnam, a, header=len(modules) > 1) |
| 893 | except CompileError as e: |
| 894 | a = e.messages |
| 895 | assert_string_arrays_equal( |
| 896 | testcase.output, a, f"Invalid output ({testcase.file}, line {testcase.line})" |
| 897 | ) |
| 898 | finally: |
| 899 | for mod in mods: |
| 900 | if mod in sys.modules: |
| 901 | del sys.modules[mod] |
| 902 | shutil.rmtree(out_dir) |
| 903 | |
| 904 | def parse_flags(self, program_text: str, extra: list[str]) -> Options: |
| 905 | flags = re.search("# flags: (.*)$", program_text, flags=re.MULTILINE) |
no test coverage detected