Code Duplication    Length = 17-22 lines in 2 locations

tests/test_stflow/test_method_interception.py 2 locations

@@ 95-116 (lines=22) @@
92
93
    ex.run()
94
95
def test_log_file_writer_as_context_manager_with_exception(ex, tf):
96
    """ Check that Tensorflow log directory is captured by LogFileWriter context manager"""
97
    TEST_LOG_DIR = "/tmp/sacred_test"
98
99
    @ex.main
100
    def run_experiment(_run):
101
        assert _run.info.get("tensorflow", None) is None
102
        with tf.Session() as s:
103
            # Capturing the log directory should be done only in scope of the context manager
104
            try:
105
                with LogFileWriter(ex):
106
                    swr = tf.summary.FileWriter(logdir=TEST_LOG_DIR, graph=s.graph)
107
                    assert swr is not None
108
                    assert _run.info["tensorflow"]["logdirs"] == [TEST_LOG_DIR]
109
                    raise ValueError("I want to be raised!")
110
            except ValueError:
111
                pass
112
            # This should not be captured:
113
            tf.summary.FileWriter("/tmp/whatever", s.graph)
114
            assert _run.info["tensorflow"]["logdirs"] == [TEST_LOG_DIR]
115
116
    ex.run()
117
118
# Tests whether logdir is stored into the info dictionary when creating a new FileWriter object,
119
# but this time on a method of a class
@@ 48-64 (lines=17) @@
45
46
47
# Tests whether logdir is stored into the info dictionary when creating a new FileWriter object
48
def test_log_file_writer(ex, tf):
49
    TEST_LOG_DIR = "/dev/null"
50
    TEST_LOG_DIR2 = "/tmp/sacred_test"
51
52
    @ex.main
53
    @LogFileWriter(ex)
54
    def run_experiment(_run):
55
        assert _run.info.get("tensorflow", None) is None
56
        with tf.Session() as s:
57
            with LogFileWriter(ex):
58
                swr = tf.summary.FileWriter(logdir=TEST_LOG_DIR, graph=s.graph)
59
            assert swr is not None
60
            assert _run.info["tensorflow"]["logdirs"] == [TEST_LOG_DIR]
61
            tf.summary.FileWriter(TEST_LOG_DIR2, s.graph)
62
            assert _run.info["tensorflow"]["logdirs"] == [TEST_LOG_DIR, TEST_LOG_DIR2]
63
64
    ex.run()
65
66
67
def test_log_summary_writer_as_context_manager(ex, tf):