def change_adjust_amount(): global config value = IntegerAdjustInput(config['adjust_amount'], i, o, message="Adjust amount", interval=1).activate() if value is None: return False config["adjust_amount"] = value write_config(config, config_path)
def change_interval( ): # A helper function to adjust the Refresher's refresh interval while it's running new_interval = IntegerAdjustInput( int(r.refresh_interval), i, o, message="Refresh interval:").activate() if new_interval is not None: r.set_refresh_interval(new_interval)
def adjust_timeout(): global config timeout = IntegerAdjustInput(config["timeout"], i, o, message="Socket timeout:").activate() if timeout is not None and timeout > 0: config["timeout"] = timeout write_config(config, config_path) elif not timeout > 0: Printer(ffs("Timeout has to be larger than 0!", o.cols), i, o)
def test_iaio_number_input(self): overlay = IntegerAdjustInputOverlay() i = get_mock_input() ia = IntegerAdjustInput(0, i, get_mock_output(), name=ui_name) overlay.apply_to(ia) def scenario(): keymap = i.set_keymap.call_args[0][0] keymap["KEY_1"]() assert (ia.number == 1) keymap["KEY_2"]() assert (ia.number == 12) ia.deactivate() assert not ia.in_foreground with patch.object(ia, 'idle_loop', side_effect=scenario) as p: ia.activate()
def test_entering_value(self): ii = IntegerAdjustInput(1, get_mock_input(), get_mock_output(), name=ii_name) ii.refresh = lambda *args, **kwargs: None plus = 5 minus = 4 expected = 2 def scenario(): for i in range(plus): execute_shorthand(ii, "u") for i in range(minus): execute_shorthand(ii, "d") execute_shorthand(ii, 'e') assert not ii.is_active with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value == expected
def test_shows_data_on_screen(self): """Tests whether the IntegerAdjustInput outputs data on screen when it's ran""" i = get_mock_input() o = get_mock_output() ii = IntegerAdjustInput(1, i, o, message="Test:", name=ii_name) def scenario(): assert o.display_data.called assert o.display_data.call_args[0][0].strip() == 'Test:' assert o.display_data.call_args[0][1].strip() == str(1) for i in range(5): execute_shorthand(ii, "u") assert o.display_data.call_args[0][1].strip() == str(i+2) execute_shorthand(ii, "e") assert not ii.in_foreground # Should exit on last "e" with patch.object(ii, 'idle_loop', side_effect=scenario) as p: ii.activate() #The scenario should only be called once assert ii.idle_loop.called assert ii.idle_loop.call_count == 1 assert o.display_data.call_count == 6
def set_countdown(self, absolute=False): if absolute: raise NotImplementedError # Needs a TimePicker or something like that rel_start = 0 message = "After (in minutes):" if self.countdown: # A countdown is already active # Using it as a starting point h, m, s, _ = self.get_countdown_time_left() rel_start = h * 60 + m offset = IntegerAdjustInput(rel_start, self.i, self.o, message=message).activate() if offset is not None: countdown = {"time": datetime.now() + timedelta(minutes=offset)} self.countdown = countdown
def test_left_returns_none(self): ii = IntegerAdjustInput(1, get_mock_input(), get_mock_output(), name=ii_name) ii.refresh = lambda *args, **kwargs: None #not needed # Checking without changing value def scenario(): ii.keymap["KEY_LEFT"]() assert not ii.in_foreground with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value is None # Checking after entering some keys test_keys = "u"*5 def scenario(): for key in test_keys: execute_shorthand(ii, key) execute_shorthand(ii, 'l') assert not ii.in_foreground with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value is None
def set_bitclock(self): """ Allows adjustments of avrdude bitclock, allowing to work with slowly-clocked microcontrollers. """ bitclock = IntegerAdjustInput(self.bitclock, self.i, self.o, message="Bitclock:", name="Avrdude app bitclock adjust", min=1, max=50).activate() if bitclock: self.bitclock = bitclock self.config["last_bitclock"] = bitclock self.save_config()
def change_interval(): global interval interval = IntegerAdjustInput(interval, i, o, message="Length in min.:").activate()
def test_iaio_apply(self): overlay = IntegerAdjustInputOverlay() ia = IntegerAdjustInput(0, get_mock_input(), get_mock_output(), name=ui_name) overlay.apply_to(ia) self.assertIsNotNone(overlay) self.assertIsNotNone(ia)
def test_constructor(self): """tests constructor""" ii = IntegerAdjustInput(1, get_mock_input(), get_mock_output(), name=ii_name) self.assertIsNotNone(ii)
def get_ia(*args, **kwargs): ia = IntegerAdjustInput(*args, **kwargs) iaio.apply_to(ia) return ia