[pp:classify] rewrite & simplify (#5213)
Do not manually build paths, which get later overwritten by
pathfmt.build_path() anyway. Just update the target directory and let
the rest of the "path logic" handle it.
Fixes skipping previously downloaded and categorized files,
which was broken since 8124c16a50
This commit is contained in:
@@ -120,30 +120,37 @@ class ClassifyTest(BasePostprocessorTest):
|
||||
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)
|
||||
self.assertEqual(pp.directory, "")
|
||||
self._trigger(("post",))
|
||||
self.assertEqual(pp.directory, self.pathfmt.directory)
|
||||
|
||||
self.pathfmt.set_extension("jpg")
|
||||
self._trigger(("prepare",))
|
||||
self.pathfmt.build_path()
|
||||
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)
|
||||
self.pathfmt.set_extension("mp4")
|
||||
self._trigger(("prepare",))
|
||||
self.pathfmt.build_path()
|
||||
path = os.path.join(self.dir.name, "test", "Video")
|
||||
self.assertEqual(self.pathfmt.path, path + "/file.mp4")
|
||||
self.assertEqual(self.pathfmt.realpath, path + "/file.mp4")
|
||||
|
||||
def test_classify_noop(self):
|
||||
pp = self._create()
|
||||
rp = self.pathfmt.realpath
|
||||
|
||||
pp.prepare(self.pathfmt)
|
||||
self.assertEqual(pp.directory, "")
|
||||
self._trigger(("post",))
|
||||
self._trigger(("prepare",))
|
||||
|
||||
self.assertEqual(pp.directory, self.pathfmt.directory)
|
||||
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"],
|
||||
@@ -153,18 +160,18 @@ class ClassifyTest(BasePostprocessorTest):
|
||||
"foo": "foo/bar",
|
||||
"bar": "foo/bar",
|
||||
})
|
||||
self.pathfmt.set_extension("foo")
|
||||
self.pathfmt.build_path()
|
||||
|
||||
pp.prepare(self.pathfmt)
|
||||
self.assertEqual(pp.directory, "")
|
||||
self._trigger(("post",))
|
||||
self.assertEqual(pp.directory, self.pathfmt.directory)
|
||||
|
||||
self.pathfmt.set_extension("foo")
|
||||
self._trigger(("prepare",))
|
||||
self.pathfmt.build_path()
|
||||
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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user