aboutsummaryrefslogtreecommitdiffstats
path: root/test/extractor
diff options
context:
space:
mode:
Diffstat (limited to 'test/extractor')
-rw-r--r--test/extractor/image/test_iptc.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/extractor/image/test_iptc.py b/test/extractor/image/test_iptc.py
new file mode 100644
index 0000000..5fa763d
--- /dev/null
+++ b/test/extractor/image/test_iptc.py
@@ -0,0 +1,69 @@
+
+# standard imports
+import unittest
+
+# bsie imports
+from bsie.extractor import base
+from bsie.utils import bsfs, node as _node, ns
+
+# objects to test
+from bsie.extractor.image.iptc import Iptc
+
+
+## code ##
+
+class TestIptc(unittest.TestCase):
+
+ def test_eq(self):
+ # identical instances are equal
+ self.assertEqual(Iptc(), Iptc())
+ self.assertEqual(hash(Iptc()), hash(Iptc()))
+ # comparison respects type
+ class Foo(): pass
+ self.assertNotEqual(Iptc(), Foo())
+ self.assertNotEqual(hash(Iptc()), hash(Foo()))
+ self.assertNotEqual(Iptc(), 1234)
+ self.assertNotEqual(hash(Iptc()), hash(1234))
+ self.assertNotEqual(Iptc(), None)
+ self.assertNotEqual(hash(Iptc()), hash(None))
+
+ def test_schema(self):
+ self.assertSetEqual({pred.uri for pred in Iptc().schema.predicates()}, {
+ ns.bsfs.Predicate,
+ ns.bse.tag,
+ ns.bst.label,
+ })
+
+ def test_extract(self):
+ ext = Iptc()
+ node = _node.Node(ns.bsfs.File, '') # Blank node
+ content = {
+ 'Iptc.Application2.Keywords': ['hello', 'world'],
+ 'Iptc.Application2.RecordVersion': '4',
+ }
+ # target tags
+ t_hello = _node.Node(ns.bsn.Tag, label='hello')
+ t_world = _node.Node(ns.bsn.Tag, label='world')
+
+ # invalid principals are ignored
+ self.assertSetEqual(set(ext.extract(node, content, {ns.bse.filename})), set())
+ # extract finds all relevant information
+ self.assertSetEqual(set(ext.extract(node, content, {ext.schema.predicate(ns.bse.tag)})), {
+ (node, ext.schema.predicate(ns.bse.tag), t_hello),
+ (node, ext.schema.predicate(ns.bse.tag), t_world),
+ (t_hello, ext.schema.predicate(ns.bst.label), 'hello'),
+ (t_world, ext.schema.predicate(ns.bst.label), 'world'),
+ })
+
+ # empty content is acceptable
+ self.assertSetEqual(set(ext.extract(node, {}, set(ext.principals))), set())
+ # no principals is acceptable
+ self.assertSetEqual(set(ext.extract(node, content, set())), set())
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##