File: test_get_mro.py

package info (click to toggle)
python-typish 1.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: python: 1,636; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import typing
from typing import Union
from unittest import TestCase

from typish import get_mro


class A:
    ...


class B(A):
    ...


class TestGetMRO(TestCase):
    def test_get_mro(self):
        mro_b = get_mro(B)
        self.assertTupleEqual((B, A, object), mro_b)

    def test_get_mro_union(self):
        mro_u = get_mro(Union[int, str])

        # Below is to stay compatible with Python 3.5+
        super_cls = getattr(typing, '_GenericAlias',
                            getattr(typing, 'GenericMeta', None))
        expected = (typing.Union, super_cls, object)

        self.assertTupleEqual(expected, mro_u)

    def test_get_mro_object(self):
        mro_b = get_mro(B())
        self.assertTupleEqual((B, A, object), mro_b)