@@ -212,7 +212,7 @@ def format_reachable_imports(node: MypyFile) -> list[str]:
212212
213213@unittest .skipUnless (has_nativeparse , "nativeparse not available" )
214214class TestNativeParserBinaryFormat (unittest .TestCase ):
215- def test_trivial_binary_data (self ) -> None :
215+ def _assert_trivial_binary_data (self , b : bytes ) -> None :
216216 # A quick sanity check to ensure the serialized data looks as expected. Only covers
217217 # a few AST nodes.
218218
@@ -228,9 +228,9 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) ->
228228 int_enc (end_column - start_column ),
229229 ]
230230
231- with temp_source ( "print('hello')" ) as fnam :
232- b , _ , _ , _ , _ , _ = parse_to_binary_ast ( fnam , Options ())
233- assert list ( b ) == (
231+ self . assertEqual (
232+ list ( b ),
233+ (
234234 [LITERAL_INT , 22 , nodes .EXPR_STMT , nodes .CALL_EXPR ]
235235 + [nodes .NAME_EXPR , LITERAL_STR ]
236236 + [int_enc (5 )]
@@ -247,7 +247,21 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) ->
247247 + [LIST_GEN , 22 , LITERAL_NONE ]
248248 + locs (1 , 0 , 1 , 14 )
249249 + [END_TAG , END_TAG ]
250- )
250+ ),
251+ )
252+
253+ def test_trivial_binary_data_from_file (self ) -> None :
254+ with temp_source ("print('hello')" ) as fnam :
255+ b , _ , _ , _ , _ , _ = parse_to_binary_ast (fnam , Options ())
256+ self ._assert_trivial_binary_data (b )
257+
258+ def test_trivial_binary_data_from_string_source (self ) -> None :
259+ b , _ , _ , _ , _ , _ = parse_to_binary_ast ("" , Options (), "print('hello')" )
260+ self ._assert_trivial_binary_data (b )
261+
262+ def test_trivial_binary_data_from_bytes_source (self ) -> None :
263+ b , _ , _ , _ , _ , _ = parse_to_binary_ast ("" , Options (), b"print('hello')" )
264+ self ._assert_trivial_binary_data (b )
251265
252266
253267@contextlib .contextmanager
0 commit comments