Skip to content

Use the new testing machinery for test_examples#676

Merged
fpliger merged 15 commits into
mainfrom
antocuni/refactor-test-examples
Aug 12, 2022
Merged

Use the new testing machinery for test_examples#676
fpliger merged 15 commits into
mainfrom
antocuni/refactor-test-examples

Conversation

@antocuni

@antocuni antocuni commented Aug 10, 2022

Copy link
Copy Markdown
Contributor

This PR refactor test_examples.py to use the new testing machinery.
Moreover, instead of using a single semi-complicated parametrized test, it uses an individual test for each example.
Currently most of them are very similar because they just check the page title and a simple pattern, but by doing so we make it possible to improve them: the idea is that each of them should become be improved to actually check that the example does what it is intended, like what we do for example with test_simple_clock:

def test_simple_clock(self):
self.goto("examples/simple_clock.html")
self.wait_for_pyscript()
assert self.page.title() == "Simple Clock Demo"
pattern = r"\d{2}/\d{2}/\d{4}, \d{2}:\d{2}:\d{2}"
# run for 5 seconds to be sure that we see the page with "It's
# espresso time!"
for _ in range(5):
content = self.page.inner_html("#outputDiv2")
if re.match(pattern, content) and int(content[-1]) in (0, 4, 8):
assert self.page.inner_html("#outputDiv3") == "It's espresso time!"
break
else:
time.sleep(1)
else:
assert False, "Espresso time not found :("

Three tests are marked with @xfail because of issues which were found during the refactoring: #673, #677, #678. I think this should not be a blocker to merge this PR, since the problems were already present and the old tests worked just because they were not as strict as the new ones.

@antocuni antocuni added the sprint issue has been pulled into current sprint and is actively being worked on label Aug 10, 2022
@antocuni antocuni changed the title WIP: use the new testing machinery for test_examples Use the new testing machinery for test_examples Aug 10, 2022
@antocuni antocuni marked this pull request as ready for review August 10, 2022 16:25
@philippjfr

Copy link
Copy Markdown
Contributor

Much better!

@fpliger fpliger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way better! That's awesome to see! Thank you !

@fpliger fpliger merged commit 817d0ed into main Aug 12, 2022
@fpliger fpliger deleted the antocuni/refactor-test-examples branch August 12, 2022 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint issue has been pulled into current sprint and is actively being worked on

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants