[gegl] Add python tests for node API



commit 40e7bfe83213333b29eb14bcbbbfaadf2a71cdfc
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Thu Jun 6 22:34:11 2013 -0700

    Add python tests for node API

 tests/python/test-gegl-node.py |   89 +++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/tests/python/test-gegl-node.py b/tests/python/test-gegl-node.py
index e576451..6163570 100755
--- a/tests/python/test-gegl-node.py
+++ b/tests/python/test-gegl-node.py
@@ -37,7 +37,7 @@ invert_crop_xml = """<?xml version='1.0' encoding='UTF-8'?>
 </gegl>
 """
 
-class TestGeglNode(unittest.TestCase):
+class TestGeglNodes(unittest.TestCase):
 
     def test_exists(self):
         Gegl.Node
@@ -46,29 +46,88 @@ class TestGeglNode(unittest.TestCase):
         graph = Gegl.Node.new()
         self.assertEqual(type(graph), gi.repository.Gegl.Node)
 
-class TestGeglNodeLoadXml(unittest.TestCase):
+    def test_node_properties(self):
+        graph = Gegl.Node()
+        node  = graph.create_child("gegl:nop")
 
-    def setUp(self):
-        self.graph = Gegl.Node.new_from_xml(invert_crop_xml, "")
+        self.assertEqual("gegl:nop", node.get_property("operation"))
 
-    def test_number_of_children(self):
-        children = self.graph.get_children()
+        node.set_property("operation", "gegl:translate")
+        self.assertEqual("gegl:translate", node.get_property("operation"))
 
-        self.assertEqual(len(children), 2)
+        default_x = node.get_property("x")
+        default_sampler = node.get_property("sampler")
 
-    def test_child_operation(self):
-        children = self.graph.get_children()
+        self.assertIsNotNone(default_x)
+        self.assertIsNotNone(default_sampler)
 
-        self.assertEqual(children[0].get_operation(), "gegl:crop")
-        self.assertEqual(children[1].get_operation(), "gegl:invert")
+        node.set_property("x", 10)
+        self.assertEqual(node.get_property("x"), 10)
+
+        node.set_property("x", -10)
+        self.assertEqual(node.get_property("x"), -10)
+
+        node.set_property("sampler", Gegl.SamplerType.NEAREST)
+        self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.NEAREST)
+
+        node.set_property("sampler", "linear")
+        self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.LINEAR)
+
+        node.set_property("operation", "gegl:nop")
+        self.assertEqual("gegl:nop", node.get_property("operation"))
+
+        node.set_property("operation", "gegl:translate")
+        self.assertEqual("gegl:translate", node.get_property("operation"))
+
+        self.assertEqual(node.get_property("x"), default_x)
+        self.assertEqual(node.get_property("sampler"), default_sampler)
+
+    def test_create_graph(self):
+        graph = Gegl.Node()
+        color_node = graph.create_child("gegl:color")
+        crop_node  = graph.create_child("gegl:crop")
+
+        self.assertEqual(color_node.get_operation(), "gegl:color")
+        self.assertEqual(crop_node.get_operation(), "gegl:crop")
+
+        crop_rect = Gegl.Rectangle.new(10, 20, 5, 15)
+
+        crop_node.set_property("x", crop_rect.x)
+        crop_node.set_property("y", crop_rect.y)
+        crop_node.set_property("width", crop_rect.width)
+        crop_node.set_property("height", crop_rect.height)
+
+        color_node.connect_to("output", crop_node, "input")
 
+        self.assertTrue(crop_rect.equal(crop_node.get_bounding_box()))
 
-class TestGeglNodeSaveXml(unittest.TestCase):
+        trans_node = graph.create_child("gegl:translate")
 
-    def setUp(self):
-        self.graph = Gegl.Node.new()
+        crop_node.connect_to("output", trans_node, "input")
+
+        self.assertTrue(crop_rect.equal(trans_node.get_bounding_box()))
+
+        trans_node.set_property("x", 10)
+
+        self.assertFalse(crop_rect.equal(trans_node.get_bounding_box()))
+
+        trans_rect = crop_rect.dup()
+        trans_rect.x += 10
+
+        self.assertTrue(trans_rect.equal(trans_node.get_bounding_box()))
+
+class TestGeglXml(unittest.TestCase):
+
+    def test_load_xml(self):
+        graph = Gegl.Node.new_from_xml(invert_crop_xml, "")
+
+        children = graph.get_children()
+
+        self.assertEqual(len(children), 2)
+
+        self.assertEqual(children[0].get_operation(), "gegl:crop")
+        self.assertEqual(children[1].get_operation(), "gegl:invert")
 
-    # Easiest way to test to_xml when we can't yet build graphs programatically
     def test_load_save_roundtrip(self):
         graph = Gegl.Node.new_from_xml(invert_crop_xml, "")
         output = graph.to_xml("")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]