def test_two_args_having_same_data_are_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), pdb_file=StandaloneFile('file.pdb'), config_file=StandaloneFile('file.json'), static_code_archive=StandaloneFile('file.a'), static_code_sigfile=StandaloneFile('file.sig'), arch='x86', mode='bin', hll='c', ar_index=0, ar_name='file.o', args='--arg' ) args2 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), pdb_file=StandaloneFile('file.pdb'), config_file=StandaloneFile('file.json'), static_code_archive=StandaloneFile('file.a'), static_code_sigfile=StandaloneFile('file.sig'), arch='x86', mode='bin', hll='c', ar_index=0, ar_name='file.o', args='--arg' ) self.assertEqual(args1, args2)
def test_two_args_having_different_input_files_are_not_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('file1.exe'),) ) args2 = DecompilerArguments( input_files=(StandaloneFile('file2.exe'),) ) self.assertNotEqual(args1, args2)
def test_two_args_having_different_static_code_sigfiles_are_not_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), static_code_sigfile=StandaloneFile('file1.sig') ) args2 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), static_code_sigfile=StandaloneFile('file2.sig') ) self.assertNotEqual(args1, args2)
def test_two_args_having_different_ar_names_are_not_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('archive.a'),), ar_name='file1.o' ) args2 = DecompilerArguments( input_files=(StandaloneFile('archive.a'),), ar_name='file2.o' ) self.assertNotEqual(args1, args2)
def test_two_args_having_different_args_are_not_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), args='--arg' ) args2 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), args='--other-arg' ) self.assertNotEqual(args1, args2)
def test_two_args_having_different_modes_are_not_equal(self): args1 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), mode='bin' ) args2 = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), mode='raw' ) self.assertNotEqual(args1, args2)
def test_with_rebased_files_returns_same_args_when_there_are_no_files(self): args = DecompilerArguments() rebased_args = args.with_rebased_files( Directory(os.path.join(ROOT_DIR, 'inputs')), Directory(os.path.join(ROOT_DIR, 'outputs')) ) self.assertEqual(args, rebased_args)
def test_initialize_tool_dir_and_args_just_returns_args_when_config_file_is_not_set( self): input_dir = mock.Mock() tool_dir = mock.Mock() args = DecompilerArguments(input_files=(File('file.exe', input_dir), )) new_args = self.decomp_runner._initialize_tool_dir_and_args( tool_dir, args) self.assertIs(new_args, args)
def test_initialize_tool_dir_and_args_copies_config_file_when_it_is_set( self): input_dir = mock.Mock() tool_dir = mock.Mock() tool_dir.copy_file.return_value = File('file.json', tool_dir) args = DecompilerArguments(input_files=(File('file.exe', input_dir), ), config_file=File('file.json', input_dir)) new_args = self.decomp_runner._initialize_tool_dir_and_args( tool_dir, args) tool_dir.copy_file.assert_called_once_with(args.config_file) self.assertEqual(new_args.config_file.dir, tool_dir)
def test_repr_returns_executable_repr_that_creates_original_args(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), pdb_file=StandaloneFile('file.pdb'), config_file=StandaloneFile('file.json'), static_code_archive=StandaloneFile('file.a'), static_code_sigfile=StandaloneFile('file.sig'), arch='x86', mode='bin', hll='c', ar_index=0, ar_name='file.o', args='--arg' ) self.assertEqual(args, eval(repr(args)))
def test_without_paths_and_output_files_returns_correct_args_when_there_are_files(self): args = DecompilerArguments( input_files=(File('file.exe', Directory(os.path.join(ROOT_DIR, 'inputs'))),), pdb_file=File('file.pdb', Directory(os.path.join(ROOT_DIR, 'inputs'))), config_file=File('file.json', Directory(os.path.join(ROOT_DIR, 'inputs'))), static_code_archive=File('file.a', Directory(os.path.join(ROOT_DIR, 'inputs'))), static_code_sigfile=File('file.sig', Directory(os.path.join(ROOT_DIR, 'inputs'))), output_file=File('file.c', Directory(os.path.join(ROOT_DIR, 'outputs'))) ) stripped_args = args.without_paths_and_output_files self.assertEqual(len(stripped_args.input_files), 1) self.assertEqual(stripped_args.input_files[0].path, 'file.exe') self.assertEqual(stripped_args.pdb_file.path, 'file.pdb') self.assertEqual(stripped_args.config_file.path, 'file.json') self.assertEqual(stripped_args.static_code_archive.path, 'file.a') self.assertEqual(stripped_args.static_code_sigfile.path, 'file.sig') self.assertIsNone(stripped_args.output_file)
def test_clone_returns_other_args_equal_to_original_args(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), pdb_file=StandaloneFile('file.pdb'), config_file=StandaloneFile('file.json'), static_code_archive=StandaloneFile('file.a'), static_code_sigfile=StandaloneFile('file.sig'), arch='x86', mode='bin', hll='c', ar_index=0, ar_name='file.o', args='--arg' ) cloned_args = args.clone() self.assertIsNot(args, cloned_args) self.assertEqual(args, cloned_args)
def test_with_rebased_files_returns_correct_args_when_there_are_files(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), pdb_file=StandaloneFile('file.pdb'), config_file=StandaloneFile('file.json'), static_code_archive=StandaloneFile('file.a'), static_code_sigfile=StandaloneFile('file.sig'), output_file=StandaloneFile('file.c') ) rebased_args = args.with_rebased_files( Directory(os.path.join(ROOT_DIR, 'inputs')), Directory(os.path.join(ROOT_DIR, 'outputs')) ) self.assertEqual(len(rebased_args.input_files), 1) self.assertEqual( rebased_args.input_files[0].path, os.path.join(ROOT_DIR, 'inputs', 'file.exe') ) self.assertEqual( rebased_args.pdb_file.path, os.path.join(ROOT_DIR, 'inputs', 'file.pdb') ) self.assertEqual( rebased_args.config_file.path, os.path.join(ROOT_DIR, 'inputs', 'file.json') ) self.assertEqual( rebased_args.static_code_archive.path, os.path.join(ROOT_DIR, 'inputs', 'file.a') ) self.assertEqual( rebased_args.static_code_sigfile.path, os.path.join(ROOT_DIR, 'inputs', 'file.sig') ) self.assertEqual( rebased_args.output_file.path, os.path.join(ROOT_DIR, 'outputs', 'file.c') )
def test_as_list_returns_correct_list_when_just_args_is_set(self): args = DecompilerArguments( args=' --arg1 --arg2 ' ) self.assertEqual(args.as_list, ['--arg1', '--arg2'])
def test_as_list_returns_correct_list_when_just_ar_name_is_set(self): args = DecompilerArguments( ar_name='file.o', ) self.assertEqual(args.as_list, ['--ar-name', 'file.o'])
def test_as_list_returns_correct_list_when_just_ar_index_is_set_as_str(self): args = DecompilerArguments( ar_index='0', ) self.assertEqual(args.as_list, ['--ar-index', '0'])
def test_as_list_returns_correct_list_when_just_hll_is_set(self): args = DecompilerArguments( hll='py' ) self.assertEqual(args.as_list, ['-l', 'py'])
def test_as_list_returns_correct_list_when_just_mode_is_set(self): args = DecompilerArguments( mode='bin' ) self.assertEqual(args.as_list, ['-m', 'bin'])
def test_as_list_returns_correct_list_when_just_arch_is_set(self): args = DecompilerArguments( arch='x86' ) self.assertEqual(args.as_list, ['-a', 'x86'])
def test_as_list_returns_correct_list_when_static_code_sigfile_is_set(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), static_code_sigfile=StandaloneFile('file.sig') ) self.assertEqual(args.as_list, ['file.exe', '--static-code-sigfile', 'file.sig'])
def test_as_list_returns_correct_list_when_just_input_files_are_set(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),) ) self.assertEqual(args.as_list, ['file.exe'])
def test_without_paths_and_output_files_returns_same_args_when_there_are_no_files(self): args = DecompilerArguments() self.assertEqual(args, args.without_paths_and_output_files)
def test_input_file_returns_file_with_correct_name(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),) ) self.assertEqual(args.input_file.name, 'file.exe')
def test_clone_but_preserves_instance_type(self): args = DecompilerArguments() cloned_args = args.clone_but() self.assertIsInstance(cloned_args, DecompilerArguments)
def test_as_list_returns_empty_list_when_nothing_is_set(self): args = DecompilerArguments() self.assertEqual(args.as_list, [])
def test_as_list_returns_correct_list_when_config_file_is_set(self): args = DecompilerArguments( input_files=(StandaloneFile('file.exe'),), config_file=StandaloneFile('file.json') ) self.assertEqual(args.as_list, ['file.exe', '--config', 'file.json'])
def test_as_list_returns_correct_list_when_just_output_is_set(self): args = DecompilerArguments( output_file=StandaloneFile('file.out.exe') ) self.assertEqual(args.as_list, ['-o', 'file.out.exe'])