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

test: Draft test example. #27

Merged
merged 10 commits into from
Dec 11, 2024
Merged

test: Draft test example. #27

merged 10 commits into from
Dec 11, 2024

Conversation

rainwoodman
Copy link
Contributor

@rainwoodman rainwoodman commented Dec 6, 2024

For coverage on all of the attribute setters and the translation from info dict to the attributes.

#25

@rainwoodman rainwoodman changed the title Draft test example. test: Draft test example. Dec 6, 2024
@rainwoodman
Copy link
Contributor Author

@dahlb please a look if you like this approach, and we can make adjustments before I farm this out to testing real devices.

@dahlb
Copy link
Owner

dahlb commented Dec 10, 2024

it looks promising and does a nice job of mocking the api in a simple way.

I'm new to the unittest package, but I found this https://docs.python.org/3/library/unittest.html which suggests replacing
assert device.pm1 is None
with
self.assertIs(device.pm1, None)

@rainwoodman
Copy link
Contributor Author

This is where pytest kicks in -- when we run unittests with pytest as the test driver, then pytest replaces stock assert function to include the context of the current running test as well the values of the expression nodes (just like self.assert* do).

Another advantage of pytest as the test driver is that we are not writing the if __name__ == '__main__': section which wasrequired by the stock unittest due to lack of a test driver. In addition, I recall the test fixtures (and parameterized tests) of pytest is a bit easier to use than unittest, though I don't think we will be using those any time soon.

@dahlb
Copy link
Owner

dahlb commented Dec 10, 2024

I was able to use the stock version with

python3 -m unittest tests/*.py

without adding any main stuff, but pytest didn't work in my virtual env, I'll try to look at test harness choices tonight along with a github hook for running them

@rainwoodman
Copy link
Contributor Author

rainwoodman commented Dec 10, 2024 via email

@dahlb
Copy link
Owner

dahlb commented Dec 10, 2024

I figured out my env issue and got pytest working, just need to find a github hook to use

@rainwoodman
Copy link
Contributor Author

I think we just add a new github workflow (forking lint.yaml).

For coverage on all of the attribute setters and the translation from
info dict to the attributes.
@dahlb dahlb merged commit ec0ed65 into dahlb:main Dec 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants