annotate test_gcp.py @ 61:67385805ae48

updated version number & changelog
author Goffi <goffi@goffi.org>
date Mon, 20 Jun 2011 14:30:45 +0200
parents 40ec9445060a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
5 gcp: Goffi's CoPier
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
7
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
12
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
17
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
21
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from __future__ import with_statement
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import tempfile
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import unittest
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
25 from os import getcwd, chdir, system, mkdir, makedirs, listdir
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
26 from os.path import join, isdir
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from shutil import rmtree
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from random import randrange
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from hashlib import sha1
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
30
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
31 #size shorcuts
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
32 S10K = 1024 * 10
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
33 S100K = 1024 * 100
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
34 S1M = 1024 * 1024
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
35 S10M = 1024 * 1024 * 10
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
36 S100M = 1024 * 1024 * 100
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
37
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
38
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def sha1sum(filename, buf_size=4096):
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
40 """Return the SHA1 hash of a file
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
41 @param filename: path to the file
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
42 @param buf_size: size of the buffer to use for calculation"""
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
43 csum = sha1()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
44 with open(filename) as fd:
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
45 data = fd.read(buf_size)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
46 while data:
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
47 csum.update(data)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
48 data = fd.read(buf_size)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
49 return csum.digest()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
50
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
51 def dirCheck(dir_path):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
52 """Recursively calculate SHA1 sum of a dir
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
53 @param path: path of the dir to check
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
54 @return: a dict in the form [{filepath: sum,...}]
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
55 """
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
56 def recursive_sum(directory, result):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
57 for current_path in listdir(directory):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
58 full_path = join(directory, current_path)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
59 if isdir(full_path):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
60 recursive_sum(full_path, result)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
61 else:
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
62 result[full_path] = sha1sum(full_path)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
63
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
64 result = {}
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
65 _ori_dir = getcwd()
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
66 chdir(dir_path)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
67 recursive_sum(".", result)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
68 chdir(_ori_dir)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
69 return result
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
70
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
71 #def makeRandomFile(path, size, buf_size=4096):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
72 # """Create a fake file
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
73 # @param path: where the file is created
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
74 # @param size: size of the file to create in bytes"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
75 # def seq(size):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
76 # return ''.join(chr(randrange(256)) for i in range(size))
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
77 # fd = open(path, 'w')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
78 # for byte in range(size//buf_size):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
79 # fd.write(seq(buf_size))
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
80 # fd.write(seq(size%buf_size))
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
81 # fd.close()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
82
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
83 def makeRandomFile(path, size=S10K, buf_size=4096):
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """Create a fake file using /dev/urandom
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
85 @param path: where the file must be created
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
86 @param size: size of the file to create in bytes"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
87 source = open('/dev/urandom','r')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
88 dest = open(path, 'w')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
89 for byte in range(size//buf_size):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
90 dest.write(source.read(buf_size))
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
91 dest.write(source.read(size%buf_size))
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
92 dest.close()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
93
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
94 def makeTestDir(path):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
95 """Helper method to easily create a test dir
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
96 @param path: where the dir must be created"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
97
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
98 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
99 subdir = join(path,'subdir_%d' % i)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
100 makedirs(subdir)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
101 for j in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
102 makeRandomFile(join(subdir, 'file_%d' % j), S10K)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
103 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
104 makeRandomFile(join(path,'file_%d' % i), S10K)
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
105
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
106 class TestCopyCases(unittest.TestCase):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
107 """Test basic copy use cases, using gcp externally
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
108 gcp must be available in the PATH"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
109 #TODO: check journal
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
110
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def setUp(self):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.ori_dir = getcwd()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.tmp_dir = tempfile.mkdtemp()
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
114 chdir(self.tmp_dir)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
115
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def tearDown(self):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
117 chdir(self.ori_dir)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
118 rmtree(self.tmp_dir)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
119
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def test_one_file_copy(self):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
121 """Copy one file and test the result"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
122 makeRandomFile('file_1', S10K)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
123 ori_sum = sha1sum('file_1')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
124 ret = system("gcp file_1 file_2")
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.assertEqual(ret,0)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
126 dest_sum = sha1sum('file_2')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self.assertEqual(ori_sum, dest_sum)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
128
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
129 def test_one_file_copy_already_exists(self):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
130 """Check that an existing file is not overwritten"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
131 makeRandomFile('file_1', S10K)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
132 makeRandomFile('file_2', S10K)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
133 file_2_sum = sha1sum('file_2')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
134 ret = system("gcp file_1 file_2")
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
135 self.assertNotEqual(ret,0)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
136 file_2_sum_bis = sha1sum('file_2')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self.assertEqual(file_2_sum, file_2_sum_bis)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
138
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def test_one_file_copy_already_exists_force(self):
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
140 """Check that an existing file is overwritten with --force"""
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
141 makeRandomFile('file_1', S10K)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
142 makeRandomFile('file_2', S10K)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
143 file_1_sum = sha1sum('file_1')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
144 ret = system("gcp -f file_1 file_2")
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.assertEqual(ret,0)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
146 file_2_sum_bis = sha1sum('file_2')
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.assertEqual(file_1_sum, file_2_sum_bis)
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
148
60
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
149 def test_one_dir_copy(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
150 """Check copy of one dir to a non existant path"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
151 makeTestDir('dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
152 check_1 = dirCheck('dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
153 ret = system("gcp -r dir_1 dir_2")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
154 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
155 check_2 = dirCheck('dir_2')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
156 self.assertEqual(check_1, check_2)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
157
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
158 def test_one_dir_copy_nocopy(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
159 """Check that a dir is not copied without the recursive option"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
160 makeTestDir('dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
161 check_before = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
162 ret = system("gcp dir_1 dir_2")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
163 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
164 check_after = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
165 self.assertEqual(check_before, check_after)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
166
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
167 def test_one_dir_copy_existing_dest(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
168 """Check that a dir is copied inside an existing destination"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
169 makeTestDir('dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
170 mkdir('dir_2')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
171 check_1 = dirCheck('dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
172 ret = system("gcp -r dir_1 dir_2")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
173 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
174 self.assertEqual(listdir('dir_2'), ['dir_1'])
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
175 check_2 = dirCheck('dir_2/dir_1')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
176 self.assertEqual(check_1, check_2)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
177
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
178 def test_mixt_copy_existing_dest(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
179 """Check that a mixt copy (files + dir) to an existing dest work as expected"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
180 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
181 makeRandomFile('file_%d' % i, S10K)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
182 makeTestDir('dir_%d' % i)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
183 check_1 = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
184 mkdir('dest_dir')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
185 ret = system("gcp -r file_0 file_1 dir_0 dir_1 dest_dir")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
186 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
187 check_2 = dirCheck('dest_dir')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
188 self.assertEqual(check_1, check_2)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
189
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
190 def test_mixt_copy_nonexisting_dest(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
191 """Check that a mixt copy (files + dir) to an non existing dest work as expected
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
192 /!\\ the behavious is different of the one of cp in this case ! (cp doesn't copy at all, while gcp create the dest)"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
193 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
194 makeRandomFile('file_%d' % i, S10K)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
195 makeTestDir('dir_%d' % i)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
196 check_1 = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
197 ret = system("gcp -r file_0 file_1 dir_0 dir_1 dest_dir")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
198 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
199 check_2 = dirCheck('dest_dir')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
200 self.assertEqual(check_1, check_2)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
201
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
202 def test_mixt_copy_existing_dest_nonrecursive(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
203 """Check that a mixt copy (files + dir) to an existing dest without the recursive option work as expected"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
204 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
205 makeRandomFile('file_%d' % i, S10K)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
206 makeTestDir('dir_%d' % i)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
207 mkdir('dest_dir')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
208 ret = system("gcp file_0 file_1 dir_0 dir_1 dest_dir")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
209 self.assertEqual(ret,0)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
210 self.assertEqual(set(listdir('dest_dir')), set(['file_0', 'file_1']))
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
211 self.assertEqual(sha1sum('file_0'), sha1sum('dest_dir/file_0'))
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
212 self.assertEqual(sha1sum('file_1'), sha1sum('dest_dir/file_1'))
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
213
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
214 def test_mixt_copy_nonexisting_dest_nonrecursive(self):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
215 """Check that a mixt copy (files + dir) to an existing dest without the recursive option work as expected"""
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
216 for i in range(2):
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
217 makeRandomFile('file_%d' % i, S10K)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
218 makeTestDir('dir_%d' % i)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
219 check_before = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
220 ret = system("gcp file_0 file_1 dir_0 dir_1 dest_dir")
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
221 self.assertEqual(ret >> 8, 1)
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
222 check_after = dirCheck('.')
40ec9445060a added test suit
Goffi <goffi@goffi.org>
parents: 57
diff changeset
223 self.assertEqual(check_before, check_after)
57
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
224
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
225 if __name__ == '__main__':
d4f1235c860b Test suit
Goffi <goffi@goffi.org>
parents:
diff changeset
226 unittest.main()