2
sys.path.insert(0, "../src")
3
import os, unittest, gzip
4
import dup_temp, file_naming
6
prefix = "testfiles/output"
8
class TempTest(unittest.TestCase):
9
"""Test various temp files methods"""
11
"""Delete testfiles/output and recreate"""
12
assert not os.system("rm -rf testfiles/output")
13
assert not os.system("mkdir testfiles/output")
15
def test_temppath(self):
16
"""Allocate new temppath, try open_with_delete"""
17
tp = dup_temp.new_temppath()
18
assert not tp.exists()
19
fileobj = tp.open("wb")
20
fileobj.write("hello, there")
25
assert tp.name in dup_temp.tempfile_names
27
fin = tp.open_with_delete("rb")
29
assert buf == "hello, there", buf
31
assert not tp.exists()
33
def test_tempduppath(self):
34
"""Allocate new tempduppath, then open_with_delete"""
35
# pr indicates file is gzipped
36
pr = file_naming.ParseResults("inc", manifest = 1,
37
start_time = 1, end_time = 3,
40
tdp = dup_temp.new_tempduppath(pr)
41
assert not tdp.exists()
42
fout = tdp.filtered_open("wb")
43
fout.write("hello, there")
48
assert tdp.name in dup_temp.tempfile_names
50
fin1 = gzip.GzipFile(tdp.name, "rb")
52
assert buf == "hello, there", buf
55
fin2 = tdp.filtered_open_with_delete("rb")
57
assert buf2 == "hello, there", buf
59
assert not tdp.exists()
62
if __name__ == "__main__": unittest.main()