11# noqa D100
2- import sys
2+ from . tools import CALIBRATED_VALUES
33
4- import mock
54
6- from .tools import CALIBRATED_VALUES , SMBusFakeAS7262
7-
8-
9- def _setup ():
10- global as7262
11- smbus = mock .Mock ()
12- smbus .SMBus = SMBusFakeAS7262
13- sys .modules ['smbus2' ] = smbus
14- from as7262 import AS7262
15- as7262 = AS7262 ()
16-
17-
18- def test_set_integration_time ():
5+ def test_set_integration_time (smbus , AS7262 ):
196 """Test the set_integration_time method against various values."""
20- _setup ()
7+ as7262 = AS7262 ()
218
229 # Integration time is stored as 2.8ms per lsb
2310 # so returned values experience quantization
@@ -39,9 +26,9 @@ def test_set_integration_time():
3926 assert as7262 ._as7262 .INTEGRATION_TIME .get_ms () == (int (99999 * 2.8 ) & 0xFF ) / 2.8
4027
4128
42- def test_set_gain ():
29+ def test_set_gain (smbus , AS7262 ):
4330 """Test the set_gain method against various values."""
44- _setup ()
31+ as7262 = AS7262 ()
4532
4633 as7262 .set_gain (1 )
4734 assert as7262 ._as7262 .CONTROL .get_gain_x () == 1
@@ -55,17 +42,17 @@ def test_set_gain():
5542 assert as7262 ._as7262 .CONTROL .get_gain_x () == 1
5643
5744
58- def test_set_measurement_mode ():
45+ def test_set_measurement_mode (smbus , AS7262 ):
5946 """Test the set_measurement_mode method."""
60- _setup ()
47+ as7262 = AS7262 ()
6148
6249 as7262 .set_measurement_mode (2 )
6350 assert as7262 ._as7262 .CONTROL .get_measurement_mode () == 2
6451
6552
66- def test_set_illumination_led_current ():
53+ def test_set_illumination_led_current (smbus , AS7262 ):
6754 """Test the set_illumination_led_current method."""
68- _setup ()
55+ as7262 = AS7262 ()
6956
7057 as7262 .set_illumination_led_current (12.5 )
7158 assert as7262 ._as7262 .LED_CONTROL .get_illumination_current_limit_ma () == 12.5
@@ -77,9 +64,9 @@ def test_set_illumination_led_current():
7764 assert as7262 ._as7262 .LED_CONTROL .get_illumination_current_limit_ma () == 100
7865
7966
80- def test_set_indicator_led_current ():
67+ def test_set_indicator_led_current (smbus , AS7262 ):
8168 """Test the set_indicator_led_current method."""
82- _setup ()
69+ as7262 = AS7262 ()
8370
8471 as7262 .set_indicator_led_current (4 )
8572 assert as7262 ._as7262 .LED_CONTROL .get_indicator_current_limit_ma () == 4
@@ -91,33 +78,33 @@ def test_set_indicator_led_current():
9178 assert as7262 ._as7262 .LED_CONTROL .get_indicator_current_limit_ma () == 1
9279
9380
94- def test_indicator_led ():
81+ def test_indicator_led (smbus , AS7262 ):
9582 """Test the indicator_led method."""
96- _setup ()
83+ as7262 = AS7262 ()
9784
9885 as7262 .set_indicator_led (1 )
9986 assert as7262 ._as7262 .LED_CONTROL .get_indicator_enable () == 1
10087
10188
102- def test_illumination_led ():
89+ def test_illumination_led (smbus , AS7262 ):
10390 """Test the illumination_led method."""
104- _setup ()
91+ as7262 = AS7262 ()
10592
10693 as7262 .set_illumination_led (1 )
10794 assert as7262 ._as7262 .LED_CONTROL .get_illumination_enable () == 1
10895
10996
110- def test_soft_reset ():
97+ def test_soft_reset (smbus , AS7262 ):
11198 """Test the soft_reset method."""
112- _setup ()
99+ as7262 = AS7262 ()
113100
114101 as7262 .soft_reset ()
115102 assert as7262 ._as7262 .CONTROL .get_reset () == 1
116103
117104
118- def test_get_calibrated_values ():
105+ def test_get_calibrated_values (smbus , AS7262 ):
119106 """Test against fake calibrated values stored in hardware mock."""
120- _setup ()
107+ as7262 = AS7262 ()
121108
122109 values = as7262 .get_calibrated_values ()
123110
0 commit comments