Skip to content

Commit 4427ae9

Browse files
committed
#128 WIP tests write of file
1 parent e50e451 commit 4427ae9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/test_filewriter.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
sys.path.insert(0, _path)
1414

1515
import apstools
16+
from apstools.filewriters import SpecWriterCallback
1617
from databroker import Broker
1718
import json
1819
import shutil
@@ -73,9 +74,22 @@ def tearDown(self):
7374
if os.path.exists(self.tempdir):
7475
shutil.rmtree(self.tempdir, ignore_errors=True)
7576

76-
def test_test(self):
77+
def test_writer(self):
7778
self.assertTrue(len(self.db) > 0, "test data ready")
78-
# TODO: newfile() tests
79+
testfile = os.path.join(self.tempdir, "tune_mr.dat")
80+
specwriter = SpecWriterCallback(filename=testfile)
81+
self.assertIsInstance(specwriter, SpecWriterCallback, "specwriter object")
82+
self.assertEqual(specwriter.spec_filename, testfile, "output data file")
83+
self.assertFalse(os.path.exists(testfile), "data file not created yet")
84+
85+
# write the doc stream to the file
86+
for document in self.db["tune_mr"]:
87+
tag, doc = document
88+
specwriter.receiver(tag, doc)
89+
90+
self.assertTrue(os.path.exists(testfile), "data file created")
91+
92+
# TODO: test newfile() with existing file
7993

8094

8195
def suite(*args, **kw):

0 commit comments

Comments
 (0)