aboutsummaryrefslogtreecommitdiffstats
path: root/test/extractor
diff options
context:
space:
mode:
Diffstat (limited to 'test/extractor')
-rw-r--r--test/extractor/image/__init__.py0
-rw-r--r--test/extractor/image/test_colors_spatial.py95
-rw-r--r--test/extractor/image/testimage.jpgbin0 -> 349264 bytes
3 files changed, 95 insertions, 0 deletions
diff --git a/test/extractor/image/__init__.py b/test/extractor/image/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/extractor/image/__init__.py
diff --git a/test/extractor/image/test_colors_spatial.py b/test/extractor/image/test_colors_spatial.py
new file mode 100644
index 0000000..b704e3f
--- /dev/null
+++ b/test/extractor/image/test_colors_spatial.py
@@ -0,0 +1,95 @@
+"""
+
+Part of the bsie test suite.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# standard imports
+import os
+import unittest
+
+# external imports
+import PIL.Image
+
+# bsie imports
+from bsie.extractor import base
+from bsie.utils import bsfs, ns, node as _node
+
+# objects to test
+from bsie.extractor.image.colors_spatial import ColorsSpatial
+
+
+## code ##
+
+class TestColorsSpatial(unittest.TestCase):
+ def setUp(self):
+ # content id with default constructors (width=32, height=32, exp=4)
+ self.instance_prefix = 'http://ie.bsfs.ai/schema/Feature/ColorsSpatial'
+ self.predicate_prefix = 'http://bsfs.ai/schema/Entity/colors_spatial'
+ self.uuid = 'adee8d6c43687021e1c5bffe56bcfe727f1638d792744137181304ef889dac2a'
+
+ def test_essentials(self):
+ # clones are equal
+ self.assertEqual(ColorsSpatial(32, 32, 4), ColorsSpatial(32, 32, 4))
+ self.assertEqual(hash(ColorsSpatial(32, 32, 4)), hash(ColorsSpatial(32, 32, 4)))
+ # equal respects type
+ self.assertNotEqual(ColorsSpatial(32, 32, 4), 'hello world')
+ self.assertNotEqual(hash(ColorsSpatial(32, 32, 4)), hash('hello world'))
+ # equals respects width
+ self.assertNotEqual(ColorsSpatial(32, 32, 4), ColorsSpatial(16, 32, 4))
+ self.assertNotEqual(hash(ColorsSpatial(32, 32, 4)), hash(ColorsSpatial(16, 32, 4)))
+ # equals respects height
+ self.assertNotEqual(ColorsSpatial(32, 32, 4), ColorsSpatial(32, 16, 4))
+ self.assertNotEqual(hash(ColorsSpatial(32, 32, 4)), hash(ColorsSpatial(32, 16, 4)))
+ # equals respects exp
+ self.assertNotEqual(ColorsSpatial(32, 32, 4), ColorsSpatial(32, 32, 8))
+ self.assertNotEqual(hash(ColorsSpatial(32, 32, 4)), hash(ColorsSpatial(32, 32, 8)))
+ # string representation
+ self.assertEqual(str(ColorsSpatial()), 'ColorsSpatial')
+ self.assertEqual(repr(ColorsSpatial(64, 16, 2)), 'ColorsSpatial(64, 16, 2)')
+
+ def test_dimension(self):
+ self.assertEqual(ColorsSpatial.dimension(32, 32, 4), 3 * (32*32 + 8*8 + 2*2))
+ self.assertEqual(ColorsSpatial.dimension(16, 16, 8), 3 * (16*16 + 2*2))
+ self.assertEqual(ColorsSpatial.dimension(64, 64, 16), 3 * (64*64 + 4*4))
+
+ def test_schema(self):
+ schema = bsfs.schema.from_string(base.SCHEMA_PREAMBLE + f'''
+ <{self.instance_prefix}> rdfs:subClassOf bsfs:Feature ;
+ # annotations
+ rdfs:label ""^^xsd:string ;
+ schema:description ""^^xsd:string .
+
+ <{self.instance_prefix}#{self.uuid}> rdfs:subClassOf <{self.instance_prefix}> ;
+ bsfs:dimension "3276"^^xsd:integer ;
+ # annotations
+ <{self.instance_prefix}/args#width> "32"^^xsd:integer ;
+ <{self.instance_prefix}/args#height> "32"^^xsd:integer ;
+ <{self.instance_prefix}/args#exp> "4"^^xsd:float .
+
+ <{self.predicate_prefix}#{self.uuid}> rdfs:subClassOf bsfs:Predicate ;
+ rdfs:domain bsfs:File ;
+ rdfs:range <{self.instance_prefix}#{self.uuid}> ;
+ bsfs:unique "true"^^xsd:boolean .
+ ''')
+ self.assertEqual(schema, ColorsSpatial().schema)
+
+ def test_extract(self):
+ ext = ColorsSpatial(2,2,2)
+ img = PIL.Image.open(os.path.join(os.path.dirname(__file__), 'testimage.jpg'))
+ node = _node.Node(ns.bsfs.Entity, bsfs.URI('http://example.com/entity#1234'))
+ principals = set(ext.principals)
+ self.assertEqual(len(principals), 1)
+ ret = list(ext.extract(node, img, principals))
+ self.assertEqual(ret[0], (
+ node,
+ list(principals)[0],
+ [91, 127, 121, 94, 138, 167, 163, 134, 190, 138, 170, 156, 121, 142, 159]))
+
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##
diff --git a/test/extractor/image/testimage.jpg b/test/extractor/image/testimage.jpg
new file mode 100644
index 0000000..c80bb48
--- /dev/null
+++ b/test/extractor/image/testimage.jpg
Binary files differ