Debian Codegraph @

tests/test_export.py

raw symbols SCIP
1 import pytest
2
3 from labgrid.resource import Resource, NetworkSerialPort, TFTPProvider
4 from labgrid.resource.remote import RemoteNetworkInterface, RemoteTFTPProvider
5 from labgrid.driver import Driver, SerialDriver, NetworkInterfaceDriver, TFTPProviderDriver
6 from labgrid.strategy import Strategy
7 from labgrid.binding import StateError
8
9
10 class ResourceA(Resource):
11 pass
12
13
14 class DriverA(Driver):
15 bindings = {"res": ResourceA}
16
17 @Driver.check_bound
18 def get_export_vars(self):
19 return {
20 "a": "b",
21 }
22
23
24 class StrategyA(Strategy):
25 bindings = {
26 "drv": DriverA,
27 }
28
29
30 def test_export(target):
31 ra = ResourceA(target, "resource")
32 d = DriverA(target, "driver")
33 s = StrategyA(target, "strategy")
34
35 exported = target.export()
36 assert exported == {
37 "LG__DRV_A": "b",
38 }
39
40 target.activate(d)
41 with pytest.raises(StateError):
42 d.get_export_vars()
43
44
45 class StrategyB(Strategy):
46 bindings = {
47 "drv": DriverA,
48 }
49
50 def prepare_export(self):
51 return {
52 self.drv: "custom_name",
53 }
54
55
56 def test_export_custom(target):
57 ra = ResourceA(target, "resource")
58 d = DriverA(target, "driver")
59 s = StrategyB(target, "strategy")
60
61 exported = target.export()
62 assert exported == {
63 "LG__CUSTOM_NAME_A": "b",
64 }
65
66
67 def test_export_network_serial(target):
68 NetworkSerialPort(target, None, host='testhost', port=12345, speed=115200)
69 SerialDriver(target, None)
70
71 exported = target.export()
72 assert exported == {
73 'LG__SERIALDRIVER_HOST': 'testhost',
74 'LG__SERIALDRIVER_PORT': '12345',
75 'LG__SERIALDRIVER_PROTOCOL': 'rfc2217',
76 'LG__SERIALDRIVER_SPEED': '115200'
77 }
78
79
80 def test_export_remote_network_interface(target):
81 RemoteNetworkInterface(target, None, host='testhost', ifname='wlan0')
82 NetworkInterfaceDriver(target, "netif")
83
84 exported = target.export()
85 assert exported == {
86 'LG__NETIF_HOST': 'testhost',
87 'LG__NETIF_IFNAME': 'wlan0'
88 }
89
90
91 def test_export_tftp_provider(target):
92 TFTPProvider(target, None, internal='/srv/tftp/testboard/', external='testboard/')
93 TFTPProviderDriver(target, "tftp")
94
95 exported = target.export()
96 assert exported == {
97 'LG__TFTP_HOST': 'localhost',
98 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/',
99 'LG__TFTP_EXTERNAL': 'testboard/',
100 }
101
102
103 def test_export_remote_tftp_provider(target):
104 RemoteTFTPProvider(target, None, host='testhost', internal='/srv/tftp/testboard/', external='testboard/')
105 TFTPProviderDriver(target, "tftp")
106
107 exported = target.export()
108 assert exported == {
109 'LG__TFTP_HOST': 'testhost',
110 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/',
111 'LG__TFTP_EXTERNAL': 'testboard/',
112 }