File: 0003-tests-move-test-file-to-something-easily-detected-by.patch

package info (click to toggle)
unrardll 0.1.7%2Bds-10
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 10,724 kB
  • sloc: python: 510; cpp: 422; makefile: 6
file content (396 lines) | stat: -rw-r--r-- 15,592 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
From: Eli Schwartz <eschwartz93@gmail.com>
Date: Mon, 23 Oct 2023 00:09:44 -0400
Subject: tests: move test file to something easily detected by unittest

Forwarded: not-needed

Due to setuptools' deprecation of direct, command-line invocation of
`python setup.py XXX`, the ecosystem has been moving towards a complex,
laborious, unpredictable collection of hand-rolled routines for
performing end-to-end integration of python software.

Wheels are built using frontends (not setuptools, apparently) that don't
consistently accept the same arguments setup.py does, but there are
various hacks to make that hopefully work anyway.

The main issue is running the testsuite. There are no standards for
running a testsuite, and no reliable entrypoints other than "run pytest
or `python -m unittest` and pray". Of course, this only works if you
define manual PYTHONPATHs, or else explicitly don't but install the
module *first*. We are sort of forced to do this anyway, because
wheels... however, unrardll cannot be detected by unittest/pytest
because they expect test implementation files to be named "test*.py".

Rename basic.py to start with the recommended name. The direct `setup.py
test` command still works, as it iterates over all test/*.py files
regardless of name and manually reads tests from those files.

This allows a workflow of:
- build unrardll however you like
- expose it to the python command
- run `python -m unittest`
---
 test/basic.py      | 173 -----------------------------------------------------
 test/test_basic.py | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 173 insertions(+), 173 deletions(-)
 delete mode 100644 test/basic.py
 create mode 100644 test/test_basic.py

diff --git a/test/basic.py b/test/basic.py
deleted file mode 100644
index 46596af..0000000
--- a/test/basic.py
+++ /dev/null
@@ -1,173 +0,0 @@
-#!/usr/bin/env python2
-# vim:fileencoding=utf-8
-# License: BSD Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
-
-from __future__ import absolute_import, division, print_function, unicode_literals
-
-import hashlib
-import os
-import unicodedata
-import unittest
-from binascii import crc32
-
-from unrardll import (
-    BadPassword, PasswordRequired, comment, extract, extract_member, extract_members, headers, names,
-    open_archive, unrar, make_long_path_useable
-)
-
-from . import TempDir, TestCase, base
-
-multipart_rar = os.path.join(base, 'example_split_archive.part1.rar')
-password_rar = os.path.join(base, 'example_password_protected.rar')
-simple_rar = os.path.join(base, 'simple.rar')
-if os.sep == '\\':
-    prefix = '\\\\?\\'
-    multipart_rar = prefix + os.path.abspath(multipart_rar)
-    password_rar = prefix + os.path.abspath(password_rar)
-    simple_rar = prefix + os.path.abspath(simple_rar)
-sr_data = {
-    '1': b'',
-    '1/sub-one': b'sub-one\n',
-    '2': b'',
-    '2/sub-two.txt': b'sub-two\n',
-    'Füße.txt': b'unicode\n',
-    'max-compressed': b'max\n',
-    'one.txt': b'one\n',
-    'symlink': b'sub-two',
-    'uncompressed': b'uncompressed\n',
-    '诶比屁.txt': b'chinese unicode\n'}
-
-
-def normalize(x):
-    return unicodedata.normalize('NFC', x)
-
-
-def get_memory():
-    'Return memory usage in bytes'
-    # See https://pythonhosted.org/psutil/#psutil.Process.memory_info
-    try:
-        import psutil
-    except ImportError:
-        raise unittest.SkipTest('psutil is not available')
-    return psutil.Process(os.getpid()).memory_info().rss
-
-
-def memory(since=0.0):
-    'Return memory used in MB. The value of since is subtracted from the used memory'
-    ans = get_memory()
-    ans /= float(1024**2)
-    return ans - since
-
-
-class BasicTests(TestCase):
-
-    def test_names(self):
-        all_names = [
-            '1/sub-one', 'one.txt', '诶比屁.txt', 'Füße.txt', '2/sub-two.txt',
-            'symlink', '1', '2', 'uncompressed', 'max-compressed']
-        self.ae(all_names, list(names(simple_rar)))
-        all_names.remove('symlink'), all_names.remove('1'), all_names.remove('2')
-        self.ae(all_names, list(names(simple_rar, only_useful=True)))
-
-    def test_comment(self):
-        self.ae(comment(simple_rar), 'some comment\n')
-        self.ae(comment(password_rar), '')
-
-    def test_share_open(self):
-        with open(simple_rar, 'rb') as f:
-            self.ae(comment(simple_rar), 'some comment\n')
-            f.close()
-
-    def test_extract(self):
-        for v in (True, False):
-            with TempDir() as tdir:
-                tdir = os.path.join(tdir, 'a' * 250)
-                os.makedirs(make_long_path_useable(tdir))
-                extract(simple_rar, tdir, verify_data=v)
-                h = {
-                    normalize(os.path.abspath(os.path.join(tdir, h['filename']))): h
-                    for h in headers(simple_rar)}
-                data = {}
-                for dirpath, dirnames, filenames in os.walk(tdir):
-                    for f in filenames:
-                        path = normalize(os.path.join(dirpath, f))
-                        data[os.path.relpath(path, tdir).replace(os.sep, '/')] = d = open(path, 'rb').read()
-                        if f == 'one.txt':
-                            self.ae(os.path.getmtime(path), 1098472879)
-                        self.ae(h[path]['unpack_size'], len(d))
-                        self.ae(h[path]['file_crc'] & 0xffffffff, crc32(d) & 0xffffffff)
-            q = {k: v for k, v in sr_data.items() if v}
-            del q['symlink']
-            self.ae(data, q)
-
-    def test_password(self):
-        with TempDir() as tdir:
-            self.assertRaises(PasswordRequired, extract, password_rar, tdir)
-            self.assertRaises(BadPassword, extract, password_rar, tdir, password='sfasgsfdg')
-            extract(password_rar, tdir, password='example')
-
-    def test_invalid_callback(self):
-        class Callback(object):
-            pass
-        with open_archive(simple_rar, None, mode=unrar.RAR_OM_EXTRACT) as f:
-            unrar.read_next_header(f)
-            self.assertRaisesRegex(unrar.UNRARError, "An exception occurred in the password callback handler", unrar.process_file, f)
-        c = Callback()
-        c._process_data = lambda x: None
-        with open_archive(simple_rar, c, mode=unrar.RAR_OM_EXTRACT) as f:
-            unrar.read_next_header(f)
-            self.assertRaisesRegex(unrar.UNRARError,  "Processing canceled by the callback", unrar.process_file, f)
-
-    def test_multipart(self):
-        self.ae(list(names(multipart_rar)), ['Fifteen_Feet_of_Time.pdf'])
-        for v in (True, False):
-            with TempDir() as tdir:
-                extract(multipart_rar, tdir, verify_data=v)
-                h = next(headers(multipart_rar))
-                raw = open(os.path.join(tdir, h['filename']), 'rb').read()
-                self.ae(len(raw), h['unpack_size'])
-                self.ae(hashlib.sha1(raw).hexdigest(), 'a9fc6a11d000044f17fcdf65816348ce0be3b145')
-
-    def test_extract_member(self):
-        self.ae(extract_member(simple_rar, lambda h: h['filename'] == 'one.txt', verify_data=True), ('one.txt', sr_data['one.txt']))
-        self.ae(extract_member(simple_rar, lambda h: False), (None, None))
-
-    def test_extract_members(self):
-        data = {'one.txt': b'', 'uncompressed': b''}
-        current = ''
-        def callback(x):
-            nonlocal current
-            if isinstance(x, dict):
-                current = x['filename']
-                return x['filename'] in data
-            if isinstance(x, bytes):
-                data[current] += x
-                return
-            self.assertTrue(x, 'Verification failed for: ' + current)
-        extract_members(simple_rar, callback, verify_data=True)
-        self.assertEqual(data, {k:sr_data[k] for k in data})
-
-    def test_open_failure(self):
-        self.assertRaises(OSError, extract, 'sdfgsfgsggsdfg.rar', '.')
-
-    def test_memory_leaks(self):
-        import gc
-
-        def collect():
-            for i in range(6):
-                gc.collect()
-            gc.collect()
-
-        with TempDir() as tdir:
-
-            def get_mem_use(num):
-                collect()
-                start = memory()
-                for i in range(num):
-                    extract(simple_rar, tdir)
-                collect()
-                return max(0, memory(start))
-
-            get_mem_use(5)  # ensure no memory used by get_mem_use itself is counted
-            a, b = get_mem_use(10), get_mem_use(100)
-        self.assertTrue(a == 0 or b/a < 3, '10 times usage: {} 100 times usage: {}'.format(a, b))
diff --git a/test/test_basic.py b/test/test_basic.py
new file mode 100644
index 0000000..46596af
--- /dev/null
+++ b/test/test_basic.py
@@ -0,0 +1,173 @@
+#!/usr/bin/env python2
+# vim:fileencoding=utf-8
+# License: BSD Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
+
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+import hashlib
+import os
+import unicodedata
+import unittest
+from binascii import crc32
+
+from unrardll import (
+    BadPassword, PasswordRequired, comment, extract, extract_member, extract_members, headers, names,
+    open_archive, unrar, make_long_path_useable
+)
+
+from . import TempDir, TestCase, base
+
+multipart_rar = os.path.join(base, 'example_split_archive.part1.rar')
+password_rar = os.path.join(base, 'example_password_protected.rar')
+simple_rar = os.path.join(base, 'simple.rar')
+if os.sep == '\\':
+    prefix = '\\\\?\\'
+    multipart_rar = prefix + os.path.abspath(multipart_rar)
+    password_rar = prefix + os.path.abspath(password_rar)
+    simple_rar = prefix + os.path.abspath(simple_rar)
+sr_data = {
+    '1': b'',
+    '1/sub-one': b'sub-one\n',
+    '2': b'',
+    '2/sub-two.txt': b'sub-two\n',
+    'Füße.txt': b'unicode\n',
+    'max-compressed': b'max\n',
+    'one.txt': b'one\n',
+    'symlink': b'sub-two',
+    'uncompressed': b'uncompressed\n',
+    '诶比屁.txt': b'chinese unicode\n'}
+
+
+def normalize(x):
+    return unicodedata.normalize('NFC', x)
+
+
+def get_memory():
+    'Return memory usage in bytes'
+    # See https://pythonhosted.org/psutil/#psutil.Process.memory_info
+    try:
+        import psutil
+    except ImportError:
+        raise unittest.SkipTest('psutil is not available')
+    return psutil.Process(os.getpid()).memory_info().rss
+
+
+def memory(since=0.0):
+    'Return memory used in MB. The value of since is subtracted from the used memory'
+    ans = get_memory()
+    ans /= float(1024**2)
+    return ans - since
+
+
+class BasicTests(TestCase):
+
+    def test_names(self):
+        all_names = [
+            '1/sub-one', 'one.txt', '诶比屁.txt', 'Füße.txt', '2/sub-two.txt',
+            'symlink', '1', '2', 'uncompressed', 'max-compressed']
+        self.ae(all_names, list(names(simple_rar)))
+        all_names.remove('symlink'), all_names.remove('1'), all_names.remove('2')
+        self.ae(all_names, list(names(simple_rar, only_useful=True)))
+
+    def test_comment(self):
+        self.ae(comment(simple_rar), 'some comment\n')
+        self.ae(comment(password_rar), '')
+
+    def test_share_open(self):
+        with open(simple_rar, 'rb') as f:
+            self.ae(comment(simple_rar), 'some comment\n')
+            f.close()
+
+    def test_extract(self):
+        for v in (True, False):
+            with TempDir() as tdir:
+                tdir = os.path.join(tdir, 'a' * 250)
+                os.makedirs(make_long_path_useable(tdir))
+                extract(simple_rar, tdir, verify_data=v)
+                h = {
+                    normalize(os.path.abspath(os.path.join(tdir, h['filename']))): h
+                    for h in headers(simple_rar)}
+                data = {}
+                for dirpath, dirnames, filenames in os.walk(tdir):
+                    for f in filenames:
+                        path = normalize(os.path.join(dirpath, f))
+                        data[os.path.relpath(path, tdir).replace(os.sep, '/')] = d = open(path, 'rb').read()
+                        if f == 'one.txt':
+                            self.ae(os.path.getmtime(path), 1098472879)
+                        self.ae(h[path]['unpack_size'], len(d))
+                        self.ae(h[path]['file_crc'] & 0xffffffff, crc32(d) & 0xffffffff)
+            q = {k: v for k, v in sr_data.items() if v}
+            del q['symlink']
+            self.ae(data, q)
+
+    def test_password(self):
+        with TempDir() as tdir:
+            self.assertRaises(PasswordRequired, extract, password_rar, tdir)
+            self.assertRaises(BadPassword, extract, password_rar, tdir, password='sfasgsfdg')
+            extract(password_rar, tdir, password='example')
+
+    def test_invalid_callback(self):
+        class Callback(object):
+            pass
+        with open_archive(simple_rar, None, mode=unrar.RAR_OM_EXTRACT) as f:
+            unrar.read_next_header(f)
+            self.assertRaisesRegex(unrar.UNRARError, "An exception occurred in the password callback handler", unrar.process_file, f)
+        c = Callback()
+        c._process_data = lambda x: None
+        with open_archive(simple_rar, c, mode=unrar.RAR_OM_EXTRACT) as f:
+            unrar.read_next_header(f)
+            self.assertRaisesRegex(unrar.UNRARError,  "Processing canceled by the callback", unrar.process_file, f)
+
+    def test_multipart(self):
+        self.ae(list(names(multipart_rar)), ['Fifteen_Feet_of_Time.pdf'])
+        for v in (True, False):
+            with TempDir() as tdir:
+                extract(multipart_rar, tdir, verify_data=v)
+                h = next(headers(multipart_rar))
+                raw = open(os.path.join(tdir, h['filename']), 'rb').read()
+                self.ae(len(raw), h['unpack_size'])
+                self.ae(hashlib.sha1(raw).hexdigest(), 'a9fc6a11d000044f17fcdf65816348ce0be3b145')
+
+    def test_extract_member(self):
+        self.ae(extract_member(simple_rar, lambda h: h['filename'] == 'one.txt', verify_data=True), ('one.txt', sr_data['one.txt']))
+        self.ae(extract_member(simple_rar, lambda h: False), (None, None))
+
+    def test_extract_members(self):
+        data = {'one.txt': b'', 'uncompressed': b''}
+        current = ''
+        def callback(x):
+            nonlocal current
+            if isinstance(x, dict):
+                current = x['filename']
+                return x['filename'] in data
+            if isinstance(x, bytes):
+                data[current] += x
+                return
+            self.assertTrue(x, 'Verification failed for: ' + current)
+        extract_members(simple_rar, callback, verify_data=True)
+        self.assertEqual(data, {k:sr_data[k] for k in data})
+
+    def test_open_failure(self):
+        self.assertRaises(OSError, extract, 'sdfgsfgsggsdfg.rar', '.')
+
+    def test_memory_leaks(self):
+        import gc
+
+        def collect():
+            for i in range(6):
+                gc.collect()
+            gc.collect()
+
+        with TempDir() as tdir:
+
+            def get_mem_use(num):
+                collect()
+                start = memory()
+                for i in range(num):
+                    extract(simple_rar, tdir)
+                collect()
+                return max(0, memory(start))
+
+            get_mem_use(5)  # ensure no memory used by get_mem_use itself is counted
+            a, b = get_mem_use(10), get_mem_use(100)
+        self.assertTrue(a == 0 or b/a < 3, '10 times usage: {} 100 times usage: {}'.format(a, b))