def test_with_rebased_files_returns_same_args_when_there_are_no_files(
         self):
     args = UnpackerArguments()
     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_clone_returns_other_args_equal_to_original_args(self):
     args = UnpackerArguments(
         input_files=(StandaloneFile('file.exe'), ),
         output_file=StandaloneFile('file.exe-unpacked'),
         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 = UnpackerArguments(
         input_files=(StandaloneFile('file.exe'), ),
         output_file=StandaloneFile('file.exe-unpacked'))
     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.output_file.path,
         os.path.join(ROOT_DIR, 'outputs', 'file.exe-unpacked'))
    def test_create_log_returns_combined_log_when_fileinfo_run(self):
        self.test_settings.run_fileinfo = True
        self.test_settings.fileinfo_timeout = 60
        unpacker = mock.Mock()
        unpacker.name = 'unpacker'
        unpacker.output = 'unpacker output\n'
        unpacker.timeouted = False
        unpacker.return_code = 0
        unpacker.args = UnpackerArguments(args='--unpacker-arg')
        unpacker.fileinfo = mock.Mock()
        unpacker.fileinfo.name = 'fileinfo'
        unpacker.fileinfo.output = 'fileinfo output\n'
        unpacker.fileinfo.timeouted = True
        unpacker.fileinfo.return_code = 1
        unpacker.fileinfo.args = FileinfoArguments(args='--fileinfo-arg')

        log = self.unpacker_runner._create_log(unpacker, timeout=100)

        expected_log = '\n'.join([
            '# Command: unpacker --unpacker-arg', '# Timeout: 100 seconds', '',
            'unpacker output', '', '# Return code: 0', '# Timeouted:   no', '',
            '# ------------------------------------------------------------------------------',
            '', '# Command: fileinfo --fileinfo-arg', '# Timeout: 60 seconds',
            '', 'fileinfo output', '', '# Return code: 1',
            '# Timeouted:   yes', ''
        ])

        self.assertEqual(log, expected_log)
 def setUp(self):
     super().setUp()
     self.name = 'unpacker'
     self.args = UnpackerArguments(
         input_files=(File('prog.exe', Directory('/test')), ),
         output_file=File('prog.exe-unpacked', Directory('/test/outputs')))
     self.unpacker = self.create_unpacker()
 def test_without_paths_and_output_files_returns_correct_args_when_there_are_files(
         self):
     args = UnpackerArguments(
         input_files=(File('file.exe',
                           Directory(os.path.join(ROOT_DIR, 'inputs'))), ),
         output_file=File('file.exe-unpacked',
                          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.assertIsNone(stripped_args.output_file)
    def test_create_log_returns_just_unpacker_log_when_fileinfo_did_not_run(
            self):
        self.test_settings.run_fileinfo = False
        unpacker = mock.Mock()
        unpacker.name = 'unpacker'
        unpacker.output = 'unpacker output\n'
        unpacker.timeouted = False
        unpacker.return_code = 0
        unpacker.args = UnpackerArguments(args='--unpacker-arg')

        log = self.unpacker_runner._create_log(unpacker, timeout=100)

        expected_log = '\n'.join([
            '# Command: unpacker --unpacker-arg', '# Timeout: 100 seconds', '',
            'unpacker output', '', '# Return code: 0', '# Timeouted:   no', ''
        ])

        self.assertEqual(log, expected_log)
 def test_two_args_having_same_data_are_equal(self):
     args1 = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ),
                               args='--arg')
     args2 = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ),
                               args='--arg')
     self.assertEqual(args1, args2)
 def test_without_paths_and_output_files_returns_same_args_when_there_are_no_files(
         self):
     args = UnpackerArguments()
     self.assertEqual(args, args.without_paths_and_output_files)
 def scenario_invalid_settings_error_is_raised(self, test_settings,
                                               ref_exc_substr):
     with self.assertRaises(InvalidTestSettingsError) as cm:
         UnpackerArguments.from_test_settings(test_settings)
     self.assertIn(ref_exc_substr, str(cm.exception))
 def test_from_test_settings_args_is_present_when_set(self):
     test_settings = UnpackerTestSettings(input='test.exe',
                                          args='--arg1 --arg2')
     args = UnpackerArguments.from_test_settings(test_settings)
     self.assertEqual(args.args, test_settings.args)
 def test_two_args_having_different_args_are_not_equal(self):
     args1 = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ),
                               args='--arg')
     args2 = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ),
                               args='--other-arg')
     self.assertNotEqual(args1, args2)
 def test_from_test_settings_input_files_are_present_when_set(self):
     test_settings = UnpackerTestSettings(input='test.exe')
     args = UnpackerArguments.from_test_settings(test_settings)
     self.assertEqual(len(args.input_files), 1)
     self.assertEqual(args.input_files[0].name, test_settings.input)
 def test_two_args_having_different_input_files_are_not_equal(self):
     args1 = UnpackerArguments(input_files=(StandaloneFile('file1.exe'), ))
     args2 = UnpackerArguments(input_files=(StandaloneFile('file2.exe'), ))
     self.assertNotEqual(args1, args2)
 def test_as_list_returns_correct_list_when_output_file_is_set(self):
     args = UnpackerArguments(
         input_files=(StandaloneFile('file.exe'), ),
         output_file=StandaloneFile('file.exe-unpacked'))
     self.assertEqual(args.as_list, ['file.exe', '-o', 'file.exe-unpacked'])
 def test_as_list_returns_correct_list_when_just_input_files_are_set(self):
     args = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ))
     self.assertEqual(args.as_list, ['file.exe'])
 def test_as_list_returns_empty_list_when_nothing_is_set(self):
     args = UnpackerArguments()
     self.assertEqual(args.as_list, [])
 def test_input_file_returns_file_with_correct_name(self):
     args = UnpackerArguments(input_files=(StandaloneFile('file.exe'), ))
     self.assertEqual(args.input_file.name, 'file.exe')
 def test_repr_returns_executable_repr_that_creates_original_args(self):
     args = UnpackerArguments(
         input_files=(StandaloneFile('file.exe'), ),
         output_file=StandaloneFile('file.exe-unpacked'),
         args='--arg')
     self.assertEqual(args, eval(repr(args)))
 def test_from_test_settings_output_file_is_automatically_set(self):
     test_settings = UnpackerTestSettings(input='test.exe')
     args = UnpackerArguments.from_test_settings(test_settings)
     self.assertEqual(args.output_file.name, 'test.exe-unpacked')
 def test_as_list_returns_correct_list_when_just_args_is_set(self):
     args = UnpackerArguments(args='  --arg1   --arg2  ')
     self.assertEqual(args.as_list, ['--arg1', '--arg2'])
 def test_two_args_having_different_output_file_are_not_equal(self):
     args1 = UnpackerArguments(
         output_file=StandaloneFile('file1.exe-unpacked'))
     args2 = UnpackerArguments(
         output_file=StandaloneFile('file2.exe-unpacked'))
     self.assertNotEqual(args1, args2)