Skip to content

Commit 4b2ba97

Browse files
committed
update test
add test for power down/wake up when HW is connected improve test for measurement/read measurement
1 parent 5fb66fd commit 4b2ba97

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

tests/test_scd4x.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#
1212

1313
import pytest
14+
import time
1415
from sensirion_i2c_scd4x.device import Scd4xDevice
1516

1617

@@ -147,26 +148,26 @@ def test_measure_and_read_single_shot1(sensor):
147148

148149
def test_measure_single_shot_rht_only1(sensor):
149150
sensor.measure_single_shot_rht_only()
150-
151-
152-
def test_measure_single_shot1(sensor):
153-
sensor.measure_single_shot()
151+
(a_co2_concentration, a_temperature, a_relative_humidity
152+
) = sensor.read_measurement()
153+
print(f"a_co2_concentration: {a_co2_concentration}; "
154+
f"a_temperature: {a_temperature}; "
155+
f"a_relative_humidity: {a_relative_humidity}; "
156+
)
154157

155158

156159
def test_start_periodic_measurement1(sensor):
157160
sensor.start_periodic_measurement()
161+
while not sensor.get_data_ready_status():
162+
# wait until data is ready to be read out
163+
time.sleep(1)
158164
(a_co2_concentration, a_temperature, a_relative_humidity
159165
) = sensor.read_measurement()
160166
print(f"a_co2_concentration: {a_co2_concentration}; "
161167
f"a_temperature: {a_temperature}; "
162168
f"a_relative_humidity: {a_relative_humidity}; "
163169
)
164-
(co2_concentration, temperature, relative_humidity
165-
) = sensor.read_measurement_raw()
166-
print(f"co2_concentration: {co2_concentration}; "
167-
f"temperature: {temperature}; "
168-
f"relative_humidity: {relative_humidity}; "
169-
)
170+
# read_measurement_raw is implicitly tested with read_measurement
170171
sensor.set_ambient_pressure(101300)
171172
a_ambient_pressure = sensor.get_ambient_pressure()
172173
print(f"a_ambient_pressure: {a_ambient_pressure}; "
@@ -186,18 +187,16 @@ def test_start_periodic_measurement1(sensor):
186187

187188
def test_start_low_power_periodic_measurement1(sensor):
188189
sensor.start_low_power_periodic_measurement()
190+
while not sensor.get_data_ready_status():
191+
# wait until data is ready to be read out
192+
time.sleep(1)
189193
(a_co2_concentration, a_temperature, a_relative_humidity
190194
) = sensor.read_measurement()
191195
print(f"a_co2_concentration: {a_co2_concentration}; "
192196
f"a_temperature: {a_temperature}; "
193197
f"a_relative_humidity: {a_relative_humidity}; "
194198
)
195-
(co2_concentration, temperature, relative_humidity
196-
) = sensor.read_measurement_raw()
197-
print(f"co2_concentration: {co2_concentration}; "
198-
f"temperature: {temperature}; "
199-
f"relative_humidity: {relative_humidity}; "
200-
)
199+
# read_measurement_raw is implicitly tested with read_measurement
201200
sensor.set_ambient_pressure(101300)
202201
a_ambient_pressure = sensor.get_ambient_pressure()
203202
print(f"a_ambient_pressure: {a_ambient_pressure}; "
@@ -214,3 +213,23 @@ def test_start_low_power_periodic_measurement1(sensor):
214213
)
215214
sensor.stop_periodic_measurement()
216215

216+
217+
@pytest.mark.needs_hardware
218+
def test_sleep_mode(sensor):
219+
"""
220+
Test power down and wake up commands
221+
"""
222+
sensor.power_down()
223+
try:
224+
sensor.get_data_ready_status()
225+
except I2cNackError:
226+
assert True
227+
else:
228+
assert False, "SCD4x should respond with NACK when in sleep mode"
229+
sensor.wake_up()
230+
try:
231+
sensor.get_data_ready_status()
232+
except I2cNackError:
233+
assert False, "SCD4x should respond after wake up"
234+
else:
235+
assert True

0 commit comments

Comments
 (0)