| 1 | import contextlib |
| 2 | import errno |
| 3 | import uuid |
| 4 | import pytest |
| 5 | |
| 6 | from systemd import id128 |
| 7 | |
| 8 | @contextlib.contextmanager |
| 9 | def skip_oserror(code): |
| 10 | try: |
| 11 | yield |
| 12 | except (OSError, IOError) as e: |
| 13 | if e.errno == code: |
| 14 | pytest.skip() |
| 15 | raise |
| 16 | |
| 17 | |
| 18 | def test_randomize(): |
| 19 | u1 = id128.randomize() |
| 20 | u2 = id128.randomize() |
| 21 | assert u1 != u2 |
| 22 | |
| 23 | def test_get_machine(): |
| 24 | u1 = id128.get_machine() |
| 25 | u2 = id128.get_machine() |
| 26 | assert u1 == u2 |
| 27 | |
| 28 | def test_get_machine_app_specific(): |
| 29 | a1 = uuid.uuid1() |
| 30 | a2 = uuid.uuid1() |
| 31 | |
| 32 | with skip_oserror(errno.ENOSYS): |
| 33 | u1 = id128.get_machine_app_specific(a1) |
| 34 | |
| 35 | u2 = id128.get_machine_app_specific(a2) |
| 36 | u3 = id128.get_machine_app_specific(a1) |
| 37 | u4 = id128.get_machine_app_specific(a2) |
| 38 | |
| 39 | assert u1 != u2 |
| 40 | assert u1 == u3 |
| 41 | assert u2 == u4 |
| 42 | |
| 43 | def test_get_boot(): |
| 44 | u1 = id128.get_boot() |
| 45 | u2 = id128.get_boot() |
| 46 | assert u1 == u2 |