1# Copyright (c) 2018 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 15from spirv_test_framework import get_all_test_methods, get_all_superclasses 16from nose.tools import assert_equal, with_setup 17 18 19# Classes to be used in testing get_all_{superclasses|test_methods}() 20class Root: 21 22 def check_root(self): 23 pass 24 25 26class A(Root): 27 28 def check_a(self): 29 pass 30 31 32class B(Root): 33 34 def check_b(self): 35 pass 36 37 38class C(Root): 39 40 def check_c(self): 41 pass 42 43 44class D(Root): 45 46 def check_d(self): 47 pass 48 49 50class E(Root): 51 52 def check_e(self): 53 pass 54 55 56class H(B, C, D): 57 58 def check_h(self): 59 pass 60 61 62class I(E): 63 64 def check_i(self): 65 pass 66 67 68class O(H, I): 69 70 def check_o(self): 71 pass 72 73 74class U(A, O): 75 76 def check_u(self): 77 pass 78 79 80class X(U, A): 81 82 def check_x(self): 83 pass 84 85 86class R1: 87 88 def check_r1(self): 89 pass 90 91 92class R2: 93 94 def check_r2(self): 95 pass 96 97 98class Multi(R1, R2): 99 100 def check_multi(self): 101 pass 102 103 104def nosetest_get_all_superclasses(): 105 """Tests get_all_superclasses().""" 106 107 assert_equal(get_all_superclasses(A), [Root]) 108 assert_equal(get_all_superclasses(B), [Root]) 109 assert_equal(get_all_superclasses(C), [Root]) 110 assert_equal(get_all_superclasses(D), [Root]) 111 assert_equal(get_all_superclasses(E), [Root]) 112 113 assert_equal(get_all_superclasses(H), [Root, B, C, D]) 114 assert_equal(get_all_superclasses(I), [Root, E]) 115 116 assert_equal(get_all_superclasses(O), [Root, B, C, D, E, H, I]) 117 118 assert_equal(get_all_superclasses(U), [Root, B, C, D, E, H, I, A, O]) 119 assert_equal(get_all_superclasses(X), [Root, B, C, D, E, H, I, A, O, U]) 120 121 assert_equal(get_all_superclasses(Multi), [R1, R2]) 122 123 124def nosetest_get_all_methods(): 125 """Tests get_all_test_methods().""" 126 assert_equal(get_all_test_methods(A), ['check_root', 'check_a']) 127 assert_equal(get_all_test_methods(B), ['check_root', 'check_b']) 128 assert_equal(get_all_test_methods(C), ['check_root', 'check_c']) 129 assert_equal(get_all_test_methods(D), ['check_root', 'check_d']) 130 assert_equal(get_all_test_methods(E), ['check_root', 'check_e']) 131 132 assert_equal( 133 get_all_test_methods(H), 134 ['check_root', 'check_b', 'check_c', 'check_d', 'check_h']) 135 assert_equal(get_all_test_methods(I), ['check_root', 'check_e', 'check_i']) 136 137 assert_equal( 138 get_all_test_methods(O), [ 139 'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h', 140 'check_i', 'check_o' 141 ]) 142 143 assert_equal( 144 get_all_test_methods(U), [ 145 'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h', 146 'check_i', 'check_a', 'check_o', 'check_u' 147 ]) 148 assert_equal( 149 get_all_test_methods(X), [ 150 'check_root', 'check_b', 'check_c', 'check_d', 'check_e', 'check_h', 151 'check_i', 'check_a', 'check_o', 'check_u', 'check_x' 152 ]) 153 154 assert_equal( 155 get_all_test_methods(Multi), ['check_r1', 'check_r2', 'check_multi']) 156