• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Tests for the spirv test framework module."""
15
16from spirv_test_framework import get_all_test_methods, get_all_superclasses
17import unittest
18
19# Classes to be used in testing get_all_{superclasses|test_methods}()
20
21
22class Root:
23
24    def check_root(self):
25        pass
26
27
28class A(Root):
29
30    def check_a(self):
31        pass
32
33
34class B(Root):
35
36    def check_b(self):
37        pass
38
39
40class C(Root):
41
42    def check_c(self):
43        pass
44
45
46class D(Root):
47
48    def check_d(self):
49        pass
50
51
52class E(Root):
53
54    def check_e(self):
55        pass
56
57
58class H(B, C, D):
59
60    def check_h(self):
61        pass
62
63
64class I(E):
65
66    def check_i(self):
67        pass
68
69
70class O(H, I):
71
72    def check_o(self):
73        pass
74
75
76class U(A, O):
77
78    def check_u(self):
79        pass
80
81
82class X(U, A):
83
84    def check_x(self):
85        pass
86
87
88class R1:
89
90    def check_r1(self):
91        pass
92
93
94class R2:
95
96    def check_r2(self):
97        pass
98
99
100class Multi(R1, R2):
101
102    def check_multi(self):
103        pass
104
105
106class TestSpirvTestFramework(unittest.TestCase):
107    def test_get_all_superclasses(self):
108        self.assertEqual(get_all_superclasses(A), [Root])
109        self.assertEqual(get_all_superclasses(B), [Root])
110        self.assertEqual(get_all_superclasses(C), [Root])
111        self.assertEqual(get_all_superclasses(D), [Root])
112        self.assertEqual(get_all_superclasses(E), [Root])
113
114        self.assertEqual(get_all_superclasses(H), [Root, B, C, D])
115        self.assertEqual(get_all_superclasses(I), [Root, E])
116
117        self.assertEqual(get_all_superclasses(O), [Root, B, C, D, E, H, I])
118
119        self.assertEqual(get_all_superclasses(
120            U), [Root, B, C, D, E, H, I, A, O])
121        self.assertEqual(get_all_superclasses(
122            X), [Root, B, C, D, E, H, I, A, O, U])
123
124        self.assertEqual(get_all_superclasses(Multi), [R1, R2])
125
126    def test_get_all_methods(self):
127        self.assertEqual(get_all_test_methods(A), ['check_root', 'check_a'])
128        self.assertEqual(get_all_test_methods(B), ['check_root', 'check_b'])
129        self.assertEqual(get_all_test_methods(C), ['check_root', 'check_c'])
130        self.assertEqual(get_all_test_methods(D), ['check_root', 'check_d'])
131        self.assertEqual(get_all_test_methods(E), ['check_root', 'check_e'])
132
133        self.assertEqual(
134            get_all_test_methods(H),
135            ['check_root', 'check_b', 'check_c', 'check_d', 'check_h'])
136        self.assertEqual(get_all_test_methods(
137            I), ['check_root', 'check_e', 'check_i'])
138
139        self.assertEqual(
140            get_all_test_methods(O), [
141                'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h',
142                'check_i', 'check_o'
143            ])
144
145        self.assertEqual(
146            get_all_test_methods(U), [
147                'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h',
148                'check_i', 'check_a', 'check_o', 'check_u'
149            ])
150
151        self.assertEqual(
152            get_all_test_methods(X), [
153                'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h',
154                'check_i', 'check_a', 'check_o', 'check_u', 'check_x'
155            ])
156
157        self.assertEqual(
158            get_all_test_methods(Multi), ['check_r1', 'check_r2', 'check_multi'])
159