From 25f26ecc0c5379615ebdc6f02c1316182745c006 Mon Sep 17 00:00:00 2001 From: pauleveritt Date: Sun, 20 Nov 2022 19:53:55 -0500 Subject: [PATCH] Hack around a timing problem when depolyed, where calculator wasn't yet loaded. --- src/psc/gallery/examples/interest_calculator/calculator.py | 3 +++ src/psc/gallery/examples/interest_calculator/index.html | 5 +---- tests/examples/test_interest_calculator.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/psc/gallery/examples/interest_calculator/calculator.py b/src/psc/gallery/examples/interest_calculator/calculator.py index 9383ffc..f0ddb80 100644 --- a/src/psc/gallery/examples/interest_calculator/calculator.py +++ b/src/psc/gallery/examples/interest_calculator/calculator.py @@ -27,3 +27,6 @@ def setup(): """When Pyodide starts up, enable the Calculate button.""" calculate_button = Element("calc") # noqa calculate_button.element.removeAttribute("disabled") + + +setup() diff --git a/src/psc/gallery/examples/interest_calculator/index.html b/src/psc/gallery/examples/interest_calculator/index.html index c9e8635..7b61460 100644 --- a/src/psc/gallery/examples/interest_calculator/index.html +++ b/src/psc/gallery/examples/interest_calculator/index.html @@ -72,10 +72,7 @@ - - - setup() - + diff --git a/tests/examples/test_interest_calculator.py b/tests/examples/test_interest_calculator.py index 156a401..a5696d2 100644 --- a/tests/examples/test_interest_calculator.py +++ b/tests/examples/test_interest_calculator.py @@ -10,14 +10,14 @@ def test_calculator(fake_document: FakeDocument, fake_element: FakeElement) -> None: """Ensure the loaded interest function works correctly.""" - from psc.gallery.examples.interest_calculator.calculator import interest - fake_document.values["principal"] = "100" fake_document.values["interest_rate"] = "0.1" fake_document.values["time"] = "10" fake_document.values["simple_interest"] = "0.1" fake_document.values["compound_interest"] = "0.1" fake_document.values["calc"] = "Calculate" + from psc.gallery.examples.interest_calculator.calculator import interest + interest() # type: ignore assert fake_document.log[0] == "simple interest: 200" assert fake_document.log[1] == "compound interest: 259"