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
=== modified file 'testing/functional/test_verify.py'
--- testing/functional/test_verify.py 2014-12-17 20:29:09 +0000
+++ testing/functional/test_verify.py 2014-12-18 01:52:23 +0000
@@ -23,8 +23,6 @@
23import os23import os
24import unittest24import unittest
2525
26from duplicity import path
27from duplicity import globals
28from . import CmdError, FunctionalTestCase26from . import CmdError, FunctionalTestCase
2927
3028
@@ -32,99 +30,97 @@
32 """30 """
33 Test verify using duplicity binary31 Test verify using duplicity binary
34 """32 """
35 def runtest(self, dirlist, backup_options=[], restore_options=[]):33 def test_verify(self):
36 """Run backup/restore test on directories in dirlist34 """Test that verify (without --compare-data) works in the basic case"""
37 This is identical to test_final.runtest"""35 self.backup("full", "testfiles/various_file_types", options=[])
38 assert len(dirlist) >= 136 self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options=[])
3937
40 # Back up directories to local backend38 # def test_verify_changed_source_file(self):
41 current_time = 10000039 # """Test verify (without --compare-data) gives no error if a source file is changed"""
42 self.backup("full", dirlist[0], current_time=current_time,40 # #TODO fix code to make this test pass (Bug #1354880)
43 options=backup_options)41 # self.backup("full", "testfiles/various_file_types", options=[])
44 for new_dir in dirlist[1:]:42 #
45 current_time += 10000043 # # Edit source file
46 self.backup("inc", new_dir, current_time=current_time,44 # f = open('testfiles/various_file_types/executable', 'w')
47 options=backup_options)45 # f.write('This changes a source file.')
4846 #
49 # Restore each and compare them47 # # Test verify for the file
50 for i in range(len(dirlist)):48 # self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options =[])
51 dirname = dirlist[i]49
52 current_time = 100000 * (i + 1)50 def test_verify_changed_source_file_adjust_mtime(self):
53 self.restore(time=current_time, options=restore_options)51 """Test verify (without --compare-data) gives no error if a source file is changed and the mtime is changed
54 self.check_same(dirname, "testfiles/restore_out")52 (changing anything about the source files shouldn't matter)"""
55 self.verify(dirname,53
56 time=current_time, options=restore_options)54 # Get the atime and mtime of the file
5755 file_info = os.stat('testfiles/various_file_types/executable')
58 def check_same(self, filename1, filename2):56
59 """Verify two filenames are the same57 # Set the atime and mtime of the file to the time that we collected, as on some systems
60 This is identical to test_final.check_same"""58 # the times from a stat call don't match what a utime will set.
61 path1, path2 = path.Path(filename1), path.Path(filename2)59 os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
62 assert path1.compare_recursive(path2, verbose=1)60
6361 self.backup("full", "testfiles/various_file_types", options=[])
64 def test_verify(self, backup_options=[], restore_options=[]):62
65 """Test that verify works in the basic case"""63 # Edit source file
66 self.runtest(["testfiles/dir1",64 f = open('testfiles/various_file_types/executable', 'w')
67 "testfiles/dir2"],65 f.write('This changes a source file.')
68 backup_options=backup_options,66
69 restore_options=restore_options)67 # Set the atime and mtime for the file back to what it was prior to the edit
7068 os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
71 # Test verify for various sub files69
72 for filename, dir in [('new_file', 'dir2'),70 # Test verify for the file
73 ('executable', 'dir1')]:71 self.verify('testfiles/various_file_types/executable', file_to_verify='executable', options=[])
74 self.verify('testfiles/%s/%s' % (dir, filename),72
75 file_to_verify=filename, options=restore_options)73 def test_verify_compare_data(self):
76
77# def test_verify_changed_source_file(self, backup_options=[], restore_options=[]):
78# """Test verify gives no error if a source file is changed (without --compare-data)"""
79# self.runtest(["testfiles/dir1",
80# "testfiles/dir2"],
81# backup_options=backup_options,
82# restore_options=restore_options)
83#
84# # Edit source file for one of the files.
85# f = open('testfiles/dir2/new_file', 'w')
86# f.write('This changes a source file.')
87#
88# # Test verify for various sub files
89# for filename, dir in [('new_file', 'dir2'),
90# ('executable', 'dir1')]:
91# self.verify('testfiles/%s/%s' % (dir, filename),
92# file_to_verify=filename, options=restore_options)
93
94 def test_verify_compare_data(self, backup_options=[], restore_options=[]):
95 """Test that verify works in the basic case when the --compare-data option is used"""74 """Test that verify works in the basic case when the --compare-data option is used"""
96 self.runtest(["testfiles/dir1",75 self.backup("full", "testfiles/various_file_types", options=[])
97 "testfiles/dir2"],76
98 backup_options=backup_options,77 # Test verify for the file with --compare-data
99 restore_options=restore_options)78 self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
10079 options=["--compare-data"])
101 # Test verify for various sub files with --compare-data80
102 globals.compare_data = True81 def test_verify_compare_data_changed_source_file(self):
103 for filename, dir in [('new_file', 'dir2'),82 """Test verify with --compare-data gives an error if a source file is changed"""
104 ('executable', 'dir1')]:83 self.backup("full", "testfiles/various_file_types", options=[])
105 self.verify('testfiles/%s/%s' % (dir, filename),84
106 file_to_verify=filename, options=restore_options)85 # Edit source file
10786 f = open('testfiles/various_file_types/executable', 'w')
108 def test_verify_compare_data_changed_source_file(self, backup_options=[], restore_options=[]):87 f.write('This changes a source file.')
109 """Test verify gives an error if a source file is changed (with --compare-data)"""88
110 self.runtest(["testfiles/dir1",89 # Test verify for edited file fails with --compare-data
111 "testfiles/dir2"],90 try:
112 backup_options=backup_options,91 self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
113 restore_options=restore_options)92 options=["--compare-data"])
11493 except CmdError as e:
115 # Edit source file for one of the files.94 self.assertEqual(e.exit_status, 1, str(e))
116 f = open('testfiles/dir2/new_file', 'w')95 else:
117 f.write('This changes a source file.')96 self.fail('Expected CmdError not thrown')
11897
119 # Test verify for edited file fails with --compare-data98 def test_verify_compare_data_changed_source_file_adjust_mtime(self):
120 globals.compare_data = True99 """Test verify with --compare-data gives an error if a source file is changed, even if the mtime is changed"""
121 for filename, dir in [('new_file', 'dir2'),100
122 ('executable', 'dir1')]:101 # Get the atime and mtime of the file
123 try:102 file_info = os.stat('testfiles/various_file_types/executable')
124 self.verify('testfiles/%s/%s' % (dir, filename),103
125 file_to_verify=filename, options=restore_options)104 # Set the atime and mtime of the file to the time that we collected, as on some systems
126 except CmdError as e:105 # the times from a stat call don't match what a utime will set
127 self.assertEqual(e.exit_status, 1, str(e))106 os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
107
108 self.backup("full", "testfiles/various_file_types", options=[])
109 # Edit source file
110 f = open('testfiles/various_file_types/executable', 'w')
111 f.write('This changes a source file.')
112
113 # Set the atime and mtime for the file back to what it was prior to the edit
114 os.utime('testfiles/various_file_types/executable', (file_info.st_atime, file_info.st_mtime))
115
116 # Test verify for edited file fails with --compare-data
117 try:
118 self.verify('testfiles/various_file_types/executable', file_to_verify='executable',
119 options=["--compare-data"])
120 except CmdError as e:
121 self.assertEqual(e.exit_status, 1, str(e))
122 else:
123 self.fail('Expected CmdError not thrown')
128124
129if __name__ == "__main__":125if __name__ == "__main__":
130 unittest.main()126 unittest.main()

Subscribers

People subscribed via source and target branches