File: test__compat.py

package info (click to toggle)
python-pyxs 0.4.2~git20190115.97f14313-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 332 kB
  • sloc: python: 1,196; makefile: 93
file content (82 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download | duplicates (3)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import pytest

from pyxs._compat import xs, Error

from . import virtualized


@virtualized
def setup_function(f):
    try:
        handle = xs()
    except Error:
        return  # Failed to connect.

    try:
        handle.rm(0, b"/foo")
    except Error:
        pass
    finally:
        handle.close()


@pytest.yield_fixture
def handle():
    handle = xs()
    try:
        yield handle
    finally:
        handle.close()


def test_api_completeness():
    try:
        from xen.lowlevel.xs import xs as cxs
    except ImportError:
        pytest.skip("xen.lowlevel.xs not available")

    def public_methods(target):
        return set(attr for attr in dir(target)
                   if not attr.startswith("_"))

    assert public_methods(cxs).issubset(public_methods(xs))


@virtualized
def test_ls(handle):
    assert handle.ls(0, b"/missing/path") is None


@virtualized
def test_transaction_start(handle):
    assert isinstance(handle.transaction_start(), bytes)


@virtualized
def test_transaction_end_rollback(handle):
    assert handle.ls(0, b"/foo") is None
    tx_id = handle.transaction_start()
    handle.write(tx_id, b"/foo/bar", b"boo")
    handle.transaction_end(tx_id, abort=1)
    assert handle.ls(0, b"/foo") is None


@virtualized
def test_transaction_end_commit(handle):
    assert handle.ls(0, b"/foo") is None
    tx_id = handle.transaction_start()
    handle.write(tx_id, b"/foo/bar", b"boo")
    handle.transaction_end(tx_id, abort=0)
    assert handle.ls(0, b"/foo") == [b"bar"]


@virtualized
def test_watch_unwatch(handle):
    token = object()
    handle.watch(b"/foo/bar", token)
    assert handle.read_watch() == (b"/foo/bar", token)
    handle.unwatch(b"/foo/bar", token)