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

feat: add pytest and coverage #68

Merged
merged 19 commits into from Mar 25, 2020
Merged

feat: add pytest and coverage #68

merged 19 commits into from Mar 25, 2020

Conversation

hobbe
Copy link
Contributor

@hobbe hobbe commented Mar 23, 2020

Enable pytest and coverage framework to address issue #26.

Add a mock to simulate Tesla servers in unit tests.
Add tests for sentry mode, GPS, odometer, battery, range, charger connection, online, parking.

Fix initialization of sentry_mode_available in VehicleDevice and sentry_mode in SentryModeSwitch.

@hobbe hobbe marked this pull request as ready for review March 23, 2020 18:05
@hobbe
Copy link
Contributor Author

hobbe commented Mar 24, 2020

Hi @zabuldon, @alandtse
I have added quite a few tests using pytest (with plugins asyncio and cov). I am not an expert and hopefully, I am not going in the wrong direction.
Please comment and advise if necessary, thanks!

@alandtse
Copy link
Collaborator

Thanks this is awesome. No negative judgment from me as the test suite closes something I haven't done for years now despite the issue #26 mainly cause I also am just learning.

There are a few warnings though. Have you taken a look to try to reduce them? Not saying it has to be done if you're not sure how--particularly given how much better it is with this, but would be nice to have those resolved.

========================================================= warnings summary ==========================================================
/Users/alandtse/.local/share/virtualenvs/teslajsonpy-JT0bMHGZ/lib/python3.7/site-packages/pytest_asyncio/plugin.py:39: 47 tests with warnings
  /Users/alandtse/.local/share/virtualenvs/teslajsonpy-JT0bMHGZ/lib/python3.7/site-packages/pytest_asyncio/plugin.py:39: PytestDeprecationWarning: direct construction of Function has been deprecated, please use Function.from_parent
    item = pytest.Function(name, parent=collector)

/Users/alandtse/.local/share/virtualenvs/teslajsonpy-JT0bMHGZ/lib/python3.7/site-packages/pytest_asyncio/plugin.py:45: 47 tests with warnings
  /Users/alandtse/.local/share/virtualenvs/teslajsonpy-JT0bMHGZ/lib/python3.7/site-packages/pytest_asyncio/plugin.py:45: PytestDeprecationWarning: direct construction of Function has been deprecated, please use Function.from_parent
    item = pytest.Function(name, parent=collector)  # To reload keywords.

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================== 77 passed, 94 warnings in 0.54s ==================================================

@hobbe
Copy link
Contributor Author

hobbe commented Mar 25, 2020

There are a few warnings though. Have you taken a look to try to reduce them? Not saying it has to be done if you're not sure how--particularly given how much better it is with this, but would be nice to have those resolved.

All the warnings are linked to pytest-asyncio. See pytest-dev/pytest-asyncio#141.

Downgrading to pytest<5.4.1 (5.3.5) removes all warnings 👍

@hobbe hobbe changed the title feat: add pytest and coverage feat: add pytest and coverage to fix #26 Mar 25, 2020
@hobbe hobbe changed the title feat: add pytest and coverage to fix #26 feat: add pytest and coverage Mar 25, 2020
@alandtse
Copy link
Collaborator

It's an upcoming deprecation warning. I don't think pinning to an older version to avoid the warning is necessarily the way to solve it. ;)

Let me know when you think you've finished your pushes.

@hobbe
Copy link
Contributor Author

hobbe commented Mar 25, 2020

It's an upcoming deprecation warning. I don't think pinning to an older version to avoid the warning is necessarily the way to solve it. ;)

Right! I am not downgrading pytest, just confirming that the warnings are not linked to teslajsonpy.

@hobbe
Copy link
Contributor Author

hobbe commented Mar 25, 2020

Let me know when you think you've finished your pushes.

Coverage is 69% total, 100% for device and sensors.
Only Controller and Connection remain. But I am not sure how to mock these.

If you are satisfied with the current status, please merge. We can see how to provide unit tests for Connection and Controller later.

@alandtse
Copy link
Collaborator

Thanks for all your help. Merging it shortly. Mocking those are probably just mocking the return values from the Tesla servers based off data we've seen before.

@alandtse alandtse merged commit a0cf7e1 into zabuldon:master Mar 25, 2020
@hobbe hobbe deleted the feat/add-pytest branch March 25, 2020 17:17
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.

None yet

2 participants