Ejemplo n.º 1
0
    def test_creates_new_dir_with_summary_dir_path_like(self):
        summary_dir = self.create_tempdir()
        shutil.rmtree(summary_dir)
        self.assertFalse(os.path.exists(summary_dir))

        tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)

        self.assertTrue(os.path.exists(summary_dir))
Ejemplo n.º 2
0
    async def test_raises_type_error_with_key(self, key):
        summary_dir = self.create_tempdir()
        release_mngr = tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)
        value = 1
        type_signature = computation_types.TensorType(tf.int32)

        with self.assertRaises(TypeError):
            await release_mngr.release(value, type_signature, key)
Ejemplo n.º 3
0
    async def test_does_not_raise_type_error_with_key(self, key):
        summary_dir = self.create_tempdir()
        release_mngr = tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)
        value = 1
        type_signature = computation_types.TensorType(tf.int32)

        try:
            await release_mngr.release(value, type_signature, key)
        except TypeError:
            self.fail('Raised TypeError unexpectedly.')
Ejemplo n.º 4
0
    async def test_does_not_write_value(self, value, type_signature):
        summary_dir = self.create_tempdir()
        release_mngr = tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)

        patch_scalar = mock.patch.object(tf.summary, 'scalar')
        patch_histogram = mock.patch.object(tf.summary, 'histogram')
        with patch_scalar as mock_scalar, patch_histogram as mock_histogram:
            await release_mngr.release(value, type_signature, 1)

            mock_scalar.assert_not_called()
            mock_histogram.assert_not_called()
Ejemplo n.º 5
0
    async def test_writes_value_histogram(self, value, type_signature,
                                          expected_calls):
        summary_dir = self.create_tempdir()
        release_mngr = tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)

        with mock.patch.object(tf.summary, 'histogram') as mock_histogram:
            await release_mngr.release(value, type_signature, 1)

            self.assertLen(mock_histogram.mock_calls, len(expected_calls))
            for call, expected_args in zip(mock_histogram.mock_calls,
                                           expected_calls):
                _, args, kwargs = call
                actual_name, actual_value = args
                expected_name, expected_value = expected_args
                self.assertEqual(actual_name, expected_name)
                self.assertAllEqual(actual_value, expected_value)
                self.assertEqual(kwargs, {'step': 1})
Ejemplo n.º 6
0
    async def test_writes_value_scalar_and_histogram(self):
        summary_dir = self.create_tempdir()
        release_mngr = tensorboard_release_manager.TensorBoardReleaseManager(
            summary_dir=summary_dir)
        value = [1, tf.ones([3], tf.int32)]
        type_signature = computation_types.StructType([
            tf.int32,
            computation_types.TensorType(tf.float32, [3]),
        ])

        patched_scalar = mock.patch.object(tf.summary, 'scalar')
        patched_histogram = mock.patch.object(tf.summary, 'histogram')
        with patched_scalar as mock_scalar, patched_histogram as mock_histogram:
            await release_mngr.release(value, type_signature, 1)

            mock_scalar.assert_called_once_with('0', 1, step=1)
            self.assertLen(mock_histogram.mock_calls, 1)
            call = mock_histogram.mock_calls[0]
            _, args, kwargs = call
            actual_name, actual_value = args
            expected_name, expected_value = '1', tf.ones([3], tf.int32)
            self.assertEqual(actual_name, expected_name)
            self.assertAllEqual(actual_value, expected_value)
            self.assertEqual(kwargs, {'step': 1})
Ejemplo n.º 7
0
 def test_raises_value_error_with_summary_dir_empty(self):
     with self.assertRaises(ValueError):
         tensorboard_release_manager.TensorBoardReleaseManager(
             summary_dir='')
Ejemplo n.º 8
0
 def test_raises_type_error_with_summary_dir(self, summary_dir):
     with self.assertRaises(TypeError):
         tensorboard_release_manager.TensorBoardReleaseManager(
             summary_dir=summary_dir)