Best Python code snippet using autotest_python
test_events.py
Source:test_events.py
1import pytest2from bokeh.models import Plot, Button, Div3from bokeh import events4concrete_events = set([v for v in globals().values()5 if isinstance(v,type) and issubclass(v, events.Event) and v.event_name is not None])6point_events = set([v for v in globals().values()7 if isinstance(v,type) and issubclass(v, events.PointEvent)])8class EventCallback(object):9 def __init__(self, attributes=[]):10 self.event_name = None11 self.attributes = attributes12 self.payload = {}13 def __call__(self, event):14 self.event_name = event.event_name15 self.payload = {attr:getattr(event, attr) for attr in self.attributes}16def test_event_metaclass():17 # All events currently in the namespace should be in the EVENT_CLASSES set18 assert len(concrete_events - set(events._CONCRETE_EVENT_CLASSES.values())) == 019def test_common_decode_json():20 for event_name, event_cls in events._CONCRETE_EVENT_CLASSES.items():21 if event_name is None: continue # Skip abstract base class22 event = events.Event.decode_json({'event_name':event_cls.event_name,23 'event_values':{'model_id':'test-model-id'}})24 assert event._model_id == 'test-model-id'25def test_pointevent_subclass_decode_json():26 event_values = dict(model_id='test-model-id', sx=3, sy=-2, x=10, y=100)27 for event_cls in point_events:28 if event_cls.event_name is None: continue # Skip abstract base class29 event = events.Event.decode_json({'event_name': event_cls.event_name,30 'event_values': event_values.copy()})31 assert event.sx == 332 assert event.sy == -233 assert event.x == 1034 assert event.y == 10035 assert event._model_id == 'test-model-id'36def test_panevent_decode_json():37 event_values = dict(model_id='test-model-id', delta_x=0.1, delta_y=0.3,38 sx=3, sy=-2, x=10, y=100)39 event = events.Event.decode_json({'event_name': events.Pan.event_name,40 'event_values': event_values.copy()})41 assert event.delta_x == 0.142 assert event.delta_y == 0.343 assert event.sx == 344 assert event.sy == -245 assert event.x == 1046 assert event.y == 10047 assert event._model_id == 'test-model-id'48def test_mousewheelevent_decode_json():49 event_values = dict(model_id='test-model-id', delta=-0.1, sx=3, sy=-2, x=10, y=100)50 event = events.Event.decode_json({'event_name': events.MouseWheel.event_name,51 'event_values': event_values.copy()})52 assert event.delta == -0.153 assert event.sx == 354 assert event.sy == -255 assert event.x == 1056 assert event.y == 10057 assert event._model_id == 'test-model-id'58def test_pinchevent_decode_json():59 event_values = dict(model_id='test-model-id', scale=42, sx=3, sy=-2, x=10, y=100)60 event = events.Event.decode_json({'event_name': events.Pinch.event_name,61 'event_values': event_values.copy()})62 assert event.scale == 4263 assert event.sx == 364 assert event.sy == -265 assert event.x == 1066 assert event.y == 10067 assert event._model_id == 'test-model-id'68def test_event_constructor_button():69 model = Button()70 event = events.Event(model)71 assert event._model_id == model._id72def test_event_constructor_div():73 model = Div()74 event = events.Event(model)75 assert event._model_id == model._id76def test_event_constructor_plot():77 model = Plot()78 event = events.Event(model)79 assert event._model_id == model._id80def test_buttonclick_constructor_button():81 model = Button()82 event = events.ButtonClick(model)83 assert event._model_id == model._id84def test_buttonclick_constructor_div():85 with pytest.raises(ValueError):86 events.ButtonClick(Div())87def test_buttonclick_constructor_plot():88 with pytest.raises(ValueError):89 events.ButtonClick(Plot())90def test_lodstart_constructor_button():91 with pytest.raises(ValueError):92 events.LODStart(Button())93def test_lodstart_constructor_div():94 with pytest.raises(ValueError):95 events.LODStart(Div())96def test_lodstart_constructor_plot():97 model = Plot()98 event = events.LODStart(model)99 assert event._model_id == model._id100def test_lodend_constructor_button():101 with pytest.raises(ValueError):102 events.LODEnd(Button())103def test_lodend_constructor_div():104 with pytest.raises(ValueError):105 events.LODEnd(Div())106def test_lodend_constructor_plot():107 model = Plot()108 event = events.LODEnd(model)109 assert event._model_id == model._id110def test_plotevent_constructor_button():111 with pytest.raises(ValueError):112 events.PlotEvent(Button())113def test_plotevent_constructor_div():114 with pytest.raises(ValueError):115 events.PlotEvent(Div())116def test_plotevent_constructor_plot():117 model = Plot()118 event = events.PlotEvent(model)119 assert event._model_id == model._id120def test_pointEvent_constructor_plot():121 model = Plot()122 event = events.PointEvent(model, sx=3, sy=-2, x=10, y=100)123 assert event.sx == 3124 assert event.sy == -2125 assert event.x == 10126 assert event.y == 100127 assert event._model_id == model._id128def test_pointevent_constructor_button():129 with pytest.raises(ValueError):130 events.PointEvent(Button(), sx=3, sy=-2, x=10, y=100)131def test_pointevent_constructor_div():132 with pytest.raises(ValueError):133 events.PointEvent(Div(), sx=3, sy=-2, x=10, y=100)134def test_pointevent_subclass_constructor_plot():135 model = Plot()136 for subcls in point_events:137 event = subcls(model, sx=3, sy=-2, x=10, y=100)138 assert event.sx == 3139 assert event.sy == -2140 assert event.x == 10141 assert event.y == 100142 assert event._model_id == model._id143def test_pointevent_subclass_constructor_button():144 model = Button()145 for subcls in point_events:146 with pytest.raises(ValueError):147 subcls(model, sx=3, sy=-2, x=10, y=100)148def test_pointevent_subclass_constructor_div():149 model = Div()150 for subcls in point_events:151 with pytest.raises(ValueError):152 subcls(model, sx=3, sy=-2, x=10, y=100)153# Testing event callback invocation154def test_buttonclick_event_callbacks():155 button = Button()156 test_callback = EventCallback()157 button.on_event(events.ButtonClick, test_callback)158 assert test_callback.event_name == None159 button._trigger_event(events.ButtonClick(button))160 assert test_callback.event_name == events.ButtonClick.event_name161def test_atomic_plot_event_callbacks():162 plot = Plot()163 for event_cls in [events.LODStart, events.LODEnd]:164 test_callback = EventCallback()165 plot.on_event(event_cls, test_callback)166 assert test_callback.event_name == None167 plot._trigger_event(event_cls(plot))168 assert test_callback.event_name == event_cls.event_name169def test_pointevent_callbacks():170 plot = Plot()171 payload = dict(sx=3, sy=-2, x=10, y=100)172 for event_cls in point_events:173 test_callback = EventCallback(['sx','sy','x','y'])174 plot.on_event(event_cls, test_callback)175 assert test_callback.event_name == None176 plot._trigger_event(event_cls(plot, **payload))177 assert test_callback.event_name == event_cls.event_name178 assert test_callback.payload == payload179def test_mousewheel_callbacks():180 plot = Plot()181 payload = dict(sx=3, sy=-2, x=10, y=100, delta=5)182 test_callback = EventCallback(['sx','sy','x','y', 'delta'])183 plot.on_event(events.MouseWheel, test_callback)184 assert test_callback.event_name == None185 plot._trigger_event(events.MouseWheel(plot, **payload))186 assert test_callback.event_name == events.MouseWheel.event_name187 assert test_callback.payload == payload188def test_pan_callbacks():189 plot = Plot()190 payload = dict(sx=3, sy=-2, x=10, y=100, delta_x=2, delta_y=3.2)191 test_callback = EventCallback(['sx','sy','x','y', 'delta_x', 'delta_y'])192 plot.on_event(events.Pan, test_callback)193 assert test_callback.event_name == None194 plot._trigger_event(events.Pan(plot, **payload))195 assert test_callback.event_name == events.Pan.event_name196 assert test_callback.payload == payload197def test_pinch_callbacks():198 plot = Plot()199 payload = dict(sx=3, sy=-2, x=10, y=100, scale=42)200 test_callback = EventCallback(['sx','sy','x','y', 'scale'])201 plot.on_event(events.Pinch, test_callback)202 assert test_callback.event_name == None203 plot._trigger_event(events.Pinch(plot, **payload))204 assert test_callback.event_name == events.Pinch.event_name...
test_update_menu.py
Source:test_update_menu.py
...13 "auto_login": True,14 "time_in_menu_bar": True,15 "strength_levels_to_practice": [1, 2, 3, 4],16 }17 def test_callback():18 return None19 app.test_callback = test_callback20 app.menu = [21 rumps.MenuItem("Login to Duolingo", callback=app.test_callback),22 rumps.MenuItem("Reload vocabulary", callback=app.test_callback),23 {24 "Settings": [25 rumps.MenuItem("Auto-login", callback=app.test_callback),26 rumps.MenuItem(27 "Show countdown in status bar",28 callback=app.test_callback,29 ),30 {31 "Change strength levels to be included": [...
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!!