makerplane / pyEfis

Electronic Flight Information System in Python
GNU General Public License v2.0
55 stars 31 forks source link

Unit tests, screenshots, code style #230

Open e100 opened 1 month ago

e100 commented 1 month ago

229 is some rather significant changes to the project and thought it might be good to get feedback from others if they like the direction or not.

Significant Changes

  1. Reorganized the project so its layout is more consistent with python standards today. The setup.py is gone and all configurations are in the pyproject.toml Settings to build, install, run tests, all in that one file.
  2. pyefis folder was moved to src/pyefis, this aligns with suggested standards today and required less configuration since some auto detection features work with the change.
  3. I added unit tests for instruments/misc as a proof of concept. My goal is to make unit tests for the whole project but this will take some time. The unit tests are primary to test the logic, not the visual results. While the tests so far are not testing user interactions like clicking a button, we can easily add such tests since everything needed to do that is already in place.
  4. I chose to use pytest over the built in unittest because I found it much simpler to setup tests for Qt with pytest, the pytest-qt add-on is quite helpful
  5. As part of the testing I also included taking a screenshot of the rendered widget. This was more proof of concept than anything useful. The goal would be to include screenshots of each widget with various settings. Different sizes, height, width, font size, font, etc and save those so they can be reviewed by a human, or perhaps an AI in the future.
  6. The tests run headless using the environment variable QT_QPA_PLATFORM = offscreen, configured in pyproject.toml, so do not expect to see any graphics when running them. This also allows things to work on headless servers for automated testing
  7. I setup a github action that will run the tests against all pull requests for master.

Project Proposal I propose we adopt the use of black to create consistent PEP8 compliant code. https://black.readthedocs.io/en/stable/the_black_code_style/index.html

For an example this file was formatted with black: https://github.com/makerplane/pyEfis/blob/0882630d75eab1bc809bb46af13b89b415c7cea9/src/pyefis/instruments/misc/__init__.py

  1. Make your changes
  2. run black the/file/I/changed.py
  3. File is automatically rewritten into a consistent style

When developing use the Makefile to create your virtual environment and run tests, it will also add black to the virtual environment. I added a make clean that will cleanup, I think, anything that the other make commands did including deleting the virtual environment. make tests would be the preferred way to run the unit tests

I may be missing some dependency that is satisfied by a system package on my machine so let me know if you have any issues. Currently I am primarily developing on Ubuntu 22.04.

Upcoming Changes

  1. I plan to update the code and github action to save the results of the test so they can be easily viewed. Maybe also add some badges
  2. Will also require some aspects of the test to pass before the pull request can be merged.
  3. Add protection to the master branch to prevent direct push to it. Basically force using merge request and passing the tests to update master.
e100 commented 1 month ago

All pull requests should now generate a comment with a coverage report like this: https://github.com/makerplane/pyEfis/pull/229#issuecomment-2156121182