• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Tests for tensorflow.python.summary.summary_iterator."""
16
17import glob
18import os.path
19
20from tensorflow.core.util import event_pb2
21from tensorflow.python.framework import test_util
22from tensorflow.python.platform import test
23from tensorflow.python.summary import summary_iterator
24from tensorflow.python.summary.writer import writer
25
26
27class SummaryIteratorTestCase(test.TestCase):
28
29  @test_util.run_deprecated_v1
30  def testSummaryIteratorEventsAddedAfterEndOfFile(self):
31    test_dir = os.path.join(self.get_temp_dir(), "events")
32    with writer.FileWriter(test_dir) as w:
33      session_log_start = event_pb2.SessionLog.START
34      w.add_session_log(event_pb2.SessionLog(status=session_log_start), 1)
35      w.flush()
36      path = glob.glob(os.path.join(test_dir, "event*"))[0]
37      rr = summary_iterator.summary_iterator(path)
38      # The first event should list the file_version.
39      ev = next(rr)
40      self.assertEqual("brain.Event:2", ev.file_version)
41      # The next event should be the START message.
42      ev = next(rr)
43      self.assertEqual(1, ev.step)
44      self.assertEqual(session_log_start, ev.session_log.status)
45      # Reached EOF.
46      self.assertRaises(StopIteration, lambda: next(rr))
47      w.add_session_log(event_pb2.SessionLog(status=session_log_start), 2)
48      w.flush()
49      # The new event is read, after previously seeing EOF.
50      ev = next(rr)
51      self.assertEqual(2, ev.step)
52      self.assertEqual(session_log_start, ev.session_log.status)
53      # Get EOF again.
54      self.assertRaises(StopIteration, lambda: next(rr))
55
56if __name__ == "__main__":
57  test.main()
58