Browse code

* run-tests.py: Improved testsuite, added parameters support to run only specified tests, cleaned up win/posix integration.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@298 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/12/29 13:41:56
Showing 4 changed files
... ...
@@ -1,5 +1,10 @@
1 1
 2008-12-29  Michal Ludvig  <michal@logix.cz>
2 2
 
3
+	* run-tests.py: Improved testsuite, added parameters support
4
+	  to run only specified tests, cleaned up win/posix integration.
5
+
6
+2008-12-29  Michal Ludvig  <michal@logix.cz>
7
+
3 8
 	* s3cmd, run-tests.py: Make it work on Windows.
4 9
 
5 10
 2008-12-26  Michal Ludvig  <michal@logix.cz>
... ...
@@ -13,6 +13,21 @@ from subprocess import Popen, PIPE, STDOUT
13 13
 
14 14
 count_pass = 0
15 15
 count_fail = 0
16
+count_skip = 0
17
+
18
+test_counter = 0
19
+run_tests = []
20
+exclude_tests = []
21
+
22
+if os.name == "posix":
23
+	have_unicode = True
24
+	have_wget = True
25
+elif os.name == "nt":
26
+	have_unicode = False
27
+	have_wget = False
28
+else:
29
+	print "Unknown platform: %s" % os.name
30
+	sys.exit(1)
16 31
 
17 32
 def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [], must_find_re = [], must_not_find_re = []):
18 33
 	def failure(message = ""):
... ...
@@ -34,6 +49,13 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [],
34 34
 		print "\x1b[32;1mOK\x1b[0m%s" % (message)
35 35
 		count_pass += 1
36 36
 		return 0
37
+	def skip(message = ""):
38
+		global count_skip
39
+		if message:
40
+			message = "  (%s)" % message
41
+		print "\x1b[33;1mSKIP\x1b[0m%s" % (message)
42
+		count_skip += 1
43
+		return 0
37 44
 	def compile_list(_list, regexps = False):
38 45
 		if type(_list) not in [ list, tuple ]:
39 46
 			_list = [_list]
... ...
@@ -41,11 +63,16 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [],
41 41
 		if regexps == False:
42 42
 			_list = [re.escape(item.encode("utf-8")) for item in _list]
43 43
 
44
-		return [re.compile(item) for item in _list]
45
-	
46
-	print (label + " ").ljust(30, "."),
44
+		return [re.compile(item, re.MULTILINE) for item in _list]
45
+
46
+	global test_counter
47
+	test_counter += 1
48
+	print ("%3d  %s " % (test_counter, label)).ljust(30, "."),
47 49
 	sys.stdout.flush()
48 50
 
51
+	if run_tests.count(test_counter) == 0 or exclude_tests.count(test_counter) > 0:
52
+		return skip()
53
+
49 54
 	p = Popen(cmd_args, stdout = PIPE, stderr = STDOUT, universal_newlines = True)
50 55
 	stdout, stderr = p.communicate()
51 56
 	if retcode != p.returncode:
... ...
@@ -82,104 +109,202 @@ def test_s3cmd(label, cmd_args = [], **kwargs):
82 82
 
83 83
 	return test(label, cmd_args, **kwargs)
84 84
 
85
+def test_mkdir(label, dir_name):
86
+	if os.name in ("posix", "nt"):
87
+		cmd = ['mkdir']
88
+	else:
89
+		print "Unknown platform: %s" % os.name
90
+		sys.exit(1)
91
+	cmd.append(dir_name)
92
+	return test(label, cmd)
93
+
94
+def test_rmdir(label, dir_name):
95
+	if os.path.isdir(dir_name):
96
+		if os.name == "posix":
97
+			cmd = ['rm', '-rf']
98
+		elif os.name == "nt":
99
+			cmd = ['rmdir', '/s/q']
100
+		else:
101
+			print "Unknown platform: %s" % os.name
102
+			sys.exit(1)
103
+		cmd.append(dir_name)
104
+		return test(label, cmd)
105
+
106
+
107
+argv = sys.argv[1:]
108
+while argv:
109
+	arg = argv.pop(0)
110
+	if arg in ("-h", "--help"):
111
+		print "%s A B K..O -N" % sys.argv[0]
112
+		print "Run tests number A, B and K through to O, except for N"
113
+		sys.exit(0)
114
+	if arg in ("-l", "--list"):
115
+		exclude_tests = range(0, 999)
116
+		break
117
+	if arg.find("..") >= 0:
118
+		range_idx = arg.find("..")
119
+		range_start = arg[:range_idx] or 0
120
+		range_end = arg[range_idx+2:] or 999
121
+		run_tests.extend(range(int(range_start), int(range_end) + 1))
122
+	elif arg.startswith("-"):
123
+		exclude_tests.append(int(arg[1:]))
124
+	else:
125
+		run_tests.append(int(arg))
126
+
127
+if not run_tests:
128
+	run_tests = range(0, 999)
129
+
130
+## ====== Remove test buckets
85 131
 test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'],
86 132
 	must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed",
87 133
 		      "Bucket 's3://s3cmd-autotest-2/' removed",
88 134
 		      "Bucket 's3://s3cmd-Autotest-3/' removed" ])
89 135
 
136
+
137
+## ====== Create one bucket (EU)
90 138
 test_s3cmd("Create one bucket (EU)", ['mb', '--bucket-location=EU', 's3://s3cmd-autotest-1'], 
91 139
 	must_find = "Bucket 's3://s3cmd-autotest-1/' created")
92 140
 
141
+
142
+
143
+## ====== Create multiple buckets
93 144
 test_s3cmd("Create multiple buckets", ['mb', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'], 
94 145
 	must_find = [ "Bucket 's3://s3cmd-autotest-2/' created", "Bucket 's3://s3cmd-Autotest-3/' created" ])
95 146
 
147
+
148
+## ====== Invalid bucket name
96 149
 test_s3cmd("Invalid bucket name", ["mb", "--bucket-location=EU", "s3://s3cmd-Autotest-EU"], 
97 150
 	retcode = 1,
98 151
 	must_find = "ERROR: Parameter problem: Bucket name 's3cmd-Autotest-EU' contains disallowed character", 
99 152
 	must_not_find_re = "Bucket.*created")
100 153
 
154
+
155
+## ====== Buckets list
101 156
 test_s3cmd("Buckets list", ["ls"], 
102 157
 	must_find = [ "autotest-1", "autotest-2", "Autotest-3" ], must_not_find_re = "Autotest-EU")
103 158
 
104
-if os.name != "nt":
105
-	## Full testsuite - POSIX (Unix, Linux, ...)
159
+
160
+## ====== Sync to S3
161
+if have_unicode:
106 162
 	test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt'])
163
+else:
164
+	test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--exclude', 'unicode/*', '--no-encrypt'])
107 165
 
108
-	test_s3cmd("List bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
109
-		must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/unicode/$" ],
110
-		must_not_find = [ u"ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
111 166
 
112
-	test_s3cmd("List bucket recursive", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
113
-		must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5",
114
-		              u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ],
115
-		must_not_find = [ "logo.png" ])
167
+## ====== List bucket content
168
+must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/binary/$", u"D s3://s3cmd-autotest-1/xyz/etc/$" ]
169
+must_not_find = [ u"random-crap.md5", u".svn" ]
170
+if have_unicode:
171
+	must_find_re.append(u"D s3://s3cmd-autotest-1/xyz/unicode/$")
172
+	must_not_find.append(u"ŪņЇЌœđЗ/☺ unicode € rocks ™")
173
+test_s3cmd("List bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
174
+	must_find_re = must_find_re,
175
+	must_not_find = must_not_find)
116 176
 
117
-	# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
118 177
 
119
-	test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
120
-		must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
178
+## ====== List bucket recursive
179
+must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5" ]
180
+if have_unicode:
181
+	must_find.append(u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™")
182
+test_s3cmd("List bucket recursive", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
183
+	must_find = must_find,
184
+	must_not_find = [ "logo.png" ])
121 185
 
122
-	test("Removing local target", ['rm', '-rf', 'testsuite-out'])
186
+## ====== FIXME
187
+# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
123 188
 
124
-	test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
125
-		must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
126 189
 
127
-	test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
128
-		must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
190
+## ====== Put public, guess MIME
191
+test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
192
+	must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
129 193
 
130
-	test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])
131 194
 
132
-else:
133
-	## Reduced testsuite - Windows NT+
134
-	test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--exclude', 'unicode/*', '--no-encrypt'])
195
+## ====== rmdir local
196
+test_rmdir("Removing local target", 'testsuite-out')
135 197
 
136
-	test_s3cmd("Check bucket content (-r)", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
137
-		must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5" ],
138
-		must_not_find = [ "logo.png" ])
139 198
 
140
-	test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
141
-		must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/binary/$" ],
142
-		must_not_find = [ u"random-crap.md5" ])
199
+## ====== Sync from S3
200
+must_find = [ "stored as testsuite-out/etc/logo.png " ]
201
+if have_unicode:
202
+	must_find.append(u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™")
203
+test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
204
+	must_find = must_find)
143 205
 
144
-	test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
145
-		must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
146 206
 
147
-	if os.path.isdir("testsuite-out"):
148
-		test("Removing local target", ['rmdir', '/s/q', 'testsuite-out'])
207
+## ====== Retrieve from URL
208
+if have_wget:
209
+	test("Retrieve from URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
210
+		must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
211
+
149 212
 
150
-	test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
151
-		must_find = [ "stored as testsuite-out/etc/logo.png " ])
213
+## ====== Sync more to S3
214
+test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])
152 215
 
153
-## Common for POSIX and Win32
216
+
217
+## ====== Rename within S3
154 218
 test_s3cmd("Rename within S3", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
155 219
 	must_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ])
156 220
 
221
+
222
+## ====== Rename (NoSuchKey)
157 223
 test_s3cmd("Rename (NoSuchKey)", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
158 224
 	retcode = 1,
159 225
 	must_find_re = [ 'ERROR:.*NoSuchKey' ],
160 226
 	must_not_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ])
161 227
 
228
+
229
+## ====== Make dst dir for get
230
+test_rmdir("Remove dst dir for get", "testsuite-out")
231
+
232
+
233
+## ====== Get multiple files
234
+test_s3cmd("Get multiple files", ['get', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG', 's3://s3cmd-autotest-1/xyz/etc/AtomicClockRadio.ttf', 'testsuite-out'],
235
+	retcode = 1,
236
+	must_find = [ 'Destination must be a directory when downloading multiple sources.' ])
237
+
238
+
239
+## ====== Make dst dir for get
240
+test_mkdir("Make dst dir for get", "testsuite-out")
241
+
242
+
243
+## ====== Get multiple files
244
+test_s3cmd("Get multiple files", ['get', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG', 's3://s3cmd-autotest-1/xyz/etc/AtomicClockRadio.ttf', 'testsuite-out'],
245
+	must_find = [ u"saved as 'testsuite-out/Logo.PNG'", u"saved as 'testsuite-out/AtomicClockRadio.ttf'" ])
246
+
247
+
248
+## ====== Sync more from S3
162 249
 test_s3cmd("Sync more from S3", ['sync', '--delete-removed', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
163 250
 	must_find = [ "deleted 'testsuite-out/etc/logo.png'", "stored as testsuite-out/etc2/Logo.PNG (22059 bytes", 
164 251
 	              "stored as testsuite-out/.svn/format " ],
165
-	must_not_find = [ "not-deleted etc/logo.png" ])
252
+	must_not_find_re = [ "not-deleted.*etc/logo.png" ])
166 253
 
254
+
255
+## ====== Copy between buckets
167 256
 test_s3cmd("Copy between buckets", ['cp', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG', 's3://s3cmd-Autotest-3'],
168 257
 	must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG copied to s3://s3cmd-Autotest-3/xyz/etc2/Logo.PNG" ])
169 258
 
259
+
260
+## ====== Simple delete
170 261
 test_s3cmd("Simple delete", ['del', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
171 262
 	must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG deleted" ])
172 263
 
173
-if os.name != "nt":
174
-	test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
175
-		must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ])
176 264
 
265
+## ====== Recursive delete
266
+test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
267
+	must_find_re = [ "Object.*\.svn/format deleted" ])
268
+
269
+
270
+## ====== Recursive delete all
177 271
 test_s3cmd("Recursive delete all", ['del', '--recursive', '--force', 's3://s3cmd-autotest-1'],
178 272
 	must_find_re = [ "Object.*binary/random-crap deleted" ])
179 273
 
274
+
275
+## ====== Remove empty bucket
180 276
 test_s3cmd("Remove empty bucket", ['rb', 's3://s3cmd-autotest-1'],
181 277
 	must_find = [ "Bucket 's3://s3cmd-autotest-1/' removed" ])
182 278
 
279
+
280
+## ====== Remove remaining buckets
183 281
 test_s3cmd("Remove remaining buckets", ['rb', '--recursive', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'],
184 282
 	must_find = [ "Bucket 's3://s3cmd-autotest-2/' removed",
185 283
 		      "Bucket 's3://s3cmd-Autotest-3/' removed" ])
186 284
new file mode 100644
187 285
Binary files /dev/null and b/testsuite/etc/AtomicClockRadio.ttf differ
188 286
new file mode 100644
189 287
Binary files /dev/null and b/testsuite/etc/TypeRa.ttf differ