77"""
88import os
99from dataclasses import dataclass
10- from typing import Dict , List , Union , Tuple
10+ from typing import Dict , List , Set , Union , Tuple
1111
1212import pytest
1313from ofrak .core .filesystem import File
@@ -37,9 +37,13 @@ class BasicBlockUnpackerTestCase(
3737 binary_filename : str
3838 binary_md5_digest : str
3939 basic_block_data_ranges_in_root : Dict [int , Range ] # Used when created basic blocks manually
40+ # Workaround for https://github.com/python/mypy/issues/12633, fixed in mypy 0.950.
41+ # Remove these two lines once using a newer mypy.
42+ expected_results : Dict [int , List [ExpectedBasicBlockUnpackResult ]]
43+ optional_results : Set [int ]
4044
4145
42- BASIC_BLOCK_UNPACKER_TEST_CASES = [
46+ BASIC_BLOCK_UNPACKER_TEST_CASES : List [ BasicBlockUnpackerTestCase ] = [
4347 BasicBlockUnpackerTestCase (
4448 "x64" ,
4549 {
@@ -1582,10 +1586,11 @@ async def unpack_verify_test_case(self, request) -> BasicBlockUnpackerTestCase:
15821586 @pytest .fixture
15831587 async def root_resource (
15841588 self ,
1585- unpack_verify_test_case : BasicBlockUnpackerTestCase ,
1589+ unpack_verify_test_case : UnpackAndVerifyTestCase ,
15861590 ofrak_context : OFRAKContext ,
15871591 test_id : str ,
15881592 ) -> Resource :
1593+ assert isinstance (unpack_verify_test_case , BasicBlockUnpackerTestCase )
15891594 asset_path = os .path .join (ASSETS_DIR , unpack_verify_test_case .binary_filename )
15901595 with open (asset_path , "rb" ) as f :
15911596 binary_data = f .read ()
@@ -1598,9 +1603,9 @@ async def verify_descendant(
15981603 instructions = await basic_block .get_instructions ()
15991604
16001605 # Check that the parent complex blocks are extracted as expected
1601- instructions_by_addr : Dict [int , ExpectedBasicBlockUnpackResult ] = dict ()
1606+ instructions_by_addr : Dict [int , Tuple [ Instruction , ...]] = {}
16021607 for expected_instructions in specified_result :
1603- if type (expected_instructions ) is tuple :
1608+ if isinstance (expected_instructions , tuple ) :
16041609 instructions_by_addr [
16051610 expected_instructions [0 ].virtual_address
16061611 ] = expected_instructions
@@ -1654,7 +1659,7 @@ async def verify_descendant(
16541659 if len (errors ) > 0 :
16551660 raise ValueError (* errors )
16561661
1657- async def get_descendants_to_verify (self , unpacked_resource : Resource ) -> Dict [int , Resource ]:
1662+ async def get_descendants_to_verify (self , unpacked_resource : Resource ) -> Dict [int , BasicBlock ]:
16581663 elf = await unpacked_resource .view_as (Elf )
16591664 text_section = await elf .get_section_by_name (".text" )
16601665 basic_blocks : List [BasicBlock ] = list (
0 commit comments