File: test_database.py

package info (click to toggle)
pytango 10.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,216 kB
  • sloc: python: 28,206; cpp: 16,380; sql: 255; sh: 82; makefile: 43
file content (65 lines) | stat: -rw-r--r-- 1,916 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
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
import pytest

from tango import Database
from tango.server import Device, attribute
from tango.test_utils import MultiDeviceTestContext, assert_close


class DeviceToTest(Device):
    @attribute(dtype=str)
    def attr1(self):
        return "attr1"

    @attribute(dtype=str)
    def attr2(self):
        return "attr2"


device_name = "device/test/1"

devices_info = ({"class": DeviceToTest, "devices": [{"name": device_name}]},)


@pytest.fixture()
def test_database():
    with MultiDeviceTestContext(devices_info) as context:
        yield Database(context.db)


def test_put_remove_attribute_properties(test_database):
    attr1_properties = {"attr1": {"value1": ["1"], "value2": ["2"], "value3": ["3"]}}
    attr2_properties = {"attr2": {"value1": ["4"], "value2": ["5"], "value3": ["6"]}}

    test_database.put_device_attribute_property(
        device_name, attr1_properties | attr2_properties
    )

    assert_close(
        test_database.get_device_attribute_property(device_name, "attr1"),
        attr1_properties,
    )
    assert_close(
        test_database.get_device_attribute_property(device_name, "attr2"),
        attr2_properties,
    )

    attr1_prop_to_delete = {"attr1": ["value1"]}
    attr2_prop_to_delete = {"attr2": ["value2"]}

    test_database.delete_device_attribute_property(
        device_name, attr1_prop_to_delete | attr2_prop_to_delete
    )

    [attr1_properties["attr1"].pop(k, None) for k in attr1_prop_to_delete["attr1"]]
    [attr2_properties["attr2"].pop(k, None) for k in attr2_prop_to_delete["attr2"]]

    assert_close(
        test_database.get_device_attribute_property(device_name, "attr1"),
        attr1_properties,
    )
    assert_close(
        test_database.get_device_attribute_property(device_name, "attr2"),
        attr2_properties,
    )