File size: 1,418 Bytes
8026e91 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from tensorboardX import SummaryWriter
import unittest
class SummaryWriterTest(unittest.TestCase):
def test_summary_writer_ctx(self):
# after using a SummaryWriter as a ctx it should be closed
with SummaryWriter(filename_suffix='.test') as writer:
writer.add_scalar('test', 1)
assert writer.file_writer is None
def test_summary_writer_backcomapt(self):
with SummaryWriter(log_dir='/tmp/tbxtest') as writer:
writer.add_scalar('test', 1)
def test_summary_writer_close(self):
# Opening and closing SummaryWriter a lot should not run into
# OSError: [Errno 24] Too many open files
passed = True
try:
writer = SummaryWriter()
writer.close()
except OSError:
passed = False
assert passed
def test_windowsPath(self):
dummyPath = "C:\\Downloads\\fjoweifj02utj43tj430"
with SummaryWriter(dummyPath) as writer:
writer.add_scalar('test', 1)
import shutil
shutil.rmtree(dummyPath)
def test_pathlib(self):
import sys
if sys.version_info.major == 2:
import pathlib2 as pathlib
else:
import pathlib
p = pathlib.Path('./pathlibtest')
with SummaryWriter(p) as writer:
writer.add_scalar('test', 1)
import shutil
shutil.rmtree(str(p))
|