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