forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest: Add very basic config to run pytest (OSGeo#2183)
This adds pytest configuration and one pytest-ready test file so that pytest can run on the source code without errors. Notably, this does not use or run any of the existing tests and searches for tests in directories called tests (instead of testsuite). There is no handling of GRASS session or any test data. Each test needs to set up the session by itself. However, given that the test assume import grass will work, the command 'pytest .' will work without errors only when Python path (PYTHONPATH) is set beforehand. (The CI is using 'grass --config ...' to get it.) The idea is to allow for writing of tests in a different style with pytest and later add functionality for easier setup or data comparison.
- Loading branch information
1 parent
991ef99
commit 0519955
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: pytest | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
pytest: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-20.04 | ||
python-version: | ||
- "3.8" | ||
- "3.10" | ||
fail-fast: true | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install non-Python dependencies | ||
run: | | ||
sudo apt-get update -y | ||
sudo apt-get install -y wget git gawk findutils | ||
xargs -a <(awk '! /^ *(#|$)/' ".github/workflows/apt.txt") -r -- \ | ||
sudo apt-get install -y --no-install-recommends --no-install-suggests | ||
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r .github/workflows/python_requirements.txt | ||
pip install pytest | ||
- name: Create installation directory | ||
run: | | ||
mkdir $HOME/install | ||
- name: Set number of cores for compilation | ||
run: | | ||
echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV | ||
- name: Set LD_LIBRARY_PATH for compilation | ||
run: | | ||
echo "LD_LIBRARY_PATH=$HOME/install/lib" >> $GITHUB_ENV | ||
- name: Build | ||
run: .github/workflows/build_${{ matrix.os }}.sh $HOME/install | ||
|
||
- name: Add the bin directory to PATH | ||
run: | | ||
echo "$HOME/install/bin" >> $GITHUB_PATH | ||
- name: Test executing of the grass command | ||
run: .github/workflows/test_simple.sh | ||
|
||
- name: Run pytest | ||
run: | | ||
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH | ||
pytest . | ||
- name: Print installed versions | ||
if: always() | ||
run: .github/workflows/print_versions.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
autoconf2.13 | ||
autotools-dev | ||
bison | ||
flex | ||
g++ | ||
gettext | ||
git | ||
imagemagick | ||
libblas-dev | ||
libbz2-dev | ||
libcairo2-dev | ||
libfftw3-dev | ||
libfreetype6-dev | ||
libgdal-dev | ||
libgeos-dev | ||
libglu1-mesa-dev | ||
libjpeg-dev | ||
liblapack-dev | ||
liblas-c-dev | ||
libncurses5-dev | ||
libnetcdf-dev | ||
libpng-dev | ||
libpq-dev | ||
libproj-dev | ||
libreadline-dev | ||
libsqlite3-dev | ||
libtiff-dev | ||
libxmu-dev | ||
libzstd-dev | ||
make | ||
netcdf-bin | ||
p7zip | ||
proj-bin | ||
sqlite3 | ||
unixodbc-dev | ||
xvfb | ||
zlib1g-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
matplotlib | ||
numpy | ||
Pillow | ||
ply | ||
PyVirtualDisplay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Test functions in grass.script.utils""" | ||
|
||
import grass.script as gs | ||
|
||
|
||
def test_named_separators(): | ||
"""Check that named separtors are recognized and correctly evaluated""" | ||
assert gs.separator("pipe") == "|" | ||
assert gs.separator("comma") == "," | ||
assert gs.separator("space") == " " | ||
assert gs.separator("tab") == "\t" | ||
assert gs.separator("newline") == "\n" | ||
|
||
|
||
def test_backslash_separators(): | ||
"""Check that separtors specified as an escape sequence are correctly evaluated""" | ||
assert gs.separator(r"\t") == "\t" | ||
assert gs.separator(r"\n") == "\n" | ||
|
||
|
||
def test_unrecognized_separator(): | ||
"""Check that unknown strings are just passed through""" | ||
assert gs.separator("apple") == "apple" |