Skip to content

Commit 661ee27

Browse files
authored
Merge pull request #119 from keszybz/sd128-tests
tests: check for errnos that sd_id128_get_machine actually returns
2 parents dc1dae2 + 4bba47d commit 661ee27

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.github/workflows/install.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,4 @@ jobs:
7676
# Avoid importing the systemd module from the git repository
7777
cd /
7878
python3 -c 'from systemd import journal; print(journal.__version__)'
79-
# Initialize /etc/machine-id if it's empty to make the tests happy
80-
[[ ! -s /etc/machine-id ]] && systemd-id128 new >/etc/machine-id
8179
pytest -v --pyargs systemd

systemd/test/test_id128.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from systemd import id128
77

88
@contextlib.contextmanager
9-
def skip_oserror(code):
9+
def skip_oserror(*errnos):
1010
try:
1111
yield
1212
except (OSError, IOError) as e:
13-
if e.errno == code:
13+
if e.errno in errnos:
1414
pytest.skip()
1515
raise
1616

@@ -21,15 +21,18 @@ def test_randomize():
2121
assert u1 != u2
2222

2323
def test_get_machine():
24-
u1 = id128.get_machine()
24+
# yikes, python2 doesn't know ENOMEDIUM
25+
with skip_oserror(errno.ENOENT, errno.ENOSYS, 123):
26+
u1 = id128.get_machine()
27+
2528
u2 = id128.get_machine()
2629
assert u1 == u2
2730

2831
def test_get_machine_app_specific():
2932
a1 = uuid.uuid1()
3033
a2 = uuid.uuid1()
3134

32-
with skip_oserror(errno.ENOSYS):
35+
with skip_oserror(errno.ENOENT, errno.ENOSYS, 123):
3336
u1 = id128.get_machine_app_specific(a1)
3437

3538
u2 = id128.get_machine_app_specific(a2)

systemd/test/test_journal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ def test_reader_this_boot(tmpdir):
233233
def test_reader_this_machine(tmpdir):
234234
j = journal.Reader(path=tmpdir.strpath)
235235
with j:
236-
j.this_machine()
236+
try:
237+
j.this_machine()
238+
except OSError:
239+
pass
240+
237241
j.this_machine(TEST_MID)
238242
j.this_machine(TEST_MID.hex)
239243

0 commit comments

Comments
 (0)