Testing - weewx/weewx GitHub Wiki
Running the test suites
You will need to set up a virtual environment with the appropriate dependencies installed.
cd ~/git/weewx
python3 -m venv venv
source venv/bin/activate
pip install pip --upgrade
pip install -r dev_requirements.txt
The suites can then be run all at once from the top-level directory of the
repository, using the make test command:
cd ~/git/weewx
make test
The test results are put in build/test-results.
Writing test suites
The test suites are located in tests subdirectories of the various WeeWX
packages. As of V5.3, the test suites are written using the
pytest framework. Before that, they used
the unittest framework.
Locale
Generally, WeeWX is locale aware. It will emit reports using the local formatting conventions for date, times, and values. However, it's worth noting that the convention can vary from operating system to operating system. For example, consider the following short program:
# Program test_time.py
import time, locale
locale.setlocale(locale.LC_ALL, '')
print(time.strftime('%b %a', time.localtime(1286128800)))
This prints the abbreviations for October and Sunday. Here's the results in a US locale:
LANG=en_US.UTF-8 python test_time.py
Oct Sun
However, if run against a German locale, the results depend on the operating system. Under Ubuntu (Linux-based), you get
LANG=de_DE-UTF-8 python test_time.py
Okt So
But under macOS (BSD-based), you get
LANG=de_DE-UTF-8 python test_time.py
Okt. So.
Note the extra periods ('.'). This can make it challenging to write test suites that are OS-independent.
What to do? There are two choices:
-
Somehow rewrite your test suites to be OS-independent. For example, instead of asking for the abbreviated month name ('
%b), ask for the full month name (%B), which is the same regardless of OS. -
Target just Linux systems. This is the approach taken by the WeeWX test suite. We use a continuous integration system (CI) on GitHub, which runs the test suite on the latest version of Ubuntu, a Linux system. Linux is what is used by the vast majority of WeeWX users.