|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
6 | | -from labgrid.driver.power.tapo import _get_credentials, _power_get, _power_set, power_get |
| 6 | +from labgrid.driver.power.tapo import _get_credentials, power_get, power_set |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @pytest.fixture |
@@ -50,89 +50,81 @@ def test_credentials_valid(self, mock_env): |
50 | 50 | assert creds.username == "test_user" |
51 | 51 | assert creds.password == "test_pass" |
52 | 52 |
|
53 | | - @pytest.mark.asyncio |
54 | | - async def test_power_get_single_plug_turn_on(self, mock_device_single_plug, mock_env): |
| 53 | + def test_power_get_single_plug_turn_on(self, mock_device_single_plug, mock_env): |
55 | 54 | mock_device_single_plug.is_on = True |
56 | 55 |
|
57 | 56 | with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
58 | | - result = await _power_get("192.168.1.100", None, "0") |
| 57 | + result = power_get("192.168.1.100", None, "0") |
59 | 58 | assert result is True |
60 | 59 |
|
61 | | - @pytest.mark.asyncio |
62 | | - async def test_power_get_single_plug_turn_off(self, mock_device_single_plug, mock_env): |
| 60 | + def test_power_get_single_plug_turn_off(self, mock_device_single_plug, mock_env): |
63 | 61 | mock_device_single_plug.is_on = False |
64 | 62 |
|
65 | 63 | with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
66 | | - result = await _power_get("192.168.1.100", None, "0") |
| 64 | + result = power_get("192.168.1.100", None, "0") |
67 | 65 | assert result is False |
68 | 66 |
|
69 | | - @pytest.mark.asyncio |
70 | | - async def test_power_get_single_plug_should_not_care_for_index(self, mock_device_single_plug, mock_env): |
| 67 | + def test_power_get_single_plug_should_not_care_for_index(self, mock_device_single_plug, mock_env): |
71 | 68 | invalid_index_ignored = "7" |
72 | 69 | mock_device_single_plug.is_on = True |
73 | 70 |
|
74 | 71 | with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
75 | | - result = await _power_get("192.168.1.100", None, invalid_index_ignored) |
| 72 | + result = power_get("192.168.1.100", None, invalid_index_ignored) |
76 | 73 | assert result is True |
77 | 74 |
|
78 | | - @pytest.mark.asyncio |
79 | | - async def test_power_set_single_plug_turn_on(self, mock_device_single_plug, mock_env): |
| 75 | + def test_power_set_single_plug_turn_on(self, mock_device_single_plug, mock_env): |
80 | 76 | mock_device_single_plug.is_on = False |
81 | 77 | with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
82 | | - await _power_set("192.168.1.100", None, "0", True) |
| 78 | + power_set("192.168.1.100", None, "0", True) |
83 | 79 | mock_device_single_plug.turn_on.assert_called_once() |
84 | 80 |
|
85 | | - @pytest.mark.asyncio |
86 | | - async def test_power_set_single_plug_turn_off(self, mock_device_single_plug, mock_env): |
| 81 | + def test_power_set_single_plug_turn_off(self, mock_device_single_plug, mock_env): |
87 | 82 | mock_device_single_plug.is_on = True |
88 | 83 | with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
89 | | - await _power_set("192.168.1.100", None, "0", False) |
| 84 | + power_set("192.168.1.100", None, "0", False) |
90 | 85 | mock_device_single_plug.turn_off.assert_called_once() |
91 | 86 |
|
92 | | - @pytest.mark.asyncio |
93 | | - async def test_power_get_strip_valid_socket(self, mock_device_strip, mock_env): |
| 87 | + def test_power_get_strip_valid_socket(self, mock_device_strip, mock_env): |
94 | 88 | with patch("kasa.Device.connect", return_value=mock_device_strip): |
95 | 89 | # Test first outlet (on) |
96 | | - result = await _power_get("192.168.1.100", None, "0") |
| 90 | + result = power_get("192.168.1.100", None, "0") |
97 | 91 | assert result is True |
98 | 92 |
|
99 | 93 | # Test second outlet (off) |
100 | | - result = await _power_get("192.168.1.100", None, "1") |
| 94 | + result = power_get("192.168.1.100", None, "1") |
101 | 95 | assert result is False |
102 | 96 |
|
103 | 97 | # Test third outlet (on) |
104 | | - result = await _power_get("192.168.1.100", None, "2") |
| 98 | + result = power_get("192.168.1.100", None, "2") |
105 | 99 | assert result is True |
106 | 100 |
|
107 | | - @pytest.mark.asyncio |
108 | | - async def test_power_set_strip_valid_socket(self, mock_device_strip, mock_env): |
| 101 | + def test_power_set_strip_valid_socket(self, mock_device_strip, mock_env): |
109 | 102 | with patch("kasa.Device.connect", return_value=mock_device_strip): |
110 | | - await _power_set("192.168.1.100", None, "0", False) |
| 103 | + power_set("192.168.1.100", None, "0", False) |
111 | 104 | mock_device_strip.children[0].turn_off.assert_called_once() |
112 | 105 |
|
113 | | - await _power_set("192.168.1.100", None, "1", True) |
| 106 | + power_set("192.168.1.100", None, "1", True) |
114 | 107 | mock_device_strip.children[1].turn_on.assert_called_once() |
115 | 108 |
|
116 | 109 | def test_power_get_should_raise_assertion_error_when_invalid_index_strip(self, mock_device_strip, mock_env): |
117 | 110 | invalid_socket = "5" |
118 | | - with patch("kasa.Device.connect", return_value=mock_device_strip): |
119 | | - with pytest.raises(AssertionError, match="Trying to access non-existant plug socket"): |
120 | | - power_get("192.168.1.100", None, invalid_socket) |
| 111 | + with patch("kasa.Device.connect", return_value=mock_device_strip), \ |
| 112 | + pytest.raises(AssertionError, match="Trying to access non-existent plug socket"): |
| 113 | + power_get("192.168.1.100", None, invalid_socket) |
121 | 114 |
|
122 | | - @pytest.mark.asyncio |
123 | | - async def test_power_set_should_raise_assertion_error_when_invalid_index_strip(self, mock_device_strip, mock_env): |
| 115 | + def test_power_set_should_raise_assertion_error_when_invalid_index_strip(self, mock_device_strip, mock_env): |
124 | 116 | invalid_socket = "5" |
125 | | - with patch("kasa.Device.connect", return_value=mock_device_strip): |
126 | | - with pytest.raises(AssertionError, match="Trying to access non-existant plug socket"): |
127 | | - await _power_set("192.168.1.100", None, invalid_socket, True) |
| 117 | + with patch("kasa.Device.connect", return_value=mock_device_strip), \ |
| 118 | + pytest.raises(AssertionError, match="Trying to access non-existent plug socket"): |
| 119 | + power_set("192.168.1.100", None, invalid_socket, True) |
128 | 120 |
|
129 | 121 | def test_port_not_none_strip(self, mock_device_strip): |
130 | | - with patch("kasa.Device.connect", return_value=mock_device_strip): |
131 | | - with pytest.raises(AssertionError): |
132 | | - power_get("192.168.1.100", "8080", "0") |
| 122 | + with patch("kasa.Device.connect", return_value=mock_device_strip), \ |
| 123 | + pytest.raises(AssertionError): |
| 124 | + power_get("192.168.1.100", "8080", "0") |
133 | 125 |
|
134 | 126 | def test_port_not_none_single_socket(self, mock_device_single_plug): |
135 | 127 | mock_device_single_plug.is_on = True |
136 | | - with patch("kasa.Device.connect", return_value=mock_device_single_plug): |
137 | | - with pytest.raises(AssertionError): |
138 | | - power_get("192.168.1.100", "8080", "0") |
| 128 | + with patch("kasa.Device.connect", return_value=mock_device_single_plug), \ |
| 129 | + pytest.raises(AssertionError): |
| 130 | + power_get("192.168.1.100", "8080", "0") |
0 commit comments