1 # Copyright 2017 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 """Unit tests for common values and methods of TensorFlow Debugger.""" 16 from __future__ import absolute_import 17 from __future__ import division 18 from __future__ import print_function 19 20 import json 21 22 from tensorflow.python.debug.lib import common 23 from tensorflow.python.framework import constant_op 24 from tensorflow.python.framework import test_util 25 from tensorflow.python.platform import googletest 26 27 28 class CommonTest(test_util.TensorFlowTestCase): 29 30 def testOnFeedOneFetch(self): 31 a = constant_op.constant(10.0, name="a") 32 b = constant_op.constant(20.0, name="b") 33 run_key = common.get_run_key({"a": a}, [b]) 34 loaded = json.loads(run_key) 35 self.assertItemsEqual(["a:0"], loaded[0]) 36 self.assertItemsEqual(["b:0"], loaded[1]) 37 38 def testGetRunKeyFlat(self): 39 a = constant_op.constant(10.0, name="a") 40 b = constant_op.constant(20.0, name="b") 41 run_key = common.get_run_key({"a": a}, [a, b]) 42 loaded = json.loads(run_key) 43 self.assertItemsEqual(["a:0"], loaded[0]) 44 self.assertItemsEqual(["a:0", "b:0"], loaded[1]) 45 46 def testGetRunKeyNestedFetches(self): 47 a = constant_op.constant(10.0, name="a") 48 b = constant_op.constant(20.0, name="b") 49 c = constant_op.constant(30.0, name="c") 50 d = constant_op.constant(30.0, name="d") 51 run_key = common.get_run_key( 52 {}, {"set1": [a, b], "set2": {"c": c, "d": d}}) 53 loaded = json.loads(run_key) 54 self.assertItemsEqual([], loaded[0]) 55 self.assertItemsEqual(["a:0", "b:0", "c:0", "d:0"], loaded[1]) 56 57 58 if __name__ == "__main__": 59 googletest.main() 60