Skip to content
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

applet: extract test code to a separate file. #448

Merged
merged 4 commits into from
Oct 21, 2023

Conversation

wanda-phi
Copy link
Member

Fixes #447.

@whitequark
Copy link
Member

H-how did you do it so quickly?!

@whitequark
Copy link
Member

But yeah the test.py wrapper can now be removed, a PDM test script that runs some normal unittest invocation can be added, and for glasgow test we need some sort of loader that I'm not yet sure how to hack together but I'm sure something can be done about it.

@whitequark
Copy link
Member

So right now GlasgowApplet maintains a registry of applet test cases (IIRC) which wouldn't work anymore unless each test module is imported when the applet itself is imported (which we probably don't want), but I'm not sure exactly how to replace that.

@wanda-phi
Copy link
Member Author

Mhm. I suppose you'd also want the testcases outside of applets extracted to test_*.py files before getting rid of the custom test.py entrypoint, right?

@whitequark
Copy link
Member

I suppose you'd also want the testcases outside of applets extracted to test_*.py files before getting rid of the custom test.py entrypoint, right?

Inevitably, yeah.

Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

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

For non-applets the tests should be in a top-level directory tests/, that exists side-by-side with software/glasgow/. (For applets we break this rule to make applets contained within a single directory, which is something I want to keep forever.)

@wanda-phi
Copy link
Member Author

For non-applets the tests should be in a top-level directory tests/, that exists side-by-side with software/glasgow/. (For applets we break this rule to make applets contained within a single directory, which is something I want to keep forever.)

It seems we cannot have the directory at top level (AssertionError: Path must be within the project), I'm going to do software/tests.

@whitequark
Copy link
Member

I'm going to do software/tests.

Yes sorry, I meant under software/tests/ and was unclear.

@wanda-phi
Copy link
Member Author

OK, this should now be done except for the glasgow test fixups.

@whitequark
Copy link
Member

except for the glasgow test fixups.

How about this as an approach for glasgow test:

  1. We remove the registration done in GlasgowAppletTestCase; applet.test_cls is now not a thing.

  2. For each applet, we have code that looks something like this:

    @classmethod
    def tests(cls):
        from . import test # this way the name of the test case is only repeated once :3
        return (test.FooAppletTestCase,)
    

    The return value of tests (a new abstract method defined on GlasgowApplet) is something that can be directly passed to unittest.TestSuite() constructor.

  3. In the CLI we use the normal discovery mechanisms, without the mutating-state-on-import that GlasgowAppletTestCase is currently using.

Sounds good?

@wanda-phi wanda-phi marked this pull request as ready for review October 21, 2023 17:05
@wanda-phi wanda-phi requested a review from attie as a code owner October 21, 2023 17:05
Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

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

Fantastic work as usual, @mwkmwkmwk!

@whitequark
Copy link
Member

@attie Looks like I cannot merge this without your consent as a code owner (!), which would be appreciated ASAP.

@whitequark whitequark added the nominated Meta: nominated for next meeting label Oct 21, 2023
Copy link
Member

@attie attie left a comment

Choose a reason for hiding this comment

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

Not reviewed in detail, but looks like a good step to me - thanks both!

@whitequark whitequark added this pull request to the merge queue Oct 21, 2023
Merged via the queue into GlasgowEmbedded:main with commit 77ca247 Oct 21, 2023
10 of 12 checks passed
@wanda-phi wanda-phi deleted the applet-test branch October 21, 2023 19:14
@attie attie removed their assignment Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nominated Meta: nominated for next meeting
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Extract test code from each applet to a separate test.py file
3 participants