1# Copyright 2018 The TensorFlow Authors. All Rights Reserved. 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# ============================================================================= 15"""Tests for the trackable view.""" 16 17from tensorflow.python.checkpoint import trackable_view 18from tensorflow.python.eager import test 19from tensorflow.python.trackable import base 20 21 22class TrackableViewTest(test.TestCase): 23 24 def test_children(self): 25 root = base.Trackable() 26 leaf = base.Trackable() 27 root._track_trackable(leaf, name="leaf") 28 (current_name, 29 current_dependency), = trackable_view.TrackableView.children(root).items() 30 self.assertIs(leaf, current_dependency) 31 self.assertEqual("leaf", current_name) 32 33 def test_descendants(self): 34 root = base.Trackable() 35 leaf = base.Trackable() 36 root._track_trackable(leaf, name="leaf") 37 descendants = trackable_view.TrackableView(root).descendants() 38 self.assertIs(2, len(descendants)) 39 self.assertIs(root, descendants[0]) 40 self.assertIs(leaf, descendants[1]) 41 42 43if __name__ == "__main__": 44 test.main() 45