diff options
Diffstat (limited to 'test/test_postprocessor.py')
| -rw-r--r-- | test/test_postprocessor.py | 86 |
1 files changed, 73 insertions, 13 deletions
diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index 5d52e1d..e4d01c2 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -78,6 +78,7 @@ class BasePostprocessorTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.dir = tempfile.TemporaryDirectory() + config.clear() config.set((), "base-directory", cls.dir.name) cls.job = FakeJob() @@ -374,6 +375,40 @@ class ExecTest(BasePostprocessorTest): m_aa.assert_called_once_with(self.pathfmt.kwdict) m_ac.assert_called_once() + def test_verbose_string(self): + self._create({ + "command": "echo foo bar", + "verbose": False, + }) + + with patch("gallery_dl.util.Popen") as p, \ + self.assertLogs(level=10) as log_info: + i = Mock() + i.wait.return_value = 123 + p.return_value = i + self._trigger(("after",)) + + msg = "DEBUG:postprocessor.exec:Running 'echo'" + self.assertEqual(log_info.output[0], msg) + self.assertIn("'echo' returned with non-zero ", log_info.output[1]) + + def test_verbose_list(self): + self._create({ + "command": ["echo", "foo", "bar"], + "verbose": False, + }) + + with patch("gallery_dl.util.Popen") as p, \ + self.assertLogs(level=10) as log_info: + i = Mock() + i.wait.return_value = 123 + p.return_value = i + self._trigger(("after",)) + + msg = "DEBUG:postprocessor.exec:Running 'echo'" + self.assertEqual(log_info.output[0], msg) + self.assertIn("'echo' returned with non-zero ", log_info.output[1]) + class HashTest(BasePostprocessorTest): @@ -453,7 +488,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realpath}.JSON" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) self.assertEqual(self._output(m), """{ "category": "test", @@ -473,6 +508,7 @@ class MetadataTest(BasePostprocessorTest): "indent" : None, "open" : "a", "encoding" : "UTF-8", + "newline" : "\r\n", "extension" : "JSON", }, { "public" : "hello ワールド", @@ -487,7 +523,9 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realpath}.JSON" - m.assert_called_once_with(path, "a", encoding="UTF-8") + m.assert_called_once_with(path, "a", encoding="UTF-8", newline='\r\n') + # Since we mocked the call to open, + # we don't actually see the effect of setting newline. self.assertEqual(self._output(m), """{\ "_private" : "foo \\u30d0\\u30fc",\ "category" : "test",\ @@ -508,7 +546,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realpath}.txt" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) self.assertEqual(self._output(m), "foo\nbar\nbaz\n") def test_metadata_tags_split_1(self): @@ -599,7 +637,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}file.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_extfmt_2(self): self._create({ @@ -611,7 +649,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}file.2.EXT-data:tESt" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_directory(self): self._create({ @@ -622,7 +660,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}metadata/file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_directory_2(self): self._create({ @@ -634,7 +672,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}metadata/file.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_directory_format(self): self._create( @@ -646,7 +684,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}../json/12500/file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_directory_empty(self): self._create( @@ -657,7 +695,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}./file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_basedirectory(self): self._create({"base-directory": True}) @@ -666,7 +704,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.basedirectory}file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_basedirectory_custom(self): self._create({ @@ -678,7 +716,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = "/home/test/meta/file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_filename(self): self._create({ @@ -690,7 +728,7 @@ class MetadataTest(BasePostprocessorTest): self._trigger() path = f"{self.pathfmt.realdirectory}test_file__meta_.data" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_meta_path(self): self._create({ @@ -790,7 +828,7 @@ class MetadataTest(BasePostprocessorTest): self.assertGreater(len(self._output(m)), 0) path = f"{self.pathfmt.realdirectory}file.ext.json" - m.assert_called_once_with(path, "w", encoding="utf-8") + m.assert_called_once_with(path, "w", encoding="utf-8", newline=None) def test_metadata_option_skip_false(self): self._create({"skip": False}) @@ -802,6 +840,28 @@ class MetadataTest(BasePostprocessorTest): self.assertTrue(not e.called) self.assertTrue(m.called) + def test_metadata_option_newline(self): + self._create({ + "newline": "\r\n", + "filename" : "data.json", + "directory" : "", + "base-directory": self.dir.name, + }) + + self._trigger() + + path = os.path.join(self.dir.name, "data.json") + with open(path, newline="") as fp: + content = fp.read() + + self.assertEqual(content, """\ +{\r\n\ + "category": "test",\r\n\ + "filename": "file",\r\n\ + "extension": "ext"\r\n\ +}\r\n\ +""") + def test_metadata_option_include(self): self._create( {"include": ["_private", "filename", "foo"], "sort": True}, |
