1# Copyright 2019 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 `multi_process_runner` for non-initialization."""
16
17from tensorflow.python.distribute import multi_process_runner
18from tensorflow.python.distribute import multi_worker_test_base
19from tensorflow.python.eager import test
20
21
22class MultiProcessRunnerNoInitTest(test.TestCase):
23
24  def test_not_calling_correct_main(self):
25
26    def simple_func():
27      return 'foobar'
28
29    with self.assertRaisesRegex(multi_process_runner.NotInitializedError,
30                                '`multi_process_runner` is not initialized.'):
31      multi_process_runner.run(
32          simple_func,
33          multi_worker_test_base.create_cluster_spec(num_workers=1))
34
35
36if __name__ == '__main__':
37  # Intentionally not using `multi_process_runner.test_main()` so the error
38  # would occur.
39  test.main()
40