summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-08-17 13:16:28 +0200
committerGitHub <noreply@github.com>2022-08-17 13:16:28 +0200
commit661ee278e801ea072508d7154696440632f894a0 (patch)
tree2023f35fe89a5c79aae1ae9594a00b98cdb29571
parentdc1dae2eaa00e2369c366f80f9bcd3f729b7abca (diff)
parent4bba47da39d9ffb9c79af9ec575c38579e7a0cda (diff)
downloadpython-systemd-661ee278e801ea072508d7154696440632f894a0.tar.gz
Merge pull request #119 from keszybz/sd128-tests
tests: check for errnos that sd_id128_get_machine actually returns
-rw-r--r--.github/workflows/install.yml2
-rw-r--r--systemd/test/test_id128.py11
-rw-r--r--systemd/test/test_journal.py6
3 files changed, 12 insertions, 7 deletions
diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml
index 6a8cc39..c1d202c 100644
--- a/.github/workflows/install.yml
+++ b/.github/workflows/install.yml
@@ -76,6 +76,4 @@ jobs:
# Avoid importing the systemd module from the git repository
cd /
python3 -c 'from systemd import journal; print(journal.__version__)'
- # Initialize /etc/machine-id if it's empty to make the tests happy
- [[ ! -s /etc/machine-id ]] && systemd-id128 new >/etc/machine-id
pytest -v --pyargs systemd
diff --git a/systemd/test/test_id128.py b/systemd/test/test_id128.py
index 146ec73..e87b1cc 100644
--- a/systemd/test/test_id128.py
+++ b/systemd/test/test_id128.py
@@ -6,11 +6,11 @@ import pytest
from systemd import id128
@contextlib.contextmanager
-def skip_oserror(code):
+def skip_oserror(*errnos):
try:
yield
except (OSError, IOError) as e:
- if e.errno == code:
+ if e.errno in errnos:
pytest.skip()
raise
@@ -21,7 +21,10 @@ def test_randomize():
assert u1 != u2
def test_get_machine():
- u1 = id128.get_machine()
+ # yikes, python2 doesn't know ENOMEDIUM
+ with skip_oserror(errno.ENOENT, errno.ENOSYS, 123):
+ u1 = id128.get_machine()
+
u2 = id128.get_machine()
assert u1 == u2
@@ -29,7 +32,7 @@ def test_get_machine_app_specific():
a1 = uuid.uuid1()
a2 = uuid.uuid1()
- with skip_oserror(errno.ENOSYS):
+ with skip_oserror(errno.ENOENT, errno.ENOSYS, 123):
u1 = id128.get_machine_app_specific(a1)
u2 = id128.get_machine_app_specific(a2)
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py
index c192136..dd733cf 100644
--- a/systemd/test/test_journal.py
+++ b/systemd/test/test_journal.py
@@ -233,7 +233,11 @@ def test_reader_this_boot(tmpdir):
def test_reader_this_machine(tmpdir):
j = journal.Reader(path=tmpdir.strpath)
with j:
- j.this_machine()
+ try:
+ j.this_machine()
+ except OSError:
+ pass
+
j.this_machine(TEST_MID)
j.this_machine(TEST_MID.hex)