@@ -234,7 +234,7 @@ def format_reachable_imports(node: MypyFile) -> list[str]:
234234
235235@unittest .skipUnless (has_nativeparse , "nativeparse not available" )
236236class TestNativeParserBinaryFormat (unittest .TestCase ):
237- def test_trivial_binary_data (self ) -> None :
237+ def _assert_trivial_binary_data (self , b : bytes , / ) -> None :
238238 # A quick sanity check to ensure the serialized data looks as expected. Only covers
239239 # a few AST nodes.
240240
@@ -250,9 +250,9 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) ->
250250 int_enc (end_column - start_column ),
251251 ]
252252
253- with temp_source ( "print('hello')" ) as fnam :
254- b , _ , _ , _ , _ , _ , _ , _ = parse_to_binary_ast ( fnam , Options ())
255- assert list ( b ) == (
253+ self . assertEqual (
254+ list ( b ),
255+ (
256256 [LITERAL_INT , 22 , nodes .EXPR_STMT , nodes .CALL_EXPR ]
257257 + [nodes .NAME_EXPR , LITERAL_STR ]
258258 + [int_enc (5 )]
@@ -269,7 +269,21 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) ->
269269 + [LIST_GEN , 22 , LITERAL_NONE ]
270270 + locs (1 , 0 , 1 , 14 )
271271 + [END_TAG , END_TAG ]
272- )
272+ ),
273+ )
274+
275+ def test_trivial_binary_data_from_file (self ) -> None :
276+ with temp_source ("print('hello')" ) as fnam :
277+ b , _ , _ , _ , _ , _ , _ , _ = parse_to_binary_ast (fnam , Options ())
278+ self ._assert_trivial_binary_data (b )
279+
280+ def test_trivial_binary_data_from_string_source (self ) -> None :
281+ b , _ , _ , _ , _ , _ , _ , _ = parse_to_binary_ast ("" , Options (), "print('hello')" )
282+ self ._assert_trivial_binary_data (b )
283+
284+ def test_trivial_binary_data_from_bytes_source (self ) -> None :
285+ b , _ , _ , _ , _ , _ , _ , _ = parse_to_binary_ast ("" , Options (), b"print('hello')" )
286+ self ._assert_trivial_binary_data (b )
273287
274288
275289@contextlib .contextmanager
0 commit comments