summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-07-01 19:22:17 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-07-01 19:22:17 (GMT)
commitbfd453d597d23b5c782aa8d40eb744d2ab56838e (patch)
treeb285ada70fcb80b367542ec876716b2aa33ebc5c /tests
parent2f1a1323b4b6c5d4ff84a6d4d335e0cf56c5c8fa (diff)
Introduced attributes for loaded contents.
Diffstat (limited to 'tests')
-rw-r--r--tests/analysis/cattribs.py142
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/analysis/cattribs.py b/tests/analysis/cattribs.py
new file mode 100644
index 0000000..1a7f7da
--- /dev/null
+++ b/tests/analysis/cattribs.py
@@ -0,0 +1,142 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+
+# S'assure du bon fonctionnement des attributs de contenus binaires à charger
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.analysis import ContentAttributes
+
+
+class TestProjectFeatures(ChrysalideTestCase):
+ """TestCase for binary content attributes."""
+
+ def testEmptyContentAttributeSet(self):
+ """Check properties of empty content attribute set."""
+
+ attribs = ContentAttributes('')
+ self.assertIsNotNone(attribs)
+
+ self.assertIsNone(attribs.filename)
+
+ self.assertEqual(len(attribs.keys), 0)
+
+
+ def testContentAttributeSet(self):
+ """Check properties of a basic content attribute set."""
+
+ model = {
+ 'a': '0',
+ 'bb': '1',
+ 'ccc': '2',
+ 'dddd': '3',
+ }
+
+ filename = 'filename'
+ path = filename
+
+ for k in model.keys():
+ path += '&%s=%s' % (k, model[k])
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ self.assertEqual(attribs.filename, filename)
+
+ kcount = 0
+
+ for key in attribs.keys:
+ self.assertTrue(key in model.keys())
+ kcount += 1
+
+ self.assertEqual(kcount, len(model.keys()))
+
+
+ def testMultiContentAttributeSet(self):
+ """Check properties of a multi level content attribute set."""
+
+ model = {
+ 'a': '0',
+ 'bb': '1',
+ 'ccc': '2',
+ 'dddd': '3',
+ }
+
+ path = ''
+
+ for k in model.keys():
+ path += '&%s=%s' % (k, model[k])
+
+ path += '&'
+
+ for k in model.keys():
+ path += '&e%s=%s' % (k, model[k])
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ self.assertIsNone(attribs.filename)
+
+ kcount = 0
+
+ for key in attribs.keys:
+ self.assertTrue(key in model.keys())
+ kcount += 1
+
+ self.assertEqual(kcount, len(model.keys()))
+
+
+ def testEmptyContentAttributeSet(self):
+ """Check properties of empty content attribute sets."""
+
+ path = '&&'
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ self.assertIsNone(attribs.filename)
+
+ self.assertEqual(len(attribs.keys), 0)
+
+ path = '&&&'
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ self.assertIsNone(attribs.filename)
+
+ self.assertEqual(len(attribs.keys), 0)
+
+ path = 'filename'
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ self.assertEqual(len(attribs.keys), 0)
+
+ self.assertEqual(attribs.filename, path)
+
+
+ def testContentAttributesKeyAccess(self):
+ """Test some access keys for content attributes."""
+
+ model = {
+ 'a': '0',
+ }
+
+ path = ''
+
+ for k in model.keys():
+ path += '&%s=%s' % (k, model[k])
+
+ attribs = ContentAttributes(path)
+ self.assertIsNotNone(attribs)
+
+ with self.assertRaisesRegex(Exception, 'key must be a string value'):
+
+ val = attribs[2]
+
+ with self.assertRaisesRegex(Exception, 'attribute value not found for the provided key'):
+
+ val = attribs['2']