summaryrefslogtreecommitdiff
path: root/systemd/test/test_id128.py
blob: 146ec736de3111d08ca46870c2dda48c4baf2206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import contextlib
import errno
import uuid
import pytest

from systemd import id128

@contextlib.contextmanager
def skip_oserror(code):
    try:
        yield
    except (OSError, IOError) as e:
        if e.errno == code:
            pytest.skip()
        raise


def test_randomize():
    u1 = id128.randomize()
    u2 = id128.randomize()
    assert u1 != u2

def test_get_machine():
    u1 = id128.get_machine()
    u2 = id128.get_machine()
    assert u1 == u2

def test_get_machine_app_specific():
    a1 = uuid.uuid1()
    a2 = uuid.uuid1()

    with skip_oserror(errno.ENOSYS):
        u1 = id128.get_machine_app_specific(a1)

    u2 = id128.get_machine_app_specific(a2)
    u3 = id128.get_machine_app_specific(a1)
    u4 = id128.get_machine_app_specific(a2)

    assert u1 != u2
    assert u1 == u3
    assert u2 == u4

def test_get_boot():
    u1 = id128.get_boot()
    u2 = id128.get_boot()
    assert u1 == u2