-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix: adjust OpsTest.tmp_path to avoid os.sep #125
base: main
Are you sure you want to change the base?
fix: adjust OpsTest.tmp_path to avoid os.sep #125
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.
@tonyandrewmeyer looks good -- a few lint issues
Are there docs somewhere on how to run the tests (locally, not relying on CI)? |
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 still looks good. I think the unit tests could be a bit easier to reason about
@patch.object(plugin.OpsTest, "default_model_name", "user/model") | ||
@patch.object(plugin.OpsTest, "_setup_model", AsyncMock()) | ||
@patch.object(plugin.OpsTest, "_cleanup_models", AsyncMock()) | ||
def test_tmp_path_with_nonpath_chars(pytester): | ||
pytester.makepyfile( | ||
f""" | ||
import os | ||
from pathlib import Path | ||
|
||
os.environ.update(**{ENV}) | ||
async def test_with_tox(ops_test): | ||
assert ops_test.tmp_path.name == "user_model0" | ||
""" | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(passed=1) | ||
|
||
|
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.
So, that test was kinda confusing to me. Can we do this:
@patch.object(plugin.OpsTest, "default_model_name", "user/model") | |
@patch.object(plugin.OpsTest, "_setup_model", AsyncMock()) | |
@patch.object(plugin.OpsTest, "_cleanup_models", AsyncMock()) | |
def test_tmp_path_with_nonpath_chars(pytester): | |
pytester.makepyfile( | |
f""" | |
import os | |
from pathlib import Path | |
os.environ.update(**{ENV}) | |
async def test_with_tox(ops_test): | |
assert ops_test.tmp_path.name == "user_model0" | |
""" | |
) | |
result = pytester.runpytest() | |
result.assert_outcomes(passed=1) | |
async def test_tmp_path_with_nonpath_chars(tmp_path_factory, setup_request): | |
setup_request.module.__name__ = "user/model" | |
ops_test = plugin.OpsTest(setup_request, tmp_path_factory) | |
assert ops_test.tmp_path.name.startswith("user_model") |
if you rebase, you'll see the integration tests are likely going to work after merging #128 |
@tonyandrewmeyer poke if still relevant |
When generating the
tmp_path
, ensure that only characters from the model name that are safe for use in paths are used. This particularly covers the case where the model name is in the formuser/name
, like MAAS.Fixes #123