-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat!: add error if meta not passed when config or actions are in ops.testing #1497
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -454,6 +454,10 @@ def test_foo(): | |||||||||||||||||||||
Use this when calling :meth:`run` to specify the event to emit. | ||||||||||||||||||||||
""" | ||||||||||||||||||||||
|
||||||||||||||||||||||
# def test_foo(): | ||||||||||||||||||||||
# ctx = Context(MyCharm, config={"foo": "bar"}) | ||||||||||||||||||||||
# ctx.run(..., State()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
def __init__( | ||||||||||||||||||||||
self, | ||||||||||||||||||||||
charm_type: type[CharmType], | ||||||||||||||||||||||
|
@@ -503,13 +507,18 @@ def __init__( | |||||||||||||||||||||
spec: _CharmSpec[CharmType] = _CharmSpec.autoload(charm_type) | ||||||||||||||||||||||
except MetadataNotFoundError as e: | ||||||||||||||||||||||
raise ContextSetupError( | ||||||||||||||||||||||
f"Cannot setup scenario with `charm_type`={charm_type}. " | ||||||||||||||||||||||
f"Did you forget to pass `meta` to this Context?", | ||||||||||||||||||||||
f"Cannot automatically setup scenario with `charm_type`={charm_type}. " | ||||||||||||||||||||||
"This is likely because this charm has some nonstandard repository setup and Scenario " | ||||||||||||||||||||||
"can't find the charmcraft|(metadata|config|actions) yamls in their usual location. " | ||||||||||||||||||||||
"Please parse and provide their contents manually via the `meta`, `config` " | ||||||||||||||||||||||
"and `actions` Context parameters.", | ||||||||||||||||||||||
Comment on lines
+510
to
+514
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose if we're improving error messages we ought to avoid Scenario as a proper noun 😞
Suggested change
|
||||||||||||||||||||||
) from e | ||||||||||||||||||||||
|
||||||||||||||||||||||
else: | ||||||||||||||||||||||
if not meta: | ||||||||||||||||||||||
meta = {"name": str(charm_type.__name__)} | ||||||||||||||||||||||
raise ContextSetupError( | ||||||||||||||||||||||
"Scenario doesn't support overriding `actions|config` without overriding `meta` too." | ||||||||||||||||||||||
) | ||||||||||||||||||||||
Comment on lines
+519
to
+521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I suppose here also 😞
Suggested change
|
||||||||||||||||||||||
spec = _CharmSpec( | ||||||||||||||||||||||
charm_type=charm_type, | ||||||||||||||||||||||
meta=meta, | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -126,6 +126,23 @@ def test_no_meta_raises(tmp_path, legacy): | |||||
Context(charm) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize("legacy", (True, False)) | ||||||
@pytest.mark.parametrize( | ||||||
"params", | ||||||
( | ||||||
{"actions": {"foo": "bar"}}, | ||||||
{"config": {"foo": "bar"}}, | ||||||
), | ||||||
) | ||||||
def test_partial_meta_raises(tmp_path, legacy, params): | ||||||
with create_tempcharm( | ||||||
tmp_path, legacy=legacy, meta={"type": "charm", "name": "sergio"} | ||||||
) as charm: | ||||||
# metadata not found: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this initially confusing because there's metadata two lines above, maybe this would be clearer?
Suggested change
|
||||||
with pytest.raises(ContextSetupError): | ||||||
Context(charm, **params) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize("legacy", (True, False)) | ||||||
def test_relations_ok(tmp_path, legacy): | ||||||
with create_tempcharm( | ||||||
|
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'm assuming this is leftover rather than meant as an example?