diff options
| author | 2023-07-03 00:57:09 -0400 | |
|---|---|---|
| committer | 2023-07-03 00:57:09 -0400 | |
| commit | 3a93cde3966897be5924ee1de7b4e044d02c7b5d (patch) | |
| tree | 201f838ff418278c49b54b9e967afd8d67b621a2 /test/test_postprocessor.py | |
| parent | 9b5645cc3e880ed2219bfd3842d6947ca989ad99 (diff) | |
| parent | ef30b1fa552fd4ceebdd14bbcc16f30f430883f8 (diff) | |
Update upstream source from tag 'upstream/1.25.7'
Update to upstream version '1.25.7'
with Debian dir 4760b04a98c58821dc7db0f3d75c73f5f395ad73
Diffstat (limited to 'test/test_postprocessor.py')
| -rw-r--r-- | test/test_postprocessor.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index ac89b55..554a51e 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -164,6 +164,76 @@ class ClassifyTest(BasePostprocessorTest): mkdirs.assert_called_once_with(path, exist_ok=True) +class ExecTest(BasePostprocessorTest): + + def test_command_string(self): + self._create({ + "command": "echo {} && rm {};", + }) + + with patch("subprocess.Popen") as p: + i = Mock() + i.wait.return_value = 0 + p.return_value = i + self._trigger(("after",)) + + p.assert_called_once_with( + "echo {0} && rm {0};".format(self.pathfmt.realpath), shell=True) + i.wait.assert_called_once_with() + + def test_command_list(self): + self._create({ + "command": ["~/script.sh", "{category}", + "\fE _directory.upper()"], + }) + + with patch("subprocess.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("subprocess.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("subprocess.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): |
