tools/update-packaging/test_make_incremental_updates.py

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:9d70a7e3f606
1 #!/usr/bin/python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
6
7 import unittest
8 import make_incremental_updates as mkup
9 from make_incremental_updates import PatchInfo, MarFileEntry
10
11 class TestPatchInfo(unittest.TestCase):
12 def setUp(self):
13 self.work_dir = 'work_dir'
14 self.file_exclusion_list = ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files']
15 self.path_exclusion_list = ['/readme.txt']
16 self.patch_info = PatchInfo(self.work_dir, self.file_exclusion_list, self.path_exclusion_list)
17
18 def testPatchInfo(self):
19 self.assertEquals(self.work_dir, self.patch_info.work_dir)
20 self.assertEquals([], self.patch_info.archive_files)
21 self.assertEquals([], self.patch_info.manifestv2)
22 self.assertEquals([], self.patch_info.manifestv3)
23 self.assertEquals(self.file_exclusion_list, self.patch_info.file_exclusion_list)
24 self.assertEquals(self.path_exclusion_list, self.patch_info.path_exclusion_list)
25
26 def test_append_add_instruction(self):
27 self.patch_info.append_add_instruction('file.test')
28 self.assertEquals(['add "file.test"'], self.patch_info.manifestv2)
29 self.assertEquals(['add "file.test"'], self.patch_info.manifestv3)
30
31 def test_append_add_if_instruction(self):
32 self.patch_info.append_add_instruction('distribution/extensions/extension/file.test')
33 self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2)
34 self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3)
35
36 def test_append_add_if_not_instruction(self):
37 self.patch_info.append_add_if_not_instruction('file.test')
38 self.assertEquals([], self.patch_info.manifestv2)
39 self.assertEquals(['add-if-not "file.test" "file.test"'], self.patch_info.manifestv3)
40
41 def test_append_patch_instruction(self):
42 self.patch_info.append_patch_instruction('file.test', 'patchname')
43 self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv2)
44 self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv3)
45
46 def test_append_patch_if_instruction(self):
47 self.patch_info.append_patch_instruction('distribution/extensions/extension/file.test', 'patchname')
48 self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2)
49 self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3)
50
51 def test_append_remove_instruction(self):
52 self.patch_info.append_remove_instruction('file.test')
53 self.assertEquals(['remove "file.test"'], self.patch_info.manifestv2)
54 self.assertEquals(['remove "file.test"'], self.patch_info.manifestv3)
55
56 def test_append_rmdir_instruction(self):
57 self.patch_info.append_remove_instruction('dirtest/')
58 self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv2)
59 self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv3)
60
61 def test_append_rmrfdir_instruction(self):
62 self.patch_info.append_remove_instruction('dirtest/*')
63 self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv2)
64 self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv3)
65
66 """ FIXME touches the filesystem, need refactoring
67 def test_create_manifest_file(self):
68 self.patch_info.create_manifest_file()
69 """
70
71 def test_build_marfile_entry_hash(self):
72 self.assertEquals(({}, set([]), set([])), self.patch_info.build_marfile_entry_hash('root_path'))
73
74 """ FIXME touches the filesystem, need refactoring
75 class TestMarFileEntry(unittest.TestCase):
76 def setUp(self):
77 root_path = '.'
78 self.filename = 'file.test'
79 f = open(self.filename, 'w')
80 f.write('Test data\n')
81 f.close()
82 self.mar_file_entry = MarFileEntry(root_path, self.filename)
83
84 def test_calc_file_sha_digest(self):
85 f = open('test.sha', 'r')
86 goodSha = f.read()
87 f.close()
88 sha = self.mar_file_entry.calc_file_sha_digest(self.filename)
89 self.assertEquals(goodSha, sha)
90
91 def test_sha(self):
92 f = open('test.sha', 'r')
93 goodSha = f.read()
94 f.close()
95 sha = self.mar_file_entry.sha()
96 self.assertEquals(goodSha, sha)
97 """
98
99 class TestMakeIncrementalUpdates(unittest.TestCase):
100 def setUp(self):
101 work_dir = '.'
102 self.patch_info = PatchInfo(work_dir, ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'],['/readme.txt'])
103 root_path = '/'
104 filename = 'test.file'
105 self.mar_file_entry = MarFileEntry(root_path, filename)
106
107 """ FIXME makes direct shell calls, need refactoring
108 def test_exec_shell_cmd(self):
109 mkup.exec_shell_cmd('echo test')
110
111 def test_copy_file(self):
112 mkup.copy_file('src_file_abs_path', 'dst_file_abs_path')
113
114 def test_bzip_file(self):
115 mkup.bzip_file('filename')
116
117 def test_bunzip_file(self):
118 mkup.bunzip_file('filename')
119
120 def test_extract_mar(self):
121 mkup.extract_mar('filename', 'work_dir')
122
123 def test_create_partial_patch_for_file(self):
124 mkup.create_partial_patch_for_file('from_marfile_entry', 'to_marfile_entry', 'shas', self.patch_info)
125
126 def test_create_add_patch_for_file(self):
127 mkup.create_add_patch_for_file('to_marfile_entry', self.patch_info)
128
129 def test_process_explicit_remove_files(self):
130 mkup.process_explicit_remove_files('dir_path', self.patch_info)
131
132 def test_create_partial_patch(self):
133 mkup.create_partial_patch('from_dir_path', 'to_dir_path', 'patch_filename', 'shas', self.patch_info, 'forced_updates')
134
135 def test_create_partial_patches(patches):
136 mkup.create_partial_patches('patches')
137
138 """
139
140 """ FIXME touches the filesystem, need refactoring
141 def test_get_buildid(self):
142 mkup.get_buildid('work_dir', 'platform')
143 """
144
145 def test_decode_filename(self):
146 expected = {'locale': 'lang', 'platform': 'platform', 'product': 'product', 'version': '1.0', 'type': 'complete'}
147 self.assertEquals(expected, mkup.decode_filename('product-1.0.lang.platform.complete.mar'))
148 self.assertRaises(Exception, mkup.decode_filename, 'fail')
149
150 if __name__ == '__main__':
151 unittest.main()

mercurial