Skip to content

Commit

Permalink
doc(tests): Add badges reflecting code quality + README.md dedicated …
Browse files Browse the repository at this point in the history
…to tests
  • Loading branch information
XavierBerger committed Sep 6, 2023
1 parent a88fa53 commit f19e78a
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
appdaemon/compiled/*
**/__pycache__/*
**/.coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![](images/pylint.svg) ![](images/pytest.svg) ![](images/coverage.svg)

# Home Assistant Config

This repository is gathering the part of home assistant configuration and appdaemon script I want to share with the community.
Expand Down
19 changes: 19 additions & 0 deletions appdaemon/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Appdaemon application tests

***X@v*** : Can you explain me why tests are important in computer programming in 2 sentences?

***ChatGPT***: Tests are crucial in computer programming as they help ensure the correctness and reliability of code by systematically verifying that it produces the expected outcomes. They also aid in detecting and preventing bugs early in the development process, leading to more maintainable and higher quality software.

Voilà, this is why I created this directory.

## Test coverage

Test coverage measures the extent to which a software's source code is exercised by a set of tests, indicating the proportion of code paths that have been tested.

For my Appdaemon application I try to cover the maximum of code with tests.

## Test framework

The test framework is a structured environment and set of tools that streamline the process of designing, executing, and managing tests, enhancing the efficiency and effectiveness of software testing endeavors.

I found on the Internet several test framework for Appdaemon. The one I choose was not the most powerfull but it is easy to understand and easy to upgrade.
16 changes: 16 additions & 0 deletions appdaemon/test/generate_badges.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
test_dir=$(realpath "$(dirname $0)")
appdaemon_dir=$(realpath "${test_dir}/../")
git_dir=$(realpath "${appdaemon_dir}/../")
apps_dir=$(realpath "${appdaemon_dir}/apps/")
pushd ${appdaemon_dir} > /dev/null
export PYTHONPATH=${apps_dir}
value=$(coverage run --source ${apps_dir} -m pytest | tee /dev/tty | perl -ne '/\[(.*)\]/ and print "$1\n"' | tail -1)
anybadge -l "pytest success" -v ${value} -o -f ../images/pytest.svg 70=red 80=orange 90=yellow 100=green
value=$(coverage report -m |& tee /dev/tty | perl -ne '/TOTAL.* (\S+%)/ and print "$1"')
anybadge -l coverage -v ${value} -o -f ../images/coverage.svg 70=red 80=orange 90=yellow 100=green
coverage html
echo ${test_dir}/htmlcov/index.html
value=$(pylint $(git ls-files '*.py' | grep -v notifier.py | grep -v hass_driver.py) --rcfile ${git_dir}/.pylintrc | tee /dev/tty | perl -ne '/at (\S+)/ and print "$1"')
anybadge -l pylint -v "${value}" -o -f ../images/pylint.svg 70=red 80=orange 90=yellow 100=green
popd > /dev/null
7 changes: 0 additions & 7 deletions appdaemon/test/pytlint_check.sh

This file was deleted.

1 change: 1 addition & 0 deletions appdaemon/test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
anybadge==1.14.0
appdaemon==4.4.2
coverage==7.2.7
esphome==2023.8.0
Expand Down
2 changes: 1 addition & 1 deletion appdaemon/test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ test_dir=$(realpath "$(dirname $0)")
appdaemon_dir=$(realpath "${test_dir}/../")
apps_dir=$(realpath "${appdaemon_dir}/apps/")
pushd ${appdaemon_dir} > /dev/null
PYTHONPATH={apps_dir} pytest-watch -- --random-order --sw -vsx $@
PYTHONPATH="${apps_dir}" pytest-watch -- --random-order --sw -vsx $@
popd > /dev/null
10 changes: 0 additions & 10 deletions appdaemon/test/show_coverage.sh

This file was deleted.

23 changes: 23 additions & 0 deletions images/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions images/pylint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions images/pytest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f19e78a

Please sign in to comment.