forked from M-Labs/artiq
1
0
Fork 0

test_dataset_db: fix for windows

This commit is contained in:
Sebastien Bourdeauducq 2021-12-14 19:07:17 +08:00
parent 4f723e19a6
commit 37f14d94d0
1 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,7 @@
"""Test internal dataset representation (persistence, applets)""" """Test internal dataset representation (persistence, applets)"""
import unittest import unittest
import tempfile import tempfile
import os
from artiq.master.databases import DatasetDB from artiq.master.databases import DatasetDB
from sipyco import pyon from sipyco import pyon
@ -11,11 +12,14 @@ KEY3 = "key3"
DATA = list(range(10)) DATA = list(range(10))
COMP = "gzip" COMP = "gzip"
# tempfile.NamedTemporaryFile:
# use delete=False and manual cleanup
# for Windows compatibility
class TestDatasetDB(unittest.TestCase): class TestDatasetDB(unittest.TestCase):
def setUp(self): def setUp(self):
# empty dataset persistance file # empty dataset persistance file
self.persist_file = tempfile.NamedTemporaryFile(mode="w+") self.persist_file = tempfile.NamedTemporaryFile(mode="w+", delete=False)
print("{}", file=self.persist_file, flush=True) print("{}", file=self.persist_file, flush=True)
self.ddb = DatasetDB(self.persist_file.name) self.ddb = DatasetDB(self.persist_file.name)
@ -26,6 +30,9 @@ class TestDatasetDB(unittest.TestCase):
self.save_ddb_to_disk() self.save_ddb_to_disk()
def tearDown(self):
os.unlink(self.persist_file.name)
def save_ddb_to_disk(self): def save_ddb_to_disk(self):
self.ddb.save() self.ddb.save()
self.persist_file.flush() self.persist_file.flush()