Merge lp:~aaron-whitehouse/duplicity/test-verify-improvements into lp:~duplicity-team/duplicity/0.7-series

Proposed by Aaron Whitehouse
Status: Merged
Merged at revision: 1038
Proposed branch: lp:~aaron-whitehouse/duplicity/test-verify-improvements
Merge into: lp:~duplicity-team/duplicity/0.7-series
Diff against target: 202 lines (+90/-94)
1 file modified
testing/functional/test_verify.py (+90/-94)
To merge this branch: bzr merge lp:~aaron-whitehouse/duplicity/test-verify-improvements
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+245060@code.launchpad.net

Description of the change

Fix up test_verify, which was a bit of a mess:
* Simplify test_verify.py to just do a simple backup and verify on a single file in each test.
* Modify tests to correctly use --compare-data option.
* Add tests for verify when the source files have the atime/mtime manipulated.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testing/functional/test_verify.py'
2--- testing/functional/test_verify.py 2014-12-17 20:29:09 +0000
3+++ testing/functional/test_verify.py 2014-12-18 01:52:23 +0000
4@@ -23,8 +23,6 @@
5 import os
6 import unittest
7
8-from duplicity import path
9-from duplicity import globals
10 from . import CmdError, FunctionalTestCase
11
12
13@@ -32,99 +30,97 @@
14 """
15 Test verify using duplicity binary
16 """
17- def runtest(self, dirlist, backup_options=[], restore_options=[]):
18- """Run backup/restore test on directories in dirlist
19- This is identical to test_final.runtest"""
20- assert len(dirlist) >= 1
21-
22- # Back up directories to local backend
23- current_time = 100000
24- self.backup("full", dirlist[0], current_time=current_time,
25- options=backup_options)
26- for new_dir in dirlist[1:]:
27- current_time += 100000
28- self.backup("inc", new_dir, current_time=current_time,
29- options=backup_options)
30-
31- # Restore each and compare them
32- for i in range(len(dirlist)):
33- dirname = dirlist[i]
34- current_time = 100000 * (i + 1)
35- self.restore(time=current_time, options=restore_options)
36- self.check_same(dirname, "testfiles/restore_out")
37- self.verify(dirname,
38- time=current_time, options=restore_options)
39-
40- def check_same(self, filename1, filename2):
41- """Verify two filenames are the same
42- This is identical to test_final.check_same"""
43- path1, path2 = path.Path(filename1), path.Path(filename2)
44- assert path1.compare_recursive(path2, verbose=1)
45-
46- def test_verify(self, backup_options=[], restore_options=[]):
47- """Test that verify works in the basic case"""
48- self.runtest(["testfiles/dir1",
49- "testfiles/dir2"],
50- backup_options=backup_options,
51- restore_options=restore_options)
52-
53- # Test verify for various sub files
54- for filename, dir in [('new_file', 'dir2'),
55- ('executable', 'dir1')]:
56- self.verify('testfiles/%s/%s' % (dir, filename),
57- file_to_verify=filename, options=restore_options)
58-
59-# def test_verify_changed_source_file(self, backup_options=[], restore_options=[]):
60-# """Test verify gives no error if a source file is changed (without --compare-data)"""
61-# self.runtest(["testfiles/dir1",
62-# "testfiles/dir2"],
63-# backup_options=backup_options,
64-# restore_options=restore_options)
65-#
66-# # Edit source file for one of the files.
67-# f = open('testfiles/dir2/new_file', 'w')
68-# f.write('This changes a source file.')
69-#
70-# # Test verify for various sub files
71-# for filename, dir in [('new_file', 'dir2'),
72-# ('executable', 'dir1')]:
73-# self.verify('testfiles/%s/%s' % (dir, filename),
74-# file_to_verify=filename, options=restore_options)
75-
76- def test_verify_compare_data(self, backup_options=[], restore_options=[]):
77+ def test_verify(self):
78+ """Test that verify (without --compare-data) works in the basic case"""
79+ self.backup("full", "testfiles/various_file_types", options=[])
80+ self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options=[])
81+
82+ # def test_verify_changed_source_file(self):
83+ # """Test verify (without --compare-data) gives no error if a source file is changed"""
84+ # #TODO fix code to make this test pass (Bug #1354880)
85+ # self.backup("full", "testfiles/various_file_types", options=[])
86+ #
87+ # # Edit source file
88+ # f = open('testfiles/various_file_types/executable', 'w')
89+ # f.write('This changes a source file.')
90+ #
91+ # # Test verify for the file
92+ # self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options =[])
93+
94+ def test_verify_changed_source_file_adjust_mtime(self):
95+ """Test verify (without --compare-data) gives no error if a source file is changed and the mtime is changed
96+ (changing anything about the source files shouldn't matter)"""
97+
98+ # Get the atime and mtime of the file
99+ file_info = os.stat('testfiles/various_file_types/executable')
100+
101+ # Set the atime and mtime of the file to the time that we collected, as on some systems
102+ # the times from a stat call don't match what a utime will set.
103+ os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
104+
105+ self.backup("full", "testfiles/various_file_types", options=[])
106+
107+ # Edit source file
108+ f = open('testfiles/various_file_types/executable', 'w')
109+ f.write('This changes a source file.')
110+
111+ # Set the atime and mtime for the file back to what it was prior to the edit
112+ os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
113+
114+ # Test verify for the file
115+ self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options=[])
116+
117+ def test_verify_compare_data(self):
118 """Test that verify works in the basic case when the --compare-data option is used"""
119- self.runtest(["testfiles/dir1",
120- "testfiles/dir2"],
121- backup_options=backup_options,
122- restore_options=restore_options)
123-
124- # Test verify for various sub files with --compare-data
125- globals.compare_data = True
126- for filename, dir in [('new_file', 'dir2'),
127- ('executable', 'dir1')]:
128- self.verify('testfiles/%s/%s' % (dir, filename),
129- file_to_verify=filename, options=restore_options)
130-
131- def test_verify_compare_data_changed_source_file(self, backup_options=[], restore_options=[]):
132- """Test verify gives an error if a source file is changed (with --compare-data)"""
133- self.runtest(["testfiles/dir1",
134- "testfiles/dir2"],
135- backup_options=backup_options,
136- restore_options=restore_options)
137-
138- # Edit source file for one of the files.
139- f = open('testfiles/dir2/new_file', 'w')
140- f.write('This changes a source file.')
141-
142- # Test verify for edited file fails with --compare-data
143- globals.compare_data = True
144- for filename, dir in [('new_file', 'dir2'),
145- ('executable', 'dir1')]:
146- try:
147- self.verify('testfiles/%s/%s' % (dir, filename),
148- file_to_verify=filename, options=restore_options)
149- except CmdError as e:
150- self.assertEqual(e.exit_status, 1, str(e))
151+ self.backup("full", "testfiles/various_file_types", options=[])
152+
153+ # Test verify for the file with --compare-data
154+ self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
155+ options=["--compare-data"])
156+
157+ def test_verify_compare_data_changed_source_file(self):
158+ """Test verify with --compare-data gives an error if a source file is changed"""
159+ self.backup("full", "testfiles/various_file_types", options=[])
160+
161+ # Edit source file
162+ f = open('testfiles/various_file_types/executable', 'w')
163+ f.write('This changes a source file.')
164+
165+ # Test verify for edited file fails with --compare-data
166+ try:
167+ self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
168+ options=["--compare-data"])
169+ except CmdError as e:
170+ self.assertEqual(e.exit_status, 1, str(e))
171+ else:
172+ self.fail('Expected CmdError not thrown')
173+
174+ def test_verify_compare_data_changed_source_file_adjust_mtime(self):
175+ """Test verify with --compare-data gives an error if a source file is changed, even if the mtime is changed"""
176+
177+ # Get the atime and mtime of the file
178+ file_info = os.stat('testfiles/various_file_types/executable')
179+
180+ # Set the atime and mtime of the file to the time that we collected, as on some systems
181+ # the times from a stat call don't match what a utime will set
182+ os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
183+
184+ self.backup("full", "testfiles/various_file_types", options=[])
185+ # Edit source file
186+ f = open('testfiles/various_file_types/executable', 'w')
187+ f.write('This changes a source file.')
188+
189+ # Set the atime and mtime for the file back to what it was prior to the edit
190+ os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
191+
192+ # Test verify for edited file fails with --compare-data
193+ try:
194+ self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
195+ options=["--compare-data"])
196+ except CmdError as e:
197+ self.assertEqual(e.exit_status, 1, str(e))
198+ else:
199+ self.fail('Expected CmdError not thrown')
200
201 if __name__ == "__main__":
202 unittest.main()

Subscribers

People subscribed via source and target branches