def test_update_keymap(self): """Tests whether the Refresher updates the keymap correctly.""" i = get_mock_input() o = get_mock_output() r = Refresher(lambda: "Hello", i, o, name=r_name, refresh_interval=0.1) r.refresh = lambda *args, **kwargs: None # We need to patch "process_callback" because otherwise the keymap callbacks # are wrapped and we can't test equivalence with patch.object(r, 'process_callback', side_effect=lambda keymap:keymap) as p: keymap1 = {"KEY_LEFT": lambda:1} r.update_keymap(keymap1) assert(r.keymap == keymap1) keymap2 = {"KEY_RIGHT": lambda:2} r.update_keymap(keymap2) keymap2.update(keymap1) assert(r.keymap == keymap2)
def i2c_read_ui(address, reg=None): global last_values if reg == True: reg = UniversalInput(i, o, message="Register:", charmap="hex").activate() if reg is None: # User picked "cancel" return if isinstance(reg, basestring): reg = int(reg, 16) last_values = [] values_on_screen = o.cols def read_value( ): # A helper function to read a value and format it into a list global last_values try: if reg: answer = "{} {}".format( hex(reg), hex(current_bus.read_byte_data(address, reg))) else: answer = hex(current_bus.read_byte(address)) except IOError: answer = "{} error".format(reg) if reg else "error" last_values.append(answer) last_values = last_values[:values_on_screen] return list(reversed(last_values)) r = Refresher(read_value, i, o) def change_interval( ): # A helper function to adjust the Refresher's refresh interval while it's running new_interval = IntegerAdjustInput( r.refresh_interval, i, o, message="Refresh interval:").activate() if new_interval is not None: r.set_refresh_interval(new_interval) r.update_keymap({"KEY_RIGHT": change_interval}) r.activate()