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"""Tests for misc module.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21from tensorflow.python.autograph.utils import misc 22from tensorflow.python.framework import test_util 23from tensorflow.python.framework.constant_op import constant 24from tensorflow.python.ops.variables import Variable 25from tensorflow.python.platform import test 26 27 28class MiscTest(test.TestCase): 29 30 def test_capitalize_initial(self): 31 self.assertEqual('', misc.capitalize_initial('')) 32 self.assertEqual('A', misc.capitalize_initial('A')) 33 self.assertEqual('Ab', misc.capitalize_initial('Ab')) 34 self.assertEqual('AbC', misc.capitalize_initial('AbC')) 35 self.assertEqual('A', misc.capitalize_initial('a')) 36 self.assertEqual('Ab', misc.capitalize_initial('ab')) 37 self.assertEqual('AbC', misc.capitalize_initial('abC')) 38 39 @test_util.run_deprecated_v1 40 def test_alias_single_tensor(self): 41 a = constant(1) 42 43 new_a = misc.alias_tensors(a) 44 self.assertFalse(new_a is a) 45 with self.cached_session() as sess: 46 self.assertEqual(1, self.evaluate(new_a)) 47 48 @test_util.run_deprecated_v1 49 def test_alias_tensors(self): 50 a = constant(1) 51 v = Variable(2) 52 s = 'a' 53 l = [1, 2, 3] 54 55 new_a, new_v, new_s, new_l = misc.alias_tensors(a, v, s, l) 56 57 self.assertFalse(new_a is a) 58 self.assertTrue(new_v is v) 59 self.assertTrue(new_s is s) 60 self.assertTrue(new_l is l) 61 with self.cached_session() as sess: 62 self.assertEqual(1, self.evaluate(new_a)) 63 64 65if __name__ == '__main__': 66 test.main() 67