~ed.so/duplicity/reuse-passphrase-for-signing-fix

« back to all changes in this revision

Viewing changes to testing/dup_temptest.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
sys.path.insert(0, "../src")
 
3
import os, unittest, gzip
 
4
import dup_temp, file_naming
 
5
 
 
6
prefix = "testfiles/output"
 
7
 
 
8
class TempTest(unittest.TestCase):
 
9
        """Test various temp files methods"""
 
10
        def del_tmp(self):
 
11
                """Delete testfiles/output and recreate"""
 
12
                assert not os.system("rm -rf testfiles/output")
 
13
                assert not os.system("mkdir testfiles/output")
 
14
 
 
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")
 
21
                fileobj.close()
 
22
                tp.setdata()
 
23
                assert tp.isreg()
 
24
 
 
25
                assert tp.name in dup_temp.tempfile_names
 
26
                
 
27
                fin = tp.open_with_delete("rb")
 
28
                buf = fin.read()
 
29
                assert buf == "hello, there", buf
 
30
                fin.close()
 
31
                assert not tp.exists()
 
32
 
 
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,
 
38
                                                                          compressed = 1)
 
39
 
 
40
                tdp = dup_temp.new_tempduppath(pr)
 
41
                assert not tdp.exists()
 
42
                fout = tdp.filtered_open("wb")
 
43
                fout.write("hello, there")
 
44
                fout.close()
 
45
                tdp.setdata()
 
46
                assert tdp.isreg()
 
47
 
 
48
                assert tdp.name in dup_temp.tempfile_names
 
49
 
 
50
                fin1 = gzip.GzipFile(tdp.name, "rb")
 
51
                buf = fin1.read()
 
52
                assert buf == "hello, there", buf
 
53
                fin1.close()
 
54
 
 
55
                fin2 = tdp.filtered_open_with_delete("rb")
 
56
                buf2 = fin2.read()
 
57
                assert buf2 == "hello, there", buf
 
58
                fin2.close()
 
59
                assert not tdp.exists()
 
60
 
 
61
 
 
62
if __name__ == "__main__": unittest.main()
 
63