Skip to content

Commit

Permalink
Add tests for union types
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Jul 26, 2019
1 parent fa109c2 commit b0a8058
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
22 changes: 22 additions & 0 deletions orangecanvas/registry/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from operator import attrgetter

import unittest
from orangecanvas.registry import InputSignal, OutputSignal

from ..base import WidgetRegistry
from .. import description
Expand Down Expand Up @@ -97,3 +98,24 @@ def test_registry_const(self):
for desc in [one_desc, zero_desc, sub_desc,
add_desc])
)

def test_input_signal(self):
isig_1 = InputSignal("A", str, "aa", id="sig-a")
isig_2 = InputSignal("A", 'builtins.str', "aa", id="sig-a")
self.assertTupleEqual(isig_1.types, isig_2.types)
self.assertTupleEqual(isig_1.types, ('builtins.str',))
isig_1 = InputSignal("A", (str, int), "aa", id="sig-a")
isig_2 = InputSignal("A", ('builtins.str', "builtins.int",), "aa",
id="sig-a")
self.assertTupleEqual(isig_1.types, isig_2.types)

def test_output_signal(self):
osig_1 = OutputSignal("A", str, id="sig-a")
osig_2 = OutputSignal("A", 'builtins.str', id="sig-a")
self.assertTupleEqual(osig_1.types, osig_2.types)
self.assertTupleEqual(osig_1.types, ('builtins.str',))
osig_1 = OutputSignal("A", (str, int), id="sig-a")
osig_2 = OutputSignal("A", ('builtins.str', "builtins.int",),
id="sig-a")
self.assertTupleEqual(osig_1.types, osig_2.types)
self.assertTupleEqual(osig_1.types, ('builtins.str', "builtins.int",))
64 changes: 64 additions & 0 deletions orangecanvas/scheme/tests/test_links.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
"""
Tests for SchemeLink
"""
import warnings

from ...gui import test
from ...registry.tests import small_testing_registry

from ...registry.description import InputSignal, OutputSignal, Dynamic

from .. import SchemeNode, SchemeLink, IncompatibleChannelTypeError
from ..link import resolved_valid_types, _classify_connection


class A:
pass


class B(A):
pass


class C:
pass


class TestSchemeLink(test.QAppTestCase):
Expand All @@ -31,3 +47,51 @@ def test_link(self):

with self.assertRaises(IncompatibleChannelTypeError):
SchemeLink(unit_node, "value", add_node, "right")

def test_utils(self):
with warnings.catch_warnings(record=True):
self.assertTupleEqual(
resolved_valid_types(("int", __name__ + ".NoSuchType", "str")),
(int, str),
)

source = OutputSignal("A", (A,))
source_d = OutputSignal("A", (A,), flags=Dynamic)
source_ac_d = OutputSignal("A", (A, C), flags=Dynamic)
source_ac = OutputSignal("A", (B, C))
sink_a = InputSignal("A", (A,), "a")
sink_b = InputSignal("B", (B,), "b")
sink_c = InputSignal("C", (C,), "c")
sink_bc = InputSignal("C", (B, C,), "c")

t1, t2 = _classify_connection(source, sink_a)
self.assertTrue(t1)
self.assertFalse(t2)

t1, t2 = _classify_connection(source, sink_b)
self.assertFalse(t1)
self.assertFalse(t2)

t1, t2 = _classify_connection(source_d, sink_b)
self.assertFalse(t1)
self.assertTrue(t2)

t1, t2 = _classify_connection(source_d, sink_a)
self.assertTrue(t1)
self.assertTrue(t2)

t1, t2 = _classify_connection(source_d, sink_c)
self.assertFalse(t1)
self.assertFalse(t2)

t1, t2 = _classify_connection(source_d, sink_bc)
self.assertFalse(t1)
self.assertTrue(t2)

t1, t2 = _classify_connection(source_ac_d, sink_bc)
self.assertFalse(t1)
self.assertTrue(t2)

t1, t2 = _classify_connection(source_ac, sink_bc)
self.assertTrue(t1)
self.assertFalse(t2)

0 comments on commit b0a8058

Please sign in to comment.