1# Copyright 2020 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"""Test for utilities for collectives.""" 16 17from tensorflow.python.distribute import collective_util 18from tensorflow.python.eager import test 19 20 21class OptionsTest(test.TestCase): 22 23 def testCreateOptionsViaExportedAPI(self): 24 options = collective_util._OptionsExported(bytes_per_pack=1) 25 self.assertIsInstance(options, collective_util.Options) 26 self.assertEqual(options.bytes_per_pack, 1) 27 with self.assertRaises(ValueError): 28 collective_util._OptionsExported(bytes_per_pack=-1) 29 30 def testCreateOptionsViaHints(self): 31 with self.assertLogs() as cm: 32 options = collective_util.Hints(50, 1) 33 self.assertTrue(any("is deprecated" in msg for msg in cm.output)) 34 self.assertIsInstance(options, collective_util.Options) 35 self.assertEqual(options.bytes_per_pack, 50) 36 self.assertEqual(options.timeout_seconds, 1) 37 38 39if __name__ == "__main__": 40 test.main() 41