
import tensorflow_cloud as tfc

# MultiWorkerMirroredStrategy
tfc.run(
    entry_point="tensorflow_cloud/python/tests/testdata/mnist_example_using_ctl.py",
    distribution_strategy=None,
    worker_count=1,
    requirements_txt="tensorflow_cloud/python/tests/testdata/requirements.txt",
    stream_logs=True,
)

"""Integration tests for calling tfc.run on script with keras."""

import os
import sys
from unittest import mock
import tensorflow as tf
import tensorflow_cloud as tfc


class TensorflowCloudOnScriptTest(tf.test.TestCase):
    def setUp(self):
        super(TensorflowCloudOnScriptTest, self).setUp()
        self.test_data_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "../testdata/"
        )

    @mock.patch.object(sys, "exit", autospec=True)
    def test_MWMS_on_script(self, mock_exit):
        mock_exit.side_effect = RuntimeError("exit called")
        with self.assertRaises(RuntimeError):
            tfc.run(
                entry_point=os.path.join(
                    self.test_data_path, "mnist_example_using_ctl.py"
                ),
                distribution_strategy=None,
                worker_count=1,
                requirements_txt=os.path.join(
                    self.test_data_path, "requirements.txt"),
            )
        mock_exit.assert_called_once_with(0)


if __name__ == "__main__":
    tf.test.main()

Add test harness to call_run_on_script_with_keras
Add test harness to call_run_on_script_with_keras

+ """Integration tests for calling tfc.run on script with keras."""
  
+ import os
+ import sys
+ from unittest import mock
+ import tensorflow as tf
  import tensorflow_cloud as tfc
  
- # MultiWorkerMirroredStrategy
- tfc.run(
-     entry_point="tensorflow_cloud/python/tests/testdata/mnist_example_using_ctl.py",
-     distribution_strategy=None,
-     worker_count=1,
-     requirements_txt="tensorflow_cloud/python/tests/testdata/requirements.txt",
-     stream_logs=True,
- )
  
+ class TensorflowCloudOnScriptTest(tf.test.TestCase):
+     def setUp(self):
+         super(TensorflowCloudOnScriptTest, self).setUp()
+         self.test_data_path = os.path.join(
+             os.path.dirname(os.path.abspath(__file__)), "../testdata/"
+         )
+ 
+     @mock.patch.object(sys, "exit", autospec=True)
+     def test_MWMS_on_script(self, mock_exit):
+         mock_exit.side_effect = RuntimeError("exit called")
+         with self.assertRaises(RuntimeError):
+             tfc.run(
+                 entry_point=os.path.join(
+                     self.test_data_path, "mnist_example_using_ctl.py"
+                 ),
+                 distribution_strategy=None,
+                 worker_count=1,
+                 requirements_txt=os.path.join(
+                     self.test_data_path, "requirements.txt"),
+             )
+         mock_exit.assert_called_once_with(0)
+ 
+ 
+ if __name__ == "__main__":
+     tf.test.main()
+ 
Add test harness to call_run_on_script_with_keras
## Code Before:

import tensorflow_cloud as tfc

# MultiWorkerMirroredStrategy
tfc.run(
    entry_point="tensorflow_cloud/python/tests/testdata/mnist_example_using_ctl.py",
    distribution_strategy=None,
    worker_count=1,
    requirements_txt="tensorflow_cloud/python/tests/testdata/requirements.txt",
    stream_logs=True,
)

## Instruction:
Add test harness to call_run_on_script_with_keras
## Code After:
"""Integration tests for calling tfc.run on script with keras."""

import os
import sys
from unittest import mock
import tensorflow as tf
import tensorflow_cloud as tfc


class TensorflowCloudOnScriptTest(tf.test.TestCase):
    def setUp(self):
        super(TensorflowCloudOnScriptTest, self).setUp()
        self.test_data_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "../testdata/"
        )

    @mock.patch.object(sys, "exit", autospec=True)
    def test_MWMS_on_script(self, mock_exit):
        mock_exit.side_effect = RuntimeError("exit called")
        with self.assertRaises(RuntimeError):
            tfc.run(
                entry_point=os.path.join(
                    self.test_data_path, "mnist_example_using_ctl.py"
                ),
                distribution_strategy=None,
                worker_count=1,
                requirements_txt=os.path.join(
                    self.test_data_path, "requirements.txt"),
            )
        mock_exit.assert_called_once_with(0)


if __name__ == "__main__":
    tf.test.main()
