docs: make the custom-endpoint-name sample test actually test something - #2664
Open
tonyandrewmeyer wants to merge 5 commits into
Open
docs: make the custom-endpoint-name sample test actually test something#2664tonyandrewmeyer wants to merge 5 commits into
tonyandrewmeyer wants to merge 5 commits into
Conversation
The "Test that the library initialises" example asserted both that no events were emitted and that emitted_events[0] was a StartEvent, which cannot both hold (the second would IndexError). It also passed an un-invoked ctx.on.<event> method to run(), parametrised 'update-status' where the attribute is update_status, and imported from my_Charm. Assert instead that the library emits none of its own events, which is what the surrounding prose says the test is for.
Matches the reference test in dwilding/basic-charms#8. Without the extra endpoint declared, a requirer that hard-coded 'database' fails at charm construction with an AttributeError on database_relation_changed, rather than failing because no DatabaseReadyEvent was emitted -- so the example demonstrated the wrong failure.
docs/ruff.toml sets line-length = 80, so the single-line assert in the library-initialisation example exceeded it.
tonyandrewmeyer
marked this pull request as ready for review
July 27, 2026 01:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two issues with the library docs.
The "Test custom endpoint names" test ran
startand asserted asaw_startflag, so it never touched the relation endpoint and would pass just as happily against aDatabaseRequirerthat ignored itsendpointargument and observed a hard-coded relation. It now firesrelation_changedon the custom-named relation and asserts aDatabaseReadyEventis emitted.The
DatabaseRequirerin "Write a library" hard-codedcharm.on['database'], so custom endpoint names were first mentioned in the testing section. It now takesendpoint: str = 'database'and observescharm.on[endpoint], with a lead-in sentence explaining why the parameter exists.That run also turned up why the sample
METAdeclaresdatabasealongside the custom endpoint. If only the custom endpoint is declared, a hard-coded requirer fails at charm construction withAttributeError("'CharmEvents' object has no attribute 'database_relation_changed'")— the test fails, but for the wrong reason. Declaring both means it fails with noDatabaseReadyEventemitted, which is the defect the section is teaching about.Fixes #2657