diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2025-03-07 09:29:32 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2025-03-10 06:27:26 (GMT) |
commit | a59fb1b3fb67a348c40bc3668445d64213e9e674 (patch) | |
tree | fcf493a6b1758c666b95a9c1c645beecc8e42a14 /tests/analysis | |
parent | e0614e482b3ca3faf43e296bb70348be0d651394 (diff) |
Prepare a new way to store objects.
Diffstat (limited to 'tests/analysis')
-rw-r--r-- | tests/analysis/storage/storage.py | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/tests/analysis/storage/storage.py b/tests/analysis/storage/storage.py deleted file mode 100644 index 612d500..0000000 --- a/tests/analysis/storage/storage.py +++ /dev/null @@ -1,81 +0,0 @@ - -from chrysacase import ChrysalideTestCase -from pychrysalide import core -from pychrysalide.analysis.contents import FileContent -from pychrysalide.analysis.storage import ObjectStorage -from pychrysalide.common import PackedBuffer -import os -import shutil -import tempfile - - -class TestObjectStorage(ChrysalideTestCase): - """TestCase for analysis.storage.""" - - @classmethod - def setUpClass(cls): - - super(TestObjectStorage, cls).setUpClass() - - cls._tmp_path = tempfile.mkdtemp() - - config = core.get_main_configuration() - param = config.search(core.MainParameterKeys.TMPDIR) - - cls._old_tmpdir = param.value - param.value = cls._tmp_path - - cls.log('Using temporary directory "%s"' % cls._tmp_path) - - - @classmethod - def tearDownClass(cls): - - super(TestObjectStorage, cls).tearDownClass() - - config = core.get_main_configuration() - param = config.search(core.MainParameterKeys.TMPDIR) - - param.value = cls._old_tmpdir - - # import os - # os.system('ls -laihR %s' % cls._tmp_path) - - cls.log('Delete directory "%s"' % cls._tmp_path) - - shutil.rmtree(cls._tmp_path) - - - def testFileContentStorage(self): - """Store and load file binary content.""" - - storage = ObjectStorage('my-storage-hash') - self.assertIsNotNone(storage) - - filename = os.path.join(self._tmp_path, 'test.bin') - - with open(filename, 'wb') as fd: - fd.write(b'ABC') - - cnt = FileContent(filename) - self.assertIsNotNone(cnt) - - ret = storage.store_object('contents', cnt) - self.assertEqual(ret, 0) - - pbuf = PackedBuffer() - - ret = storage.store(pbuf) - self.assertTrue(ret) - - self.assertTrue(pbuf.payload_length > 0) - - pbuf.rewind() - - storage2 = ObjectStorage.load(pbuf) - self.assertIsNotNone(storage2) - - cnt2 = storage2.load_object('contents', 0) - self.assertIsNotNone(cnt2) - - self.assertEqual(cnt.data, cnt2.data) |