From 2227f81a7a070ea369cb3d334b63373ee77ae155 Mon Sep 17 00:00:00 2001 From: platinops Date: Thu, 8 Sep 2022 00:20:52 +0200 Subject: [PATCH] Apply default black code style --- examples/issues/issue_279_key_error.py | 27 +++-- .../quasar_tutorial/QRating/rating_test1.py | 84 +++++++++++--- .../quasar_tutorial/QRating/rating_test2.py | 22 +++- examples/tutorial/routes/bye_function1.py | 14 ++- examples/tutorial/routes/route1.py | 11 +- examples/tutorial/routes/route2.py | 15 ++- examples/tutorial/routes/route3.py | 15 ++- jpcore/template.py | 65 ++++++----- justpy/chartcomponents.py | 7 +- justpy/htmlcomponents.py | 1 + justpy/justpy.py | 17 +-- tests/test_benchmark_decode.py | 23 ++-- tests/test_importability.py | 2 +- tests/test_route.py | 48 ++++---- tests/test_template.py | 106 ++++++++++-------- tests/test_tutorial.py | 21 ++-- tests/test_with_selenium.py | 34 +++--- 17 files changed, 320 insertions(+), 192 deletions(-) diff --git a/examples/issues/issue_279_key_error.py b/examples/issues/issue_279_key_error.py index 83e38f46..e7b0008a 100644 --- a/examples/issues/issue_279_key_error.py +++ b/examples/issues/issue_279_key_error.py @@ -2,33 +2,44 @@ import justpy as jp import time + def button_click(self, _msg): """ on button click delete the components of the button """ self.num_clicked += 1 - self.message.text = f'{self.text} clicked. Number of clicks: {self.num_clicked}' - self.set_class('bg-red-500') - self.set_class('bg-red-700', 'hover') + self.message.text = f"{self.text} clicked. Number of clicks: {self.num_clicked}" + self.set_class("bg-red-500") + self.set_class("bg-red-700", "hover") self.button_div.delete_components() # wait a bit so that another button may be clicked time.sleep(3) + def issue_279(): """ show misbehavior of handle_events when a message for a non existing component arrives """ number_of_buttons = 25 wp = jp.WebPage() - button_div = jp.Div(classes='flex m-4 flex-wrap', a=wp) - button_classes = 'w-32 mr-2 mb-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full' - message = jp.Div(text='No button clicked yet', classes='text-2xl border m-4 p-2', a=wp) + button_div = jp.Div(classes="flex m-4 flex-wrap", a=wp) + button_classes = "w-32 mr-2 mb-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full" + message = jp.Div( + text="No button clicked yet", classes="text-2xl border m-4 p-2", a=wp + ) for i in range(1, number_of_buttons + 1): - b = jp.Button(text=f'Button {i}', a=button_div, classes=button_classes, click=button_click, button_div=button_div) + b = jp.Button( + text=f"Button {i}", + a=button_div, + classes=button_classes, + click=button_click, + button_div=button_div, + ) b.message = message b.num_clicked = 0 return wp + from examples.basedemo import Demo -Demo("Issue 279 KeyError", issue_279) +Demo("Issue 279 KeyError", issue_279) diff --git a/examples/quasar_tutorial/QRating/rating_test1.py b/examples/quasar_tutorial/QRating/rating_test1.py index 5053e712..548f9abf 100644 --- a/examples/quasar_tutorial/QRating/rating_test1.py +++ b/examples/quasar_tutorial/QRating/rating_test1.py @@ -1,22 +1,76 @@ # Justpy Tutorial demo rating_test1 from docs/quasar_tutorial/QRating.md import justpy as jp + def rating_test1(): - wp = jp.QuasarPage(data={'rating': 2}) - d = jp.Div(classes='q-pa-md', a=wp) - rating_div = jp.Div(classes='q-gutter-y-md column', a=d) - jp.QRating(size='1.5em', icon='thumb_up', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='2em', icon='favorite_border',color='red-7', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='2.5em', icon='create',color='purple-4', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='3em', icon='pets',color='brown-5', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='4.5em', icon='star_border',color='green-5', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='5em', icon='star_border',icon_selected='star',color='grey', a=rating_div, model=[wp, 'rating'], - color_selected=['light-green-3', 'light-green-6', 'green', 'green-9', 'green-10']) - jp.QRating(size='5em', icon='star_border',icon_selected='star',color='green-5', a=rating_div, model=[wp, 'rating']) - jp.QRating(size='3.5em', max=4,color='red-5', a=rating_div, model=[wp, 'rating'], - icon=['sentiment_very_dissatisfied', 'sentiment_dissatisfied', 'sentiment_satisfied', 'sentiment_very_satisfied']) + wp = jp.QuasarPage(data={"rating": 2}) + d = jp.Div(classes="q-pa-md", a=wp) + rating_div = jp.Div(classes="q-gutter-y-md column", a=d) + jp.QRating(size="1.5em", icon="thumb_up", a=rating_div, model=[wp, "rating"]) + jp.QRating( + size="2em", + icon="favorite_border", + color="red-7", + a=rating_div, + model=[wp, "rating"], + ) + jp.QRating( + size="2.5em", + icon="create", + color="purple-4", + a=rating_div, + model=[wp, "rating"], + ) + jp.QRating( + size="3em", icon="pets", color="brown-5", a=rating_div, model=[wp, "rating"] + ) + jp.QRating( + size="4.5em", + icon="star_border", + color="green-5", + a=rating_div, + model=[wp, "rating"], + ) + jp.QRating( + size="5em", + icon="star_border", + icon_selected="star", + color="grey", + a=rating_div, + model=[wp, "rating"], + color_selected=[ + "light-green-3", + "light-green-6", + "green", + "green-9", + "green-10", + ], + ) + jp.QRating( + size="5em", + icon="star_border", + icon_selected="star", + color="green-5", + a=rating_div, + model=[wp, "rating"], + ) + jp.QRating( + size="3.5em", + max=4, + color="red-5", + a=rating_div, + model=[wp, "rating"], + icon=[ + "sentiment_very_dissatisfied", + "sentiment_dissatisfied", + "sentiment_satisfied", + "sentiment_very_satisfied", + ], + ) return wp + # initialize the demo -from examples.basedemo import Demo -Demo ("rating_test1",rating_test1) +from examples.basedemo import Demo + +Demo("rating_test1", rating_test1) diff --git a/examples/quasar_tutorial/QRating/rating_test2.py b/examples/quasar_tutorial/QRating/rating_test2.py index 8a91b600..a5cd7938 100644 --- a/examples/quasar_tutorial/QRating/rating_test2.py +++ b/examples/quasar_tutorial/QRating/rating_test2.py @@ -1,17 +1,27 @@ # Justpy Tutorial demo rating_test2 from docs/quasar_tutorial/QRating.md import justpy as jp + def rating_test2(): wp = jp.QuasarPage() wp.tailwind = True num_stars = 3 - r = jp.QRating(size='2em', max=num_stars, color='primary', classes='m-2 p-2', a=wp, value=2, debounce=0) - for i in range(1,num_stars + 1,1): - t = jp.QTooltip(text=f'{i} rating') - r.add_scoped_slot(f'tip-{i}', t) + r = jp.QRating( + size="2em", + max=num_stars, + color="primary", + classes="m-2 p-2", + a=wp, + value=2, + debounce=0, + ) + for i in range(1, num_stars + 1, 1): + t = jp.QTooltip(text=f"{i} rating") + r.add_scoped_slot(f"tip-{i}", t) return wp # initialize the demo -from examples.basedemo import Demo -Demo ("rating_test2",rating_test2) +from examples.basedemo import Demo + +Demo("rating_test2", rating_test2) diff --git a/examples/tutorial/routes/bye_function1.py b/examples/tutorial/routes/bye_function1.py index 73b3b980..95214581 100644 --- a/examples/tutorial/routes/bye_function1.py +++ b/examples/tutorial/routes/bye_function1.py @@ -1,18 +1,22 @@ # Justpy Tutorial demo bye_function1 from docs/tutorial/routes.md import justpy as jp + def hello_function2(): wp = jp.WebPage() - wp.add(jp.P(text='Hello there!', classes='text-5xl m-2')) + wp.add(jp.P(text="Hello there!", classes="text-5xl m-2")) return wp + def bye_function1(): wp = jp.WebPage() - wp.add(jp.P(text='Goodbye!', classes='text-5xl m-2')) + wp.add(jp.P(text="Goodbye!", classes="text-5xl m-2")) return wp -jp.Route('/hello', hello_function2) + +jp.Route("/hello", hello_function2) # initialize the demo -from examples.basedemo import Demo -Demo ("bye_function1",bye_function1) +from examples.basedemo import Demo + +Demo("bye_function1", bye_function1) diff --git a/examples/tutorial/routes/route1.py b/examples/tutorial/routes/route1.py index e484b1f9..a1cb55f0 100644 --- a/examples/tutorial/routes/route1.py +++ b/examples/tutorial/routes/route1.py @@ -1,13 +1,16 @@ # Justpy Tutorial demo from docs/tutorial/routes.md import justpy as jp + def hello_function1(): wp = jp.WebPage() - wp.add(jp.P(text='Hello there!', classes='text-5xl m-2')) + wp.add(jp.P(text="Hello there!", classes="text-5xl m-2")) return wp -jp.Route('/hello', hello_function1) + +jp.Route("/hello", hello_function1) # initialize the demo -from examples.basedemo import Demo -Demo ("route1",None) \ No newline at end of file +from examples.basedemo import Demo + +Demo("route1", None) diff --git a/examples/tutorial/routes/route2.py b/examples/tutorial/routes/route2.py index 2376b0de..54f9ecea 100644 --- a/examples/tutorial/routes/route2.py +++ b/examples/tutorial/routes/route2.py @@ -1,19 +1,22 @@ # Justpy Tutorial demo from docs/tutorial/routes.md import justpy as jp -@jp.SetRoute('/hello') + +@jp.SetRoute("/hello") def hello_function3(): wp = jp.WebPage() - wp.add(jp.P(text='Hello there!', classes='text-5xl m-2')) + wp.add(jp.P(text="Hello there!", classes="text-5xl m-2")) return wp -@jp.SetRoute('/bye') + +@jp.SetRoute("/bye") def bye_function2(): wp = jp.WebPage() - wp.add(jp.P(text='Goodbye!', classes='text-5xl m-2')) + wp.add(jp.P(text="Goodbye!", classes="text-5xl m-2")) return wp # initialize the demo -from examples.basedemo import Demo -Demo ("route2",None) +from examples.basedemo import Demo + +Demo("route2", None) diff --git a/examples/tutorial/routes/route3.py b/examples/tutorial/routes/route3.py index 4c5b8b64..b652cb81 100644 --- a/examples/tutorial/routes/route3.py +++ b/examples/tutorial/routes/route3.py @@ -1,12 +1,17 @@ # Justpy Tutorial demo from docs/tutorial/routes.md import justpy as jp + + def greeting_function(request): wp = jp.WebPage() - name=f"""{request.path_params["name"]}""" - wp.add(jp.P(text=f'Hello there, {name}!', classes='text-5xl m-2')) + name = f"""{request.path_params["name"]}""" + wp.add(jp.P(text=f"Hello there, {name}!", classes="text-5xl m-2")) return wp -jp.Route('/hello/{name}', greeting_function) + + +jp.Route("/hello/{name}", greeting_function) # initialize the demo -from examples.basedemo import Demo -Demo ("route3",None) +from examples.basedemo import Demo + +Demo("route3", None) diff --git a/jpcore/template.py b/jpcore/template.py index c54d0189..bcd487af 100644 --- a/jpcore/template.py +++ b/jpcore/template.py @@ -1,33 +1,35 @@ -''' +""" Created on 2022-09-07 @author: wf -''' +""" + + class Context: - """ + """ legacy context handler, encapsulates context """ - - def __init__(self,context_dict:dict): + + def __init__(self, context_dict: dict): """ constructor - + Args: context_dict(dict): a context dict in legacy format """ - self.context_dict=context_dict - self.page_options=PageOptions(context_dict.get("page_options",{})) - + self.context_dict = context_dict + self.page_options = PageOptions(context_dict.get("page_options", {})) + def as_javascript(self): """ generate my initial JavaScript """ - title=self.page_options.get_title() - debug=str(self.page_options.get_debug()).lower() - page_ready=str(self.page_options.get_page_ready()).lower() - result_ready=str(self.page_options.get_result_ready()).lower() - reload_interval_ms=self.page_options.get_reload_interval_ms() - javascript=f"""let justpy_core=new JustpyCore( + title = self.page_options.get_title() + debug = str(self.page_options.get_debug()).lower() + page_ready = str(self.page_options.get_page_ready()).lower() + result_ready = str(self.page_options.get_result_ready()).lower() + reload_interval_ms = self.page_options.get_reload_interval_ms() + javascript = f"""let justpy_core=new JustpyCore( this, // window '{title}', // title {page_ready}, // page_ready @@ -36,32 +38,33 @@ def as_javascript(self): {debug} // debug );""" return javascript - + + class PageOptions: """ legacy page_options handler, encapsulating page_options """ - - def __init__(self,page_options_dict:dict): - self.page_options_dict=page_options_dict - self.events=page_options_dict["events"] - + + def __init__(self, page_options_dict: dict): + self.page_options_dict = page_options_dict + self.events = page_options_dict["events"] + def get_title(self): - return self.page_options_dict.get("title","JustPy") + return self.page_options_dict.get("title", "JustPy") def get_debug(self): - return self.page_options_dict.get("debug",False) - + return self.page_options_dict.get("debug", False) + def get_page_ready(self): return "page_ready" in self.events - + def get_result_ready(self): return "result_ready" in self.events - - def get_reload_interval_ms(self)->float: - reload_interval=self.page_options_dict.get("reload_interval",0) + + def get_reload_interval_ms(self) -> float: + reload_interval = self.page_options_dict.get("reload_interval", 0) if reload_interval: - ms=round(reload_interval*1000) + ms = round(reload_interval * 1000) else: - ms=0 - return ms \ No newline at end of file + ms = 0 + return ms diff --git a/justpy/chartcomponents.py b/justpy/chartcomponents.py index b6aefdf7..5d13c7c8 100644 --- a/justpy/chartcomponents.py +++ b/justpy/chartcomponents.py @@ -450,6 +450,7 @@ def set_figure(self, fig=None): output.close() return self.inner_html + # -------------------------------------------------------------------- # deck.gl related objects @@ -465,6 +466,7 @@ def set_figure(self, fig=None): _has_pydeck = False if _has_pydeck: + class PyDeckFrame(Iframe): vue_type = "iframejp" @@ -487,7 +489,6 @@ def convert_object_to_dict(self): d["transition_duration"] = self.transition_duration return d - class PyDeck(Div): vue_type = "deckgl" @@ -511,6 +512,7 @@ def convert_object_to_dict(self): d["mapbox_key"] = self.deck.mapbox_key return d + try: import altair as alt @@ -550,6 +552,7 @@ def convert_object_to_dict(self): d["options"] = self.options return d + try: import plotly @@ -588,6 +591,7 @@ def convert_object_to_dict(self): d["config"] = self.config return d + try: import bokeh @@ -626,6 +630,7 @@ def convert_object_to_dict(self): d["config"] = self.config return d + try: import folium diff --git a/justpy/htmlcomponents.py b/justpy/htmlcomponents.py index 29815c24..69c4149c 100644 --- a/justpy/htmlcomponents.py +++ b/justpy/htmlcomponents.py @@ -49,6 +49,7 @@ def __call__(self, cls, **kwargs): register_component(cls, self.tag, self.attributes) return cls + class WebPage: # TODO: Add page events online, beforeunload, resize instances = {} diff --git a/justpy/justpy.py b/justpy/justpy.py index ef118b3e..045a9795 100644 --- a/justpy/justpy.py +++ b/justpy/justpy.py @@ -85,6 +85,7 @@ NO_INTERNET = config("NO_INTERNET", cast=bool, default=True) HTML_404_PAGE = "justpy is sorry - that path doesn't exist" + def create_component_file_list(): file_list = [] component_dir = os.path.join(STATIC_DIRECTORY, "components") @@ -257,8 +258,8 @@ async def get(self, request): "html": load_page.html, } # wrap the context in a context object to make it available - context_obj=Context(context) - context["context_obj"]=context_obj + context_obj = Context(context) + context["context_obj"] = context_obj response = templates.TemplateResponse(load_page.template_file, context) if SESSIONS and new_cookie: cookie_value = cookie_signer.sign(request.state.session_id) @@ -418,13 +419,15 @@ async def handle_event(data_dict, com_type=0, page_event=False): if page_event: c = p else: - component_id=event_data["id"] - c=JustpyBaseComponent.instances.get(component_id,None) + component_id = event_data["id"] + c = JustpyBaseComponent.instances.get(component_id, None) if c is not None: event_data["target"] = c else: - logging.warning(f"component with id {component_id} doesn't exist (anymore ...) it might have been deleted before the event handling was triggered") - + logging.warning( + f"component with id {component_id} doesn't exist (anymore ...) it might have been deleted before the event handling was triggered" + ) + try: if c is not None: before_result = await c.run_event_function("before", event_data, True) @@ -440,7 +443,7 @@ async def handle_event(data_dict, com_type=0, page_event=False): event_result = None logging.debug(f"{c} has no {event_data['event_type']} event handler") else: - event_result = None + event_result = None logging.debug(f"Event result:{event_result}") except Exception as e: # raise Exception(e) diff --git a/tests/test_benchmark_decode.py b/tests/test_benchmark_decode.py index 420837cd..5fa012fc 100644 --- a/tests/test_benchmark_decode.py +++ b/tests/test_benchmark_decode.py @@ -48,8 +48,11 @@ def test_decode_time_demjson(self): """ test demjson """ - elapsed = timeit(lambda: demjson.decode(self.options_string.encode("ascii", "ignore")), number=1000) - print(f'Time: {elapsed:.2f}s') + elapsed = timeit( + lambda: demjson.decode(self.options_string.encode("ascii", "ignore")), + number=1000, + ) + print(f"Time: {elapsed:.2f}s") self.assertGreater(elapsed, 0.0) def test_decode_time_yaml(self): @@ -57,9 +60,11 @@ def test_decode_time_yaml(self): test yaml """ - elapsed = timeit(lambda: yaml.full_load(self.options_string.encode("ascii", "ignore")), - number=1000) - print(f'Time: {elapsed:.2f}s') + elapsed = timeit( + lambda: yaml.full_load(self.options_string.encode("ascii", "ignore")), + number=1000, + ) + print(f"Time: {elapsed:.2f}s") self.assertGreater(elapsed, 0.0) def test_decode_time_hjson(self): @@ -67,7 +72,9 @@ def test_decode_time_hjson(self): test hjson """ - elapsed = timeit(lambda: hjson.loads(self.options_string.encode("ascii", "ignore")), - number=1000) - print(f'Time: {elapsed:.2f}s') + elapsed = timeit( + lambda: hjson.loads(self.options_string.encode("ascii", "ignore")), + number=1000, + ) + print(f"Time: {elapsed:.2f}s") self.assertGreater(elapsed, 0.0) diff --git a/tests/test_importability.py b/tests/test_importability.py index b5b51ae8..6bdc1860 100644 --- a/tests/test_importability.py +++ b/tests/test_importability.py @@ -28,7 +28,7 @@ def test_importability(self): assert justpy outputText = outputBuf.getvalue() debug = self.debug - #debug=True + # debug=True if debug: print(outputText) self.assertTrue("Module directory" in outputText) diff --git a/tests/test_route.py b/tests/test_route.py index c2b4cc42..35259c87 100644 --- a/tests/test_route.py +++ b/tests/test_route.py @@ -12,13 +12,15 @@ from justpy.routing import JpRoute from tests.basetest import Basetest -@jp.SetRoute('/greet/{name}') + +@jp.SetRoute("/greet/{name}") def greeting_function(request): wp = jp.WebPage() - name=f"""{request.path_params["name"]}""" - wp.add(jp.P(text=f'Hello there, {name}!', classes='text-5xl m-2')) + name = f"""{request.path_params["name"]}""" + wp.add(jp.P(text=f"Hello there, {name}!", classes="text-5xl m-2")) return wp + @jp.SetRoute("/bye", name="bye") def bye_function(_request): wp = jp.WebPage() @@ -38,10 +40,10 @@ class TestRouteAndUrlFor(Basetest): """ test the url_for functionality """ - + def setUp(self, debug=False, profile=True): Basetest.setUp(self, debug=debug, profile=profile) - self.app=jp.app + self.app = jp.app def testRoute(self): """ @@ -54,20 +56,20 @@ def testRoute(self): route_as_text = str(route) if debug: print(route_as_text) - for path in ["/bye", "/hello","/greet/{name}"]: + for path in ["/bye", "/hello", "/greet/{name}"]: self.assertTrue(path in JpRoute.routes_by_path) - - def checkResponse(self,path,expected_code=200,debug:bool=None): + + def checkResponse(self, path, expected_code=200, debug: bool = None): """ check the response for the given path - + Args: path(str): the path to check expected_code(int): the HTTP status code to expect debug(bool): if True show debugging info """ if debug is None: - debug=self.debug + debug = self.debug with TestClient(self.app) as client: response = client.get(path) self.assertEqual(expected_code, response.status_code) @@ -79,27 +81,27 @@ def testUrlFor(self): """ Test url for functionality """ - #@TODO - not implemented yet + # @TODO - not implemented yet pass - + def testInvalidPath(self): - ''' + """ test handling an invalid path - ''' - response=self.checkResponse("/invalidpath",404) - self.assertEqual(jp.HTML_404_PAGE,response.text) - + """ + response = self.checkResponse("/invalidpath", 404) + self.assertEqual(jp.HTML_404_PAGE, response.text) + def testStaticPath(self): - ''' + """ test handling static content - ''' - response=self.checkResponse("/templates/js/justpy_core.js") + """ + response = self.checkResponse("/templates/js/justpy_core.js") self.assertTrue("class JustpyCore" in response.text) - response=self.checkResponse("/templates/css/invalid_css.css",404) - + response = self.checkResponse("/templates/css/invalid_css.css", 404) + def testHtmlContent(self): # see https://www.starlette.io/testclient/ - response=self.checkResponse("/hello") + response = self.checkResponse("/hello") debug = self.debug debug = True lines = response.text.split("\n") diff --git a/tests/test_template.py b/tests/test_template.py index 274ba916..9b915c7c 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -1,8 +1,8 @@ -''' +""" Created on 2022-09-07 @author: wf -''' +""" from tests.basetest import Basetest from jpcore.template import Context @@ -11,55 +11,67 @@ class TestTemplate(Basetest): """ Tests template handling """ - + def test_javascript(self): """ test javascript generation """ - context_dict={'html': '', - 'justpy_dict': '[{"attrs": {}, "id": null, "vue_type": "html_component", ' - '"show": true, "events": [], "event_modifiers": {}, "classes": ' - '"text-5xl m-2", "style": "", "set_focus": false, "html_tag": ' - '"p", "class_name": "P", "event_propagation": true, ' - '"inner_html": "", "animation": false, "debug": false, ' - '"transition": null, "directives": {}, "scoped_slots": {}, ' - '"object_props": [], "text": "Hello there!"}]', - 'options': {'aggrid': True, - 'aggrid_enterprise': False, - 'bokeh': False, - 'component_file_list': [], - 'deckgl': False, - 'highcharts': True, - 'katex': False, - 'no_internet': True, - 'plotly': False, - 'quasar': False, - 'quasar_version': None, - 'static_name': 'static', - 'tailwind': True, - 'vega': False}, - 'page_id': 0, - 'page_options': {'body_classes': '', - 'body_html': '', - 'body_style': '', - 'css': '', - 'dark': False, - 'debug': False, - 'display_url': None, - 'events': [], - 'favicon': '', - 'head_html': '', - 'highcharts_theme': None, - 'redirect': None, - 'reload_interval': None, - 'title': 'JustPy'}, - 'request': None, - 'use_websockets': 'true'} - context_obj=Context(context_dict) - js=context_obj.as_javascript() - debug=True + context_dict = { + "html": "", + "justpy_dict": '[{"attrs": {}, "id": null, "vue_type": "html_component", ' + '"show": true, "events": [], "event_modifiers": {}, "classes": ' + '"text-5xl m-2", "style": "", "set_focus": false, "html_tag": ' + '"p", "class_name": "P", "event_propagation": true, ' + '"inner_html": "", "animation": false, "debug": false, ' + '"transition": null, "directives": {}, "scoped_slots": {}, ' + '"object_props": [], "text": "Hello there!"}]', + "options": { + "aggrid": True, + "aggrid_enterprise": False, + "bokeh": False, + "component_file_list": [], + "deckgl": False, + "highcharts": True, + "katex": False, + "no_internet": True, + "plotly": False, + "quasar": False, + "quasar_version": None, + "static_name": "static", + "tailwind": True, + "vega": False, + }, + "page_id": 0, + "page_options": { + "body_classes": "", + "body_html": "", + "body_style": "", + "css": "", + "dark": False, + "debug": False, + "display_url": None, + "events": [], + "favicon": "", + "head_html": "", + "highcharts_theme": None, + "redirect": None, + "reload_interval": None, + "title": "JustPy", + }, + "request": None, + "use_websockets": "true", + } + context_obj = Context(context_dict) + js = context_obj.as_javascript() + debug = True if debug: print(js) - for param in ["window","title","page_ready","result_ready","reload_interval","debug"]: + for param in [ + "window", + "title", + "page_ready", + "result_ready", + "reload_interval", + "debug", + ]: self.assertTrue(f"// {param}" in js) - diff --git a/tests/test_tutorial.py b/tests/test_tutorial.py index 9ef6d687..de5f55e3 100644 --- a/tests/test_tutorial.py +++ b/tests/test_tutorial.py @@ -12,6 +12,7 @@ from examples.basedemo import Demo from testfixtures import LogCapture + class TestWithSelenium(BaseAsynctest): """ testing actual browser behavior with selenium @@ -76,23 +77,24 @@ async def testClickDemo(self): self.browser.close() await asyncio.sleep(self.server.sleep_time) await self.server.stop() - + async def testIssue279(self): """ see https://github.com/justpy-org/justpy/issues/279 - + """ self.browser = SeleniumBrowsers(headless=Basetest.inPublicCI()).getFirst() await asyncio.sleep(self.server.sleep_time) - Demo.testmode=True + Demo.testmode = True from examples.issues.issue_279_key_error import issue_279 + with LogCapture() as lc: await self.server.start(issue_279) url = self.server.get_url("/") self.browser.get(url) await asyncio.sleep(self.server.sleep_time) buttons = self.browser.find_elements(By.TAG_NAME, "button") - debug=True + debug = True if debug: print(f"found {len(buttons)} buttons") await asyncio.sleep(0.5) @@ -102,13 +104,12 @@ async def testIssue279(self): await asyncio.sleep(3.2) if debug: print(f"log capture: {str(lc)}") - expecteds=[ + expecteds = [ "component with id", - "doesn't exist (anymore ...) it might have been deleted before the event handling was triggered" + "doesn't exist (anymore ...) it might have been deleted before the event handling was triggered", ] - for i,expected in enumerate(expecteds): - self.assertTrue(expected in str(lc),f"{i}:{expected}") - + for i, expected in enumerate(expecteds): + self.assertTrue(expected in str(lc), f"{i}:{expected}") + self.browser.close() await self.server.stop() - diff --git a/tests/test_with_selenium.py b/tests/test_with_selenium.py index 7764d99f..9b9acd3f 100644 --- a/tests/test_with_selenium.py +++ b/tests/test_with_selenium.py @@ -13,6 +13,7 @@ from examples.basedemo import Demo from testfixtures import LogCapture + class TestWithSelenium(BaseAsynctest): """ testing actual browser behavior with selenium @@ -77,53 +78,56 @@ async def testClickDemo(self): self.browser.close() await asyncio.sleep(self.server.sleep_time) await self.server.stop() - + async def testIssue279(self): """ see https://github.com/justpy-org/justpy/issues/279 - + """ self.browser = SeleniumBrowsers(headless=Basetest.inPublicCI()).getFirst() await asyncio.sleep(self.server.sleep_time) - Demo.testmode=True + Demo.testmode = True from examples.issues.issue_279_key_error import issue_279 + await self.server.start(issue_279) url = self.server.get_url("/") self.browser.get(url) await asyncio.sleep(self.server.sleep_time) buttons = self.browser.find_elements(By.TAG_NAME, "button") - debug=True + debug = True if debug: print(f"found {len(buttons)} buttons") await asyncio.sleep(0.5) - ok='False' + ok = "False" with LogCapture() as lc: try: - for buttonIndex in [0,1,2,3]: + for buttonIndex in [0, 1, 2, 3]: buttons[buttonIndex].click() await asyncio.sleep(0.25) await asyncio.sleep(1.0) - for buttonIndex in [0,1,2,3]: + for buttonIndex in [0, 1, 2, 3]: buttons[buttonIndex].click() await asyncio.sleep(0.25) except selenium.common.exceptions.StaleElementReferenceException: if debug: - print("Expected sideeffect: Selenium already complains about missing button") - ok=True + print( + "Expected sideeffect: Selenium already complains about missing button" + ) + ok = True pass await asyncio.sleep(3.2) if debug: print(f"log capture: {str(lc)}") - expecteds=[ + expecteds = [ "component with id", - "doesn't exist (anymore ...) it might have been deleted before the event handling was triggered" + "doesn't exist (anymore ...) it might have been deleted before the event handling was triggered", ] - for i,expected in enumerate(expecteds): + for i, expected in enumerate(expecteds): if not ok: - self.assertTrue(expected in str(lc),f"{i}:{expected}") + self.assertTrue(expected in str(lc), f"{i}:{expected}") else: if not expected in str(lc): print(f"{i}:{expected} missing in captured log") - + self.browser.close() - await self.server.stop() \ No newline at end of file + await self.server.stop()