<s> """<STR_LIT>""" <EOL> from mock import patch , call , MagicMock <EOL> from braubuddy . tests import BraubuddyTestCase <EOL> from braubuddy . envcontroller import tosr0x_usb <EOL> from braubuddy . envcontroller import DeviceError <EOL> from braubuddy . envcontroller import PercentageError <EOL> @ patch ( '<STR_LIT>' ) <EOL> class TestTosr0x ( BraubuddyTestCase ) : <EOL> def test_tosr0x_detected ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> self . assertIs ( envcontroller . _tosr0x_device , mk_tosr0x_device ) <EOL> def test_first_if_multiple_tosr0x_detected ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device_1 = MagicMock ( ) <EOL> mk_tosr0x_device_2 = MagicMock ( ) <EOL> mk_tosr0x_device_3 = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ <EOL> mk_tosr0x_device_1 , <EOL> mk_tosr0x_device_2 , <EOL> mk_tosr0x_device_3 , <EOL> ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> self . assertIs ( envcontroller . _tosr0x_device , mk_tosr0x_device_1 ) <EOL> def test_tosr0x_not_detected ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x . handler . return_value = [ ] <EOL> with self . assertRaises ( DeviceError ) : <EOL> t = tosr0x_usb . Tosr0xEnvController ( ) <EOL> def test_heat_set_zero ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> envcontroller . set_heater_level ( <NUM_LIT:0> ) <EOL> mk_tosr0x_device . set_relay_position . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> def test_heat_set_gt_zero ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> for h in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> envcontroller . set_heater_level ( h ) <EOL> mk_tosr0x_device . set_relay_position . assert_called_with ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def test_cool_set_zero ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> envcontroller . set_cooler_level ( <NUM_LIT:0> ) <EOL> mk_tosr0x_device . set_relay_position . assert_called_with ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> def test_cool_set_gt_zero ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> for h in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> envcontroller . set_cooler_level ( h ) <EOL> mk_tosr0x_device . set_relay_position . assert_called_with ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> def test_get_power_levels_100_percent ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> relays_both_on = { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:1> } <EOL> mk_tosr0x_device . get_relay_positions . return_value = relays_both_on <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> self . assertEqual ( envcontroller . get_power_levels ( ) , ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_get_power_levels_0_percent ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> relays_both_on = { <NUM_LIT:1> : <NUM_LIT:0> , <NUM_LIT:2> : <NUM_LIT:0> } <EOL> mk_tosr0x_device . get_relay_positions . return_value = relays_both_on <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> self . assertEqual ( envcontroller . get_power_levels ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def test_heat_set_invalid ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> with self . assertRaises ( PercentageError ) : <EOL> envcontroller . set_heater_level ( <NUM_LIT> ) <EOL> def test_cool_set_invalid ( self , mk_tosr0x ) : <EOL> """<STR_LIT>""" <EOL> mk_tosr0x_device = MagicMock ( ) <EOL> mk_tosr0x . handler . return_value = [ mk_tosr0x_device ] <EOL> envcontroller = tosr0x_usb . Tosr0xEnvController ( ) <EOL> with self . assertRaises ( PercentageError ) : <EOL> envcontroller . set_cooler_level ( <NUM_LIT> ) </s>
