Spaces:
Runtime error
Runtime error
# Copyright 2023 The TensorFlow Authors. All Rights Reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
"""Tests for registry.""" | |
import tensorflow as tf, tf_keras | |
from official.core import registry | |
class RegistryTest(tf.test.TestCase): | |
def test_register(self): | |
collection = {} | |
def func_test(): | |
pass | |
self.assertEqual(registry.lookup(collection, 'functions/func_0'), func_test) | |
class ClassRegistryKey: | |
pass | |
self.assertEqual( | |
registry.lookup(collection, 'classes/cls_0'), ClassRegistryKey) | |
class ClassRegistryValue: | |
pass | |
self.assertEqual( | |
registry.lookup(collection, ClassRegistryKey), ClassRegistryValue) | |
def test_register_hierarchy(self): | |
collection = {} | |
def func_test0(): | |
pass | |
def func_test1(): | |
pass | |
def func_test2(): | |
pass | |
expected_collection = { | |
'functions': { | |
'func_0': func_test0, | |
}, | |
'func_1': func_test1, | |
func_test1: func_test2, | |
} | |
self.assertEqual(collection, expected_collection) | |
def test_register_error(self): | |
collection = {} | |
def func_test0(): # pylint: disable=unused-variable | |
pass | |
with self.assertRaises(KeyError): | |
def func_test1(): # pylint: disable=unused-variable | |
pass | |
with self.assertRaises(LookupError): | |
registry.lookup(collection, 'non-exist') | |
if __name__ == '__main__': | |
tf.test.main() | |