Home | History | Annotate | Download | only in pyct
      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 anno module."""
     16 
     17 from __future__ import absolute_import
     18 from __future__ import division
     19 from __future__ import print_function
     20 
     21 import ast
     22 
     23 from tensorflow.contrib.py2tf.pyct import anno
     24 from tensorflow.python.platform import test
     25 
     26 
     27 class AnnoTest(test.TestCase):
     28 
     29   def test_basic(self):
     30     node = ast.Name()
     31 
     32     self.assertFalse(anno.hasanno(node, 'foo'))
     33     with self.assertRaises(AttributeError):
     34       anno.getanno(node, 'foo')
     35 
     36     anno.setanno(node, 'foo', 3)
     37     self.assertTrue(anno.hasanno(node, 'foo'))
     38     self.assertEqual(3, anno.getanno(node, 'foo'))
     39 
     40     anno.delanno(node, 'foo')
     41     self.assertFalse(anno.hasanno(node, 'foo'))
     42     with self.assertRaises(AttributeError):
     43       anno.getanno(node, 'foo')
     44 
     45 
     46 if __name__ == '__main__':
     47   test.main()
     48