aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/python/python_abstractbase_runme.py
blob: 0790c5ca73fd3e4efcda05a6dd8873c46f2e8f96 (plain)
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
34
35
36
37
38
39
40
import sys

# collections.abc requires Python 3.3+

from python_abstractbase import *
if sys.version_info[0:2] >= (3, 3):
    import collections.abc
else:
    import collections

# This is expected to fail with -builtin option
# Builtin types can't inherit from pure-python abstract bases
if is_python_builtin():
    exit(0)

def check_issubclass(derived, base):
    if not issubclass(derived, base):
        raise RuntimeError("{} is not a subclass of {}".format(derived, base))

if sys.version_info[0:2] >= (3, 3):
    check_issubclass(Mapii, collections.abc.MutableMapping)
    check_issubclass(Multimapii, collections.abc.MutableMapping)
    check_issubclass(IntSet, collections.abc.MutableSet)
    check_issubclass(IntMultiset, collections.abc.MutableSet)
    check_issubclass(IntVector, collections.abc.MutableSequence)
    check_issubclass(IntList, collections.abc.MutableSequence)
else:
    check_issubclass(Mapii, collections.MutableMapping)
    check_issubclass(Multimapii, collections.MutableMapping)
    check_issubclass(IntSet, collections.MutableSet)
    check_issubclass(IntMultiset, collections.MutableSet)
    check_issubclass(IntVector, collections.MutableSequence)
    check_issubclass(IntList, collections.MutableSequence)

mapii = Mapii()
multimapii = Multimapii()
intset = IntSet()
intmultiset = IntMultiset()
intvector = IntVector()
intlist = IntList()