tests.functions.test_common_ancestor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestCommonAncestor.test_common_acestor_of_collections() 0 2 1
A TestCommonAncestor.test_invalid() 0 3 2
A TestCommonAncestor.test_common_ancestor_of_types() 0 4 1
A TestCommonAncestor.test_common_ancestor() 0 4 1
A TestCommonAncestor.test_common_ancestor_of_typing_types() 0 2 1
A TestCommonAncestor.test_special_args() 0 3 1
1
from typing import Type
2
from unittest import TestCase
3
4
from typish import common_ancestor, common_ancestor_of_types, NoneType
5
6
7
class A: pass
8
class B(A): pass
9
class C(B): pass
10
class D(C): pass
11
class E(D): pass
12
13
14
class TestCommonAncestor(TestCase):
15
    def test_common_ancestor(self):
16
        self.assertEqual(C, common_ancestor(E(), C(), D(), E()))
17
        self.assertEqual(B, common_ancestor(E(), C(), D(), E(), B()))
18
        self.assertEqual(object, common_ancestor(E(), C(), D(), E(), B(), 42))
19
20
    def test_common_ancestor_of_types(self):
21
        self.assertEqual(C, common_ancestor_of_types(E, C, D, E))
22
        self.assertEqual(object, common_ancestor_of_types(int, str))
23
        common_ancestor_of_types(list, tuple)
24
25
    def test_common_ancestor_of_typing_types(self):
26
        self.assertEqual(type, common_ancestor_of_types(Type[int], Type[str]))
27
28
    def test_common_acestor_of_collections(self):
29
        self.assertEqual(list, common_ancestor([1, 2, 3], ['a', 'b', 'c']))
30
31
    def test_special_args(self):
32
        self.assertEqual(NoneType, common_ancestor(None, None))
33
        self.assertEqual(int, common_ancestor(42))
34
35
    def test_invalid(self):
36
        with self.assertRaises(TypeError):
37
            common_ancestor()
38