diff options
author | Michał Górny <mgorny@gentoo.org> | 2020-09-05 17:49:35 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2020-09-05 17:49:35 +0200 |
commit | f51119d8c9e65dfd1f48f5669eafb072fb15af1c (patch) | |
tree | 3003bc1303b7a169d1d67934fdfbe0f7bb5ed3e4 | |
parent | 61c3f0a91582ad337bbaeea06472f23816478ce8 (diff) | |
download | gemato-f51119d8c9e65dfd1f48f5669eafb072fb15af1c.tar.gz |
Do not call signal.strsignal() when not available (py<3.8)
Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r-- | gemato/cli.py | 8 | ||||
-rw-r--r-- | tests/test_openpgp.py | 11 |
2 files changed, 15 insertions, 4 deletions
diff --git a/gemato/cli.py b/gemato/cli.py index 22b19f7..8b28b5e 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -589,8 +589,12 @@ class GnuPGWrapCommand(VerifyingOpenPGPMixin, GematoCommand): p = subprocess.Popen(self.argv) ret = p.wait() if ret < 0: - logging.error(f'Child process terminated due to signal: ' - f'{signal.strsignal(-ret)}') + if hasattr(signal, 'strsignal'): + sig = signal.strsignal(-ret) + else: + sig = -ret + logging.error( + f'Child process terminated due to signal: {sig}') return ret diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index 69f0aad..3125d3a 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -845,6 +845,13 @@ def test_get_wkd_url(email, expected): assert OpenPGPEnvironment.get_wkd_url(email) == expected +def signal_desc(sig): + if hasattr(signal, 'strsignal'): + return signal.strsignal(sig) + else: + return sig + + @pytest.mark.parametrize( 'command,expected,match', [('true', 0, None), @@ -853,10 +860,10 @@ def test_get_wkd_url(email, expected): ('gpg --verify {tmp_path}/Manifest.subkey', 2, None), ('sh -c "kill $$"', -signal.SIGTERM, f'Child process terminated due to signal: ' - f'{signal.strsignal(signal.SIGTERM)}'), + f'{signal_desc(signal.SIGTERM)}'), ('sh -c "kill -USR1 $$"', -signal.SIGUSR1, f'Child process terminated due to signal: ' - f'{signal.strsignal(signal.SIGUSR1)}'), + f'{signal_desc(signal.SIGUSR1)}'), ]) def test_cli_gpg_wrap(tmp_path, caplog, command, expected, match): with open(tmp_path / '.key.bin', 'wb') as f: |