Ejemplo n.º 1
0
 def test_extract_file(self, patch_os, patch_open):
     dat_file = MagicMock()
     out_file_path = 'dst/path/filename'
     offset = 123
     size = 456
     CatParser.extract_file(dat_file, out_file_path, offset, size)
     patch_os.makedirs.assert_called_once_with('dst/path', exist_ok=True)
     dat_file.seek.assert_called_once_with(offset)
     dat_file.read.assert_called_once_with(size)
     patch_open.assert_called_once_with(out_file_path, 'wb')
     patch_open.return_value.__enter__.return_value.write.assert_called_once_with(
         dat_file.read.return_value)
Ejemplo n.º 2
0
 def test_extract_scripts(self, patch_open):
     parser = CatParser(out_path='some/out/path')
     parser.cat_files_iterator = MagicMock(return_value=self.CAT_FILES)
     parser.extract_file = MagicMock()
     parser.extract(cat_filename='path/to/catfile.cat')
     parser.cat_files_iterator.assert_called_once_with(
         'path/to/catfile.cat')
     patch_open.assert_called_once_with('path/to/catfile.dat', 'rb')
     parser.extract_file.assert_called_once_with(
         patch_open.return_value.__enter__.return_value,
         'some/out/path/some path/filename1.xml', 0, 101)
Ejemplo n.º 3
0
 def test_extract_all_no_sig(self, patch_open):
     parser = CatParser(out_path='some/out/path', scripts_only=False)
     parser.cat_files_iterator = MagicMock(return_value=self.CAT_FILES)
     parser.extract_file = MagicMock()
     parser.extract(cat_filename='path/to/catfile.cat')
     parser.cat_files_iterator.assert_called_once_with(
         'path/to/catfile.cat')
     patch_open.assert_called_once_with('path/to/catfile.dat', 'rb')
     self.assertEqual(parser.extract_file.call_count, 2)
     parser.extract_file.assert_has_calls([
         call(patch_open.return_value.__enter__.return_value,
              'some/out/path/some path/filename1.xml', 0, 101),
         call(patch_open.return_value.__enter__.return_value,
              'some/out/path/some path/filename2.xmf', 311, 300),
     ])