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"""Basic assertions.""" 16 17import tensorflow as tf 18 19from tensorflow.python.autograph.tests import reference_test_base 20 21 22def simple_assertion(x): 23 assert x > 0 24 return x 25 26 27class ReferenceTest(reference_test_base.TestCase): 28 29 def setUp(self): 30 super(ReferenceTest, self).setUp() 31 self.autograph_opts = tf.autograph.experimental.Feature.ASSERT_STATEMENTS 32 33 def test_basic(self): 34 self.assertFunctionMatchesEager(simple_assertion, 1) 35 self.assertFunctionMatchesEager(simple_assertion, tf.constant(1)) 36 with self.assertRaises(AssertionError): 37 self.function(simple_assertion)(0) 38 with self.assertRaises(tf.errors.InvalidArgumentError): 39 self.function(simple_assertion)(tf.constant(0)) 40 41 42if __name__ == '__main__': 43 tf.test.main() 44