| 1 |
|
| 2 |
|
| 3 |
from __future__ import absolute_import |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from pyxs._compat import xs, Error |
| 8 |
|
| 9 |
from . import virtualized |
| 10 |
|
| 11 |
|
| 12 |
@virtualized |
| 13 |
def setup_function(f): |
| 14 |
try: |
| 15 |
handle = xs() |
| 16 |
except Error: |
| 17 |
return |
| 18 |
|
| 19 |
try: |
| 20 |
handle.rm(0, b"/foo") |
| 21 |
except Error: |
| 22 |
pass |
| 23 |
finally: |
| 24 |
handle.close() |
| 25 |
|
| 26 |
|
| 27 |
@pytest.yield_fixture |
| 28 |
def handle(): |
| 29 |
handle = xs() |
| 30 |
try: |
| 31 |
yield handle |
| 32 |
finally: |
| 33 |
handle.close() |
| 34 |
|
| 35 |
|
| 36 |
def test_api_completeness(): |
| 37 |
try: |
| 38 |
from xen.lowlevel.xs import xs as cxs |
| 39 |
except ImportError: |
| 40 |
pytest.skip("xen.lowlevel.xs not available") |
| 41 |
|
| 42 |
def public_methods(target): |
| 43 |
return set(attr for attr in dir(target) |
| 44 |
if not attr.startswith("_")) |
| 45 |
|
| 46 |
assert public_methods(cxs).issubset(public_methods(xs)) |
| 47 |
|
| 48 |
|
| 49 |
@virtualized |
| 50 |
def test_ls(handle): |
| 51 |
assert handle.ls(0, b"/missing/path") is None |
| 52 |
|
| 53 |
|
| 54 |
@virtualized |
| 55 |
def test_transaction_start(handle): |
| 56 |
assert isinstance(handle.transaction_start(), bytes) |
| 57 |
|
| 58 |
|
| 59 |
@virtualized |
| 60 |
def test_transaction_end_rollback(handle): |
| 61 |
assert handle.ls(0, b"/foo") is None |
| 62 |
tx_id = handle.transaction_start() |
| 63 |
handle.write(tx_id, b"/foo/bar", b"boo") |
| 64 |
handle.transaction_end(tx_id, abort=1) |
| 65 |
assert handle.ls(0, b"/foo") is None |
| 66 |
|
| 67 |
|
| 68 |
@virtualized |
| 69 |
def test_transaction_end_commit(handle): |
| 70 |
assert handle.ls(0, b"/foo") is None |
| 71 |
tx_id = handle.transaction_start() |
| 72 |
handle.write(tx_id, b"/foo/bar", b"boo") |
| 73 |
handle.transaction_end(tx_id, abort=0) |
| 74 |
assert handle.ls(0, b"/foo") == [b"bar"] |
| 75 |
|
| 76 |
|
| 77 |
@virtualized |
| 78 |
def test_watch_unwatch(handle): |
| 79 |
token = object() |
| 80 |
handle.watch(b"/foo/bar", token) |
| 81 |
assert handle.read_watch() == (b"/foo/bar", token) |
| 82 |
handle.unwatch(b"/foo/bar", token) |