forked from mikf/gallery-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_postprocessor.py
743 lines (584 loc) · 22.9 KB
/
test_postprocessor.py
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2019-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
import os
import sys
import unittest
from unittest.mock import Mock, mock_open, patch
import logging
import zipfile
import tempfile
import collections
from datetime import datetime
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from gallery_dl import extractor, output, path # noqa E402
from gallery_dl import postprocessor, config # noqa E402
from gallery_dl.postprocessor.common import PostProcessor # noqa E402
class MockPostprocessorModule(Mock):
__postprocessor__ = "mock"
class FakeJob():
def __init__(self, extr=extractor.find("generic:https://example.org/")):
extr.directory_fmt = ("{category}",)
self.extractor = extr
self.pathfmt = path.PathFormat(extr)
self.out = output.NullOutput()
self.get_logger = logging.getLogger
self.hooks = collections.defaultdict(list)
def register_hooks(self, hooks, options):
for hook, callback in hooks.items():
self.hooks[hook].append(callback)
class TestPostprocessorModule(unittest.TestCase):
def setUp(self):
postprocessor._cache.clear()
def test_find(self):
for name in (postprocessor.modules):
cls = postprocessor.find(name)
self.assertEqual(cls.__name__, name.capitalize() + "PP")
self.assertIs(cls.__base__, PostProcessor)
self.assertEqual(postprocessor.find("foo"), None)
self.assertEqual(postprocessor.find(1234) , None)
self.assertEqual(postprocessor.find(None) , None)
@patch("builtins.__import__")
def test_cache(self, import_module):
import_module.return_value = MockPostprocessorModule()
for name in (postprocessor.modules):
postprocessor.find(name)
self.assertEqual(import_module.call_count, len(postprocessor.modules))
# no new calls to import_module
for name in (postprocessor.modules):
postprocessor.find(name)
self.assertEqual(import_module.call_count, len(postprocessor.modules))
class BasePostprocessorTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dir = tempfile.TemporaryDirectory()
config.set((), "base-directory", cls.dir.name)
cls.job = FakeJob()
@classmethod
def tearDownClass(cls):
cls.dir.cleanup()
config.clear()
def tearDown(self):
self.job.hooks.clear()
def _create(self, options=None, data=None):
kwdict = {"category": "test", "filename": "file", "extension": "ext"}
if options is None:
options = {}
if data is not None:
kwdict.update(data)
self.pathfmt = self.job.pathfmt
self.pathfmt.set_directory(kwdict)
self.pathfmt.set_filename(kwdict)
self.pathfmt.build_path()
pp = postprocessor.find(self.__class__.__name__[:-4].lower())
return pp(self.job, options)
def _trigger(self, events=None):
for event in (events or ("prepare", "file")):
for callback in self.job.hooks[event]:
callback(self.pathfmt)
class ClassifyTest(BasePostprocessorTest):
def test_classify_default(self):
pp = self._create()
self.assertEqual(pp.mapping, {
ext: directory
for directory, exts in pp.DEFAULT_MAPPING.items()
for ext in exts
})
self.pathfmt.set_extension("jpg")
self.pathfmt.build_path()
pp.prepare(self.pathfmt)
path = os.path.join(self.dir.name, "test", "Pictures")
self.assertEqual(self.pathfmt.path, path + "/file.jpg")
self.assertEqual(self.pathfmt.realpath, path + "/file.jpg")
with patch("os.makedirs") as mkdirs:
self._trigger()
mkdirs.assert_called_once_with(path, exist_ok=True)
def test_classify_noop(self):
pp = self._create()
rp = self.pathfmt.realpath
pp.prepare(self.pathfmt)
self.assertEqual(self.pathfmt.path, rp)
self.assertEqual(self.pathfmt.realpath, rp)
with patch("os.makedirs") as mkdirs:
self._trigger()
self.assertEqual(mkdirs.call_count, 0)
def test_classify_custom(self):
pp = self._create({"mapping": {
"foo/bar": ["foo", "bar"],
}})
self.assertEqual(pp.mapping, {
"foo": "foo/bar",
"bar": "foo/bar",
})
self.pathfmt.set_extension("foo")
self.pathfmt.build_path()
pp.prepare(self.pathfmt)
path = os.path.join(self.dir.name, "test", "foo", "bar")
self.assertEqual(self.pathfmt.path, path + "/file.foo")
self.assertEqual(self.pathfmt.realpath, path + "/file.foo")
with patch("os.makedirs") as mkdirs:
self._trigger()
mkdirs.assert_called_once_with(path, exist_ok=True)
class ExecTest(BasePostprocessorTest):
def test_command_string(self):
self._create({
"command": "echo {} {_path} {_directory} {_filename} && rm {};",
})
with patch("gallery_dl.util.Popen") as p:
i = Mock()
i.wait.return_value = 0
p.return_value = i
self._trigger(("after",))
p.assert_called_once_with(
"echo {0} {0} {1} {2} && rm {0};".format(
self.pathfmt.realpath,
self.pathfmt.realdirectory,
self.pathfmt.filename),
shell=True)
i.wait.assert_called_once_with()
def test_command_list(self):
self._create({
"command": ["~/script.sh", "{category}",
"\fE _directory.upper()"],
})
with patch("gallery_dl.util.Popen") as p:
i = Mock()
i.wait.return_value = 0
p.return_value = i
self._trigger(("after",))
p.assert_called_once_with(
[
os.path.expanduser("~/script.sh"),
self.pathfmt.kwdict["category"],
self.pathfmt.realdirectory.upper(),
],
shell=False,
)
def test_command_returncode(self):
self._create({
"command": "echo {}",
})
with patch("gallery_dl.util.Popen") as p:
i = Mock()
i.wait.return_value = 123
p.return_value = i
with self.assertLogs() as log:
self._trigger(("after",))
msg = ("WARNING:postprocessor.exec:'echo {}' returned with "
"non-zero exit status (123)".format(self.pathfmt.realpath))
self.assertEqual(log.output[0], msg)
def test_async(self):
self._create({
"async" : True,
"command": "echo {}",
})
with patch("gallery_dl.util.Popen") as p:
i = Mock()
p.return_value = i
self._trigger(("after",))
self.assertTrue(p.called)
self.assertFalse(i.wait.called)
class MetadataTest(BasePostprocessorTest):
def test_metadata_default(self):
pp = self._create()
# default arguments
self.assertEqual(pp.write , pp._write_json)
self.assertEqual(pp.extension, "json")
self.assertTrue(callable(pp._json_encode))
def test_metadata_json(self):
pp = self._create({
"mode" : "json",
"extension" : "JSON",
}, {
"public" : "hello ワールド",
"_private" : "foo バー",
})
self.assertEqual(pp.write , pp._write_json)
self.assertEqual(pp.extension, "JSON")
self.assertTrue(callable(pp._json_encode))
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realpath + ".JSON"
m.assert_called_once_with(path, "w", encoding="utf-8")
if sys.hexversion >= 0x3060000:
# python 3.4 & 3.5 have random order without 'sort: True'
self.assertEqual(self._output(m), """{
"category": "test",
"filename": "file",
"extension": "ext",
"public": "hello ワールド"
}
""")
def test_metadata_json_options(self):
pp = self._create({
"mode" : "json",
"ascii" : True,
"sort" : True,
"separators": [",", " : "],
"private" : True,
"indent" : None,
"open" : "a",
"encoding" : "UTF-8",
"extension" : "JSON",
}, {
"public" : "hello ワールド",
"_private" : "foo バー",
})
self.assertEqual(pp.write , pp._write_json)
self.assertEqual(pp.extension, "JSON")
self.assertTrue(callable(pp._json_encode))
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realpath + ".JSON"
m.assert_called_once_with(path, "a", encoding="UTF-8")
self.assertEqual(self._output(m), """{\
"_private" : "foo \\u30d0\\u30fc",\
"category" : "test",\
"extension" : "ext",\
"filename" : "file",\
"public" : "hello \\u30ef\\u30fc\\u30eb\\u30c9"}
""")
def test_metadata_tags(self):
pp = self._create(
{"mode": "tags"},
{"tags": ["foo", "bar", "baz"]},
)
self.assertEqual(pp.write, pp._write_tags)
self.assertEqual(pp.extension, "txt")
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realpath + ".txt"
m.assert_called_once_with(path, "w", encoding="utf-8")
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
def test_metadata_tags_split_1(self):
self._create(
{"mode": "tags"},
{"tags": "foo, bar, baz"},
)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
def test_metadata_tags_split_2(self):
self._create(
{"mode": "tags"},
{"tags": "foobar1 foobar2 foobarbaz"},
)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "foobar1\nfoobar2\nfoobarbaz\n")
def test_metadata_tags_tagstring(self):
self._create(
{"mode": "tags"},
{"tag_string": "foo, bar, baz"},
)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
def test_metadata_tags_dict(self):
self._create(
{"mode": "tags"},
{"tags": {"g": ["foobar1", "foobar2"], "m": ["foobarbaz"]}},
)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "foobar1\nfoobar2\nfoobarbaz\n")
def test_metadata_tags_list_of_dict(self):
self._create(
{"mode": "tags"},
{"tags": [
{"g": "foobar1", "m": "foobar2", "u": True},
{"g": None, "m": "foobarbaz", "u": [3, 4]},
]},
)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "foobar1\nfoobar2\nfoobarbaz\n")
def test_metadata_custom(self):
def test(pp_info):
pp = self._create(pp_info, {"foo": "bar"})
self.assertEqual(pp.write, pp._write_custom)
self.assertEqual(pp.extension, "txt")
self.assertTrue(pp._content_fmt)
with patch("builtins.open", mock_open()) as m:
self._trigger()
self.assertEqual(self._output(m), "bar\nNone\n")
self.job.hooks.clear()
test({"mode": "custom", "content-format": "{foo}\n{missing}\n"})
test({"mode": "custom", "content-format": ["{foo}", "{missing}"]})
test({"mode": "custom", "format": "{foo}\n{missing}\n"})
test({"format": "{foo}\n{missing}\n"})
def test_metadata_extfmt(self):
pp = self._create({
"extension" : "ignored",
"extension-format": "json",
})
self.assertEqual(pp._filename, pp._filename_extfmt)
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realdirectory + "file.json"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_extfmt_2(self):
self._create({
"extension-format": "{extension!u}-data:{category:Res/ES/}",
})
self.pathfmt.prefix = "2."
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realdirectory + "file.2.EXT-data:tESt"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_directory(self):
self._create({
"directory": "metadata",
})
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realdirectory + "metadata/file.ext.json"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_directory_2(self):
self._create({
"directory" : "metadata////",
"extension-format": "json",
})
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realdirectory + "metadata/file.json"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_filename(self):
self._create({
"filename" : "{category}_{filename}_/meta/\n\r.data",
"extension-format": "json",
})
with patch("builtins.open", mock_open()) as m:
self._trigger()
path = self.pathfmt.realdirectory + "test_file__meta_.data"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_stdout(self):
self._create({"filename": "-", "indent": None, "sort": True})
with patch("sys.stdout", Mock()) as m:
self._trigger()
self.assertEqual(self._output(m), """\
{"category": "test", "extension": "ext", "filename": "file"}
""")
def test_metadata_modify(self):
kwdict = {"foo": 0, "bar": {"bax": 1, "bay": 2, "baz": 3, "ba2": {}}}
self._create({
"mode": "modify",
"fields": {
"foo" : "{filename}-{foo!s}",
"foo2" : "\fE bar['bax'] + 122",
"bar[\"baz\"]" : "{_now}",
"bar['ba2'][a]": "test",
},
}, kwdict)
pdict = self.pathfmt.kwdict
self.assertIsNot(kwdict, pdict)
self.assertEqual(pdict["foo"], kwdict["foo"])
self.assertEqual(pdict["bar"], kwdict["bar"])
self._trigger()
self.assertEqual(pdict["foo"] , "file-0")
self.assertEqual(pdict["foo2"], 123)
self.assertEqual(pdict["bar"]["ba2"]["a"], "test")
self.assertIsInstance(pdict["bar"]["baz"], datetime)
def test_metadata_delete(self):
kwdict = {
"foo": 0,
"bar": {
"bax": 1,
"bay": 2,
"baz": {"a": 3, "b": 4},
},
}
self._create({
"mode": "delete",
"fields": ["foo", "bar['bax']", "bar[\"baz\"][a]"],
}, kwdict)
pdict = self.pathfmt.kwdict
self.assertIsNot(kwdict, pdict)
self.assertEqual(pdict["foo"], kwdict["foo"])
self.assertEqual(pdict["bar"], kwdict["bar"])
self._trigger()
self.assertNotIn("foo", pdict)
self.assertNotIn("bax", pdict["bar"])
self.assertNotIn("a", pdict["bar"]["baz"])
# no errors for deleted/undefined fields
self._trigger()
self.assertNotIn("foo", pdict)
self.assertNotIn("bax", pdict["bar"])
self.assertNotIn("a", pdict["bar"]["baz"])
def test_metadata_option_skip(self):
self._create({"skip": True})
with patch("builtins.open", mock_open()) as m, \
patch("os.path.exists") as e:
e.return_value = True
self._trigger()
self.assertTrue(e.called)
self.assertTrue(not m.called)
self.assertTrue(not len(self._output(m)))
with patch("builtins.open", mock_open()) as m, \
patch("os.path.exists") as e:
e.return_value = False
self._trigger()
self.assertTrue(e.called)
self.assertTrue(m.called)
self.assertGreater(len(self._output(m)), 0)
path = self.pathfmt.realdirectory + "file.ext.json"
m.assert_called_once_with(path, "w", encoding="utf-8")
def test_metadata_option_skip_false(self):
self._create({"skip": False})
with patch("builtins.open", mock_open()) as m, \
patch("os.path.exists") as e:
self._trigger()
self.assertTrue(not e.called)
self.assertTrue(m.called)
@staticmethod
def _output(mock):
return "".join(
call[1][0]
for call in mock.mock_calls
if call[0].endswith("write")
)
class MtimeTest(BasePostprocessorTest):
def test_mtime_datetime(self):
self._create(None, {"date": datetime(1980, 1, 1)})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
def test_mtime_timestamp(self):
self._create(None, {"date": 315532800})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
def test_mtime_none(self):
self._create(None, {"date": None})
self._trigger()
self.assertNotIn("_mtime", self.pathfmt.kwdict)
def test_mtime_undefined(self):
self._create(None, {})
self._trigger()
self.assertNotIn("_mtime", self.pathfmt.kwdict)
def test_mtime_key(self):
self._create({"key": "foo"}, {"foo": 315532800})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
def test_mtime_value(self):
self._create({"value": "{foo}"}, {"foo": 315532800})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
class PythonTest(BasePostprocessorTest):
def test_module(self):
path = os.path.join(self.dir.name, "module.py")
self._write_module(path)
sys.path.insert(0, self.dir.name)
try:
self._create({"function": "module:calc"}, {"_value": 123})
finally:
del sys.path[0]
self.assertNotIn("_result", self.pathfmt.kwdict)
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_result"], 246)
def test_path(self):
path = os.path.join(self.dir.name, "module.py")
self._write_module(path)
self._create({"function": path + ":calc"}, {"_value": 12})
self.assertNotIn("_result", self.pathfmt.kwdict)
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_result"], 24)
def _write_module(self, path):
with open(path, "w") as fp:
fp.write("""
def calc(kwdict):
kwdict["_result"] = kwdict["_value"] * 2
""")
class ZipTest(BasePostprocessorTest):
def test_zip_default(self):
pp = self._create()
self.assertEqual(self.job.hooks["file"][0], pp.write_fast)
self.assertEqual(pp.path, self.pathfmt.realdirectory[:-1])
self.assertEqual(pp.delete, True)
self.assertEqual(pp.args, (
pp.path + ".zip", "a", zipfile.ZIP_STORED, True,
))
self.assertTrue(pp.args[0].endswith("/test.zip"))
def test_zip_safe(self):
pp = self._create({"mode": "safe"})
self.assertEqual(self.job.hooks["file"][0], pp.write_safe)
self.assertEqual(pp.path, self.pathfmt.realdirectory[:-1])
self.assertEqual(pp.delete, True)
self.assertEqual(pp.args, (
pp.path + ".zip", "a", zipfile.ZIP_STORED, True,
))
self.assertTrue(pp.args[0].endswith("/test.zip"))
def test_zip_options(self):
pp = self._create({
"keep-files": True,
"compression": "zip",
"extension": "cbz",
})
self.assertEqual(pp.delete, False)
self.assertEqual(pp.args, (
pp.path + ".cbz", "a", zipfile.ZIP_DEFLATED, True,
))
self.assertTrue(pp.args[0].endswith("/test.cbz"))
def test_zip_write(self):
with tempfile.NamedTemporaryFile("w", dir=self.dir.name) as file:
pp = self._create({"files": [file.name, "_info_.json"],
"keep-files": True})
filename = os.path.basename(file.name)
file.write("foobar\n")
# write dummy file with 3 different names
for i in range(3):
name = "file{}.ext".format(i)
self.pathfmt.temppath = file.name
self.pathfmt.filename = name
self._trigger()
nti = pp.zfile.NameToInfo
self.assertEqual(len(nti), i+2)
self.assertIn(name, nti)
# check file contents
self.assertEqual(len(nti), 4)
self.assertIn("file0.ext", nti)
self.assertIn("file1.ext", nti)
self.assertIn("file2.ext", nti)
self.assertIn(filename, nti)
# write the last file a second time (will be skipped)
self._trigger()
self.assertEqual(len(pp.zfile.NameToInfo), 4)
# close file
self._trigger(("finalize",))
# reopen to check persistence
with zipfile.ZipFile(pp.zfile.filename) as file:
nti = file.NameToInfo
self.assertEqual(len(pp.zfile.NameToInfo), 4)
self.assertIn("file0.ext", nti)
self.assertIn("file1.ext", nti)
self.assertIn("file2.ext", nti)
self.assertIn(filename, nti)
os.unlink(pp.zfile.filename)
def test_zip_write_mock(self):
def side_effect(_, name):
pp.zfile.NameToInfo.add(name)
pp = self._create()
pp.zfile = Mock()
pp.zfile.NameToInfo = set()
pp.zfile.write.side_effect = side_effect
# write 3 files
for i in range(3):
self.pathfmt.temppath = self.pathfmt.realdirectory + "file.ext"
self.pathfmt.filename = "file{}.ext".format(i)
self._trigger()
# write the last file a second time (should be skipped)
self._trigger()
# close file
self._trigger(("finalize",))
self.assertEqual(pp.zfile.write.call_count, 3)
for call in pp.zfile.write.call_args_list:
args, kwargs = call
self.assertEqual(len(args), 2)
self.assertEqual(len(kwargs), 0)
self.assertEqual(args[0], self.pathfmt.temppath)
self.assertRegex(args[1], r"file\d\.ext")
self.assertEqual(pp.zfile.close.call_count, 1)
if __name__ == "__main__":
unittest.main()