-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weâll occasionally send you account related emails.
Already on GitHub? Sign in to your account
đ Tutorial study functionality #58
base: master
Are you sure you want to change the base?
đ Tutorial study functionality #58
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bisgaard-itis please do not forget to fill the PR issue attributes. e.g.
- assignee
- select project
- add labels
- select milestone
Also, the gh issue links render better if you use them in enumerations, ie.g. issue #1
renders
this is how it renders a flat #1
- but this is how it renders in enum Upgrade v0.2Â #1
), f"The version defined in {API_DIR/'config.json'} is not present in {TUTORIAL_CLIENT_COMPATIBILITY_JSON}" | ||
|
||
|
||
@pytest.mark.parametrize("tutorial", get_tutorials()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIP: using ids=
argument will display the parametrization much clearer.
e.g. try running it now and see the output vs
@pytest.mark.parametrize("tutorial", get_tutorials(), ids: lambda p: p.name)
def test_...
``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good tip. I was actually trying to figure out how to do this, but didn't find any good tips on google or perplexity
pytest.skip( | ||
f"{tutorial.relative_to(DOCS_DIR)} is not compatible with osparc.__version__=={osparc.__version__}. See {TUTORIAL_CLIENT_COMPATIBILITY_JSON.name}" | ||
) | ||
print(f"Running {tutorial.relative_to(DOCS_DIR)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this print will be unnecessary if you use the parametrization ids
above.
@pytest.mark.parametrize("tutorial", get_tutorials(), ids: lambda p: p.relative_to(DOCS_DIR))
def test_...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
), f"Some tutorial notebooks are not present in {TUTORIAL_CLIENT_COMPATIBILITY_JSON}" | ||
|
||
# check that version of this repo is present in compatibility json | ||
cur_version: str = json.loads((API_DIR / "config.json").read_text())["python"][ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STYLE: prioritize good variable names and structure to doc.
e.g. these lines of code do not need extra doc
current_version = json.loads((API_DIR / "config.json").read_text())["python"]["version"]
compatible_versions = set(json.loads(TUTORIAL_CLIENT_COMPATIBILITY_JSON.read_text())["versions"].keys())
assert current_version in compatible_versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Will fix
@pytest.mark.parametrize("notebook", all_notebooks) | ||
def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] = {}): | ||
"""Run all notebooks in the documentation""" | ||
def run_notebook(tmp_path: Path, notebook: Path, params: dict[str, Any] = {}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STYLE: every function not being fixtures or tests in a test/*/test_*.py
file are helpers.
- The fixtures are decorated with
pytest.fixture
- Tests are named
test_
- (our convention) helpers use protected prefix, i.e.
def _run_notebook(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I will add a _
in front of these.
@@ -45,3 +46,90 @@ def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] = | |||
kernel_name="python3", | |||
parameters=params, | |||
) | |||
|
|||
|
|||
def get_tutorials(osparc_version: Optional[str] = None) -> List[Path]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIP: I think there is a packaging.version.Version
object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know about that one. However, since here I use the input to extract something from a dict
(loaded from a json). So I think it is makes sense to simply use the string here. Let me know if you disagree.
@@ -45,3 +46,90 @@ def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] = | |||
kernel_name="python3", | |||
parameters=params, | |||
) | |||
|
|||
|
|||
def get_tutorials(osparc_version: Optional[str] = None) -> List[Path]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Optional
or Dict
annotations are because we have to be compatible with 3.6>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this has to be compatible with <3.6. Currently I use 3.9 when developing the client. I can replace the Dict
by dict
, but what about the Optional
? Should that be replaced by <> | None
?
Sorry, I thought I had already filled in all the PR attributes. I will be more careful next time. |
What do these changes do?
Add a first tutorial for the studies entry.
Related issue/s
How to test