22
33from __future__ import annotations
44
5- import os
65import json
6+ import os
77import re
8- import pprint
98import sys
109
1110from mypy import build
1211from mypy .errors import CompileError
12+ from mypy .exportjson import convert_binary_cache_to_json
1313from mypy .modulefinder import BuildSource
1414from mypy .options import Options
1515from mypy .test .config import test_temp_dir
1616from mypy .test .data import DataDrivenTestCase , DataSuite
1717from mypy .test .helpers import assert_string_arrays_equal
18- from mypy .exportjson import convert_binary_cache_to_json
1918
2019
2120class TypeExportSuite (DataSuite ):
2221 required_out_section = True
2322 files = ["exportjson.test" ]
2423
2524 def run_case (self , testcase : DataDrivenTestCase ) -> None :
25+ error = False
26+ src = "\n " .join (testcase .input )
2627 try :
27- src = "\n " .join (testcase .input )
2828 options = Options ()
2929 options .use_builtins_fixtures = True
3030 options .show_traceback = True
@@ -34,17 +34,23 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3434 with open (fnam , "w" ) as f :
3535 f .write (src )
3636 result = build .build (
37- sources = [BuildSource (fnam , "main" )],
38- options = options ,
39- alt_lib_path = test_temp_dir ,
37+ sources = [BuildSource (fnam , "main" )], options = options , alt_lib_path = test_temp_dir
4038 )
4139 a = result .errors
40+ error = bool (a )
4241
4342 major , minor = sys .version_info [:2 ]
4443 cache_dir = os .path .join (".mypy_cache" , f"{ major } .{ minor } " )
4544
4645 for module in result .files :
47- if module in ("builtins" , "typing" , "_typeshed" ):
46+ if module in (
47+ "builtins" ,
48+ "typing" ,
49+ "_typeshed" ,
50+ "__future__" ,
51+ "typing_extensions" ,
52+ "sys" ,
53+ ):
4854 continue
4955 fnam = os .path .join (cache_dir , f"{ module } .data.ff" )
5056 with open (fnam , "rb" ) as f :
@@ -54,11 +60,10 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
5460 # We source file path is unpredictable, so filter it out
5561 line = re .sub (r'"[^"]+\.pyi?"' , "..." , line )
5662 a .append (line )
57- print (fnam )
5863 except CompileError as e :
5964 a = e .messages
60- assert_string_arrays_equal (
61- testcase .output ,
62- a ,
63- f"Invalid output ({ testcase .file } , line { testcase .line } )" ,
64- )
65+ error = True
66+ if error or " \n " . join ( testcase .output ). strip () != "<not checked>" :
67+ assert_string_arrays_equal (
68+ testcase . output , a , f"Invalid output ({ testcase .file } , line { testcase .line } )"
69+ )
0 commit comments