Best Python code snippet using slash
test_tn3270.py
Source:test_tn3270.py
...186 _set_characters(cells, 62, 'UNPROTECTED INTENSIFIED'.encode('ibm037'))187 _set_attribute(cells, 85, protected=False, hidden=True)188 _set_characters(cells, 86, 'UNPROTECTED HIDDEN'.encode('ibm037'))189 _set_attribute(cells, 104, protected=True)190 _set_formatting(cells, 104, color=Color.YELLOW)191 _set_characters(cells, 105, 'EAB'.encode('ibm037'))192 _set_formatting(cells, 105, blink=True)193 _set_formatting(cells, 106, reverse=True)194 _set_formatting(cells, 107, underscore=True)195 _set_attribute(cells, 108, protected=True)196 self.session.emulator.cells = cells197 self.session.emulator.dirty = set(range(109))198 self.session.emulator.cursor_address = 8199 # Act200 self.session.render()201 # Assert202 regen_bytes = bytes.fromhex('e0afb1aeb3a4a2b3a4a3e8afb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ecafb1aeb3a4a2b3a4a300a7a8a3a3a4adc0b4adafb1aeb3a4a2b3a4a3c8b4adafb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ccb4adafb1aeb3a4a2b3a4a300a7a8a3a3a4ade0a4a0a1e0')203 for (index, regen_byte) in enumerate(regen_bytes):204 self.terminal.display.buffered_write_byte.assert_any_call(regen_byte, None, index=index)205 self.terminal.display.flush.assert_called()206 self.terminal.display.move_cursor.assert_called_with(index=8)207 self.assertFalse(self.session.emulator.dirty)208 def test_with_eab_feature(self):209 # Arrange210 self.terminal.display = BufferedDisplay(self.terminal, Dimensions(24, 80), 7)211 self.terminal.display.buffered_write_byte = Mock(wraps=self.terminal.display.buffered_write_byte)212 self.terminal.display.move_cursor = Mock(wraps=self.terminal.display.move_cursor)213 self.terminal.display.flush = Mock(wraps=self.terminal.display.flush)214 cells = _create_screen_cells(24, 80)215 _set_attribute(cells, 0, protected=True)216 _set_characters(cells, 1, 'PROTECTED'.encode('ibm037'))217 _set_attribute(cells, 10, protected=True, intensified=True)218 _set_characters(cells, 11, 'PROTECTED INTENSIFIED'.encode('ibm037'))219 _set_attribute(cells, 32, protected=True, hidden=True)220 _set_characters(cells, 33, 'PROTECTED HIDDEN'.encode('ibm037'))221 _set_attribute(cells, 49, protected=False)222 _set_characters(cells, 50, 'UNPROTECTED'.encode('ibm037'))223 _set_attribute(cells, 61, protected=False, intensified=True)224 _set_characters(cells, 62, 'UNPROTECTED INTENSIFIED'.encode('ibm037'))225 _set_attribute(cells, 85, protected=False, hidden=True)226 _set_characters(cells, 86, 'UNPROTECTED HIDDEN'.encode('ibm037'))227 _set_attribute(cells, 104, protected=True)228 _set_formatting(cells, 104, color=Color.YELLOW)229 _set_characters(cells, 105, 'EAB'.encode('ibm037'))230 _set_formatting(cells, 105, blink=True)231 _set_formatting(cells, 106, reverse=True)232 _set_formatting(cells, 107, underscore=True)233 _set_attribute(cells, 108, protected=True)234 self.session.emulator.cells = cells235 self.session.emulator.dirty = set(range(109))236 self.session.emulator.cursor_address = 8237 # Act238 self.session.render()239 # Assert240 regen_bytes = bytes.fromhex('e0afb1aeb3a4a2b3a4a3e8afb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ecafb1aeb3a4a2b3a4a300a7a8a3a3a4adc0b4adafb1aeb3a4a2b3a4a3c8b4adafb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ccb4adafb1aeb3a4a2b3a4a300a7a8a3a3a4ade0a4a0a1e0')241 eab_bytes = bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304080c000')242 for (index, (regen_byte, eab_byte)) in enumerate(zip(regen_bytes, eab_bytes)):243 self.terminal.display.buffered_write_byte.assert_any_call(regen_byte, eab_byte, index=index)244 self.terminal.display.flush.assert_called()245 self.terminal.display.move_cursor.assert_called_with(index=8)246 self.assertFalse(self.session.emulator.dirty)247 def test_keyboard_locked(self):248 # Arrange249 self.session.emulator.cells = _create_screen_cells(24, 80)250 self.session.emulator.dirty = set()251 self.session.emulator.cursor_address = 8252 self.session.emulator.keyboard_locked = True253 # Act254 self.session.render()255 # Assert256 self.terminal.display.status_line.write.assert_called_with(8, bytes.fromhex('f600b2b8b2b3a4ac00'))257 def test_protected_cell_operator_error(self):258 # Arrange259 self.session.emulator.cells = _create_screen_cells(24, 80)260 self.session.emulator.dirty = set()261 self.session.emulator.cursor_address = 8262 self.session.operator_error = ProtectedCellOperatorError()263 # Act264 self.session.render()265 # Assert266 self.terminal.display.status_line.write.assert_called_with(8, bytes.fromhex('f600f8dbd800000000'))267 def test_field_overflow_operator_error(self):268 # Arrange269 self.session.emulator.cells = _create_screen_cells(24, 80)270 self.session.emulator.dirty = set()271 self.session.emulator.cursor_address = 8272 self.session.operator_error = FieldOverflowOperatorError()273 # Act274 self.session.render()275 # Assert276 self.terminal.display.status_line.write.assert_called_with(8, bytes.fromhex('f600db080000000000'))277def _create_terminal(interface):278 terminal_id = TerminalId(0b11110100)279 extended_id = 'c1348300'280 features = { }281 keymap = KEYMAP_3278_2282 terminal = Terminal(InterfaceWrapper(interface), None, terminal_id, extended_id, features, keymap)283 terminal.display.status_line = create_autospec(StatusLine, instance=True)284 return terminal285def _create_screen_cells(rows, columns):286 return [CharacterCell(0x00) for address in range(rows * columns)]287def _set_attribute(cells, index, protected=False, intensified=False, hidden=False):288 display = 2 if intensified else 3 if hidden else 0289 attribute = Attribute((0x20 if protected else 0) | (display << 2))290 cells[index] = AttributeCell(attribute)291def _set_characters(cells, index, bytes_):292 for byte in bytes_:293 cells[index] = CharacterCell(byte)294 index += 1295def _set_formatting(cells, index, color=0x00, blink=False, reverse=False, underscore=False):296 if color == 0x00 and not blink and not reverse and not underscore:297 cells[index].formatting = None298 return299 formatting = CellFormatting()300 formatting.color = color301 formatting.blink = blink302 formatting.reverse = reverse303 formatting.underscore = underscore...
utils.py
Source:utils.py
...44 _name_line = None45 _description_line = None46 def update_preferences(self, preferences):47 self._preferences = preferences48 self._set_formatting()49 @property50 def keep_open(self):51 return str(self._preferences.get('keep_open')).lower() == 'true'52 def menu_items(self, spotify):53 try:54 return self._control_panel(spotify.status)55 except dbus.exceptions.DBusException:56 return self._spotify_not_launched()57 @staticmethod58 def _spotify_not_launched():59 return RenderResultListAction([60 ExtensionResultItem(61 icon=cs.IconPaths.ICON,62 name='Run Spotify desktop app first',63 on_enter=LaunchAppAction(cs.SPOTIFY_PATH)64 ),65 ])66 def _control_panel(self, spotify_status):67 return RenderResultListAction([68 ExtensionResultItem(69 icon=cs.IconPaths.PLAY if spotify_status.playback_status == cs.States.PAUSED else cs.IconPaths.PAUSE,70 name=self._format(self._name_line, spotify_status),71 description=self._format(self._description_line, spotify_status),72 on_enter=ExtensionCustomAction(cs.Actions.PLAY_PAUSE, keep_app_open=self.keep_open),73 ),74 ExtensionResultItem(75 icon=cs.IconPaths.NEXT,76 name='Next track',77 on_enter=ExtensionCustomAction(cs.Actions.NEXT, keep_app_open=self.keep_open),78 ),79 ExtensionResultItem(80 icon=cs.IconPaths.PREVIOUS,81 name='Previous track',82 on_enter=ExtensionCustomAction(cs.Actions.PREVIOUS, keep_app_open=self.keep_open),83 ),84 ])85 def _set_formatting(self):86 formatting = self._preferences.get('custom_format')87 newline = '\n' if '\n' in formatting else cs.NEWLINE_TAG # backward compatibility88 try:89 name_line, description_line = formatting.split(newline, 1)90 description_line = description_line.split(newline)[0]91 except ValueError:92 name_line = formatting93 description_line = ''94 self._name_line, self._description_line = name_line, description_line95 @staticmethod96 def _format(template, spotify_status):97 try:98 return template.format(**spotify_status._asdict())99 except ValueError as err:...
color.py
Source:color.py
...29 def _set_color(self, name):30 self._prev_color = name31 return f"\033[{self.formatting};3{self.color_names.index(name)}m"32 def bold(self):33 return self._set_formatting(1)34 def underline(self):35 return self._set_formatting(4)36 def reset(self):37 self._set_color("white")38 return self._set_formatting(0)39 def _set_formatting(self, num):40 self.formatting = num41 return self._set_color(self._prev_color)42 def filter_color_codes(self, text):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!