Skip to content

Commit 5f4ab02

Browse files
committed
initial commit
0 parents  commit 5f4ab02

File tree

9 files changed

+226
-0
lines changed

9 files changed

+226
-0
lines changed

.flake8

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
3+
# E501 line too long (83 > 79 characters)
4+
# F821 undefined name '_'
5+
6+
exclude = .git
7+
8+
per-file-ignores =
9+
./g.message.stdout.py: F821
10+
11+
max-line-length = 88

.github/workflows/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM mundialis/grass-py3-pdal:latest-alpine
2+
3+
WORKDIR /src
4+
COPY . /src
5+
COPY .github/workflows/test.sh /src
6+
RUN apk add gcc make
7+
RUN test -e requirements.txt && pip3 install -r requirements.txt || echo "No requirements.txt"
8+
9+
# # run tests with downloaded NC test loaction
10+
# RUN grass -c epsg:3358 /grassdb/nc_spm_empty --exec bash test.sh NC
11+
12+
# run tests in empty location
13+
RUN grass -c epsg:3358 /grassdb/nc_spm_empty --exec bash test.sh

.github/workflows/flake8.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Python Flake8 Code Quality
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
flake8:
9+
runs-on: ubuntu-20.04
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.8
18+
19+
- name: Install
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install flake8==3.8.4
23+
- name: Run Flake8
24+
run: |
25+
flake8 --config=.flake8 --count --statistics --show-source --jobs=$(nproc) .

.github/workflows/test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# fail on non-zero return code from a subprocess
4+
set -e
5+
6+
# download NC test loaction if the test needs the data and run tests
7+
if [ $1 == "NC" ]
8+
then
9+
g.extension g.download.location
10+
g.download.location url=https://grass.osgeo.org/sampledata/north_carolina/nc_spm_full_v2alpha2.tar.gz path=/grassdb
11+
g.mapset mapset=PERMANENT location=nc_spm_full_v2alpha2 -c
12+
g.list all
13+
fi
14+
15+
# run all tests in folder
16+
FILENAME=$(basename "$(find . -name *.html -maxdepth 1)")
17+
ADDON="${FILENAME%%.html}"
18+
19+
CURRENTDIR=$(pwd)
20+
g.extension extension=${ADDON} url=. && \
21+
for file in $(find . -type f -name test*.py) ; \
22+
do \
23+
echo ${file}
24+
BASENAME=$(basename "${file}") ; \
25+
DIR=$(dirname "${file}") ; \
26+
cd ${CURRENTDIR}/${DIR} && python3 -m unittest ${BASENAME}
27+
done

.github/workflows/tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run tests for GRASS GIS addons
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
# The branches below must be a subset of the branches above
7+
branches: [ main ]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
# with:
16+
# path: "."
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v1
19+
- name: Test of GRASS GIS addon
20+
id: docker_build
21+
uses: docker/build-push-action@v2
22+
with:
23+
push: false
24+
tags: addon-tests:alpine
25+
context: .
26+
file: .github/workflows/Dockerfile
27+
no-cache: true
28+
# pull: true

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MODULE_TOPDIR = ../..
2+
3+
PGM = g.message.stdout
4+
5+
include $(MODULE_TOPDIR)/include/Make/Script.make
6+
7+
default: script

g.message.stdout.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h2>DESCRIPTION</h2>
2+
3+
<em>g.message.stdout</em> is a module which writes a message to stdout.
4+
5+
<h2>EXAMPLES</h2>
6+
7+
<h3>Write message to stdout</h3>
8+
9+
<div class="code"><pre>
10+
g.message.stdout message="Hello World"
11+
</pre></div>
12+
13+
<h2>AUTHORS</h2>
14+
15+
Anika Weinmann, mundialis<br>
16+
17+
<!--
18+
<p>
19+
<i>Last changed: $Date$</i>
20+
-->

g.message.stdout.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
############################################################################
4+
#
5+
# MODULE: g.message.stdout
6+
# AUTHOR(S): Anika Weinmann
7+
# PURPOSE: This module writes a message to stdout
8+
#
9+
# COPYRIGHT: (C) 2021-2022 by mundialis GmbH & Co. KG and the GRASS Development Team
10+
#
11+
# This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation; either version 2 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
#############################################################################
22+
23+
# %module
24+
# % label: Prints a message to stdout
25+
# % description: This module writes a message to stdout.
26+
# % keyword: general
27+
# % keyword: support
28+
# % keyword: scripts
29+
# %end
30+
31+
# %option
32+
# % key: message
33+
# % type: string
34+
# % required: yes
35+
# % multiple: no
36+
# % key_desc: string
37+
# % label: Text of the message to be printed
38+
# % description: Message is printed on GRASS_VERBOSE>=2
39+
# %end
40+
41+
42+
import sys
43+
import grass.script as grass
44+
45+
46+
def main():
47+
print(options["message"])
48+
49+
50+
if __name__ == "__main__":
51+
options, flags = grass.parser()
52+
sys.exit(main())

testsuite/test_g_message_stdout.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
############################################################################
4+
#
5+
# MODULE: g.message.stdout
6+
# AUTHOR(S): Anika Weinmann
7+
# PURPOSE: Tests g.message.stdout GRASS module
8+
#
9+
# COPYRIGHT: (C) 2021-2022 mundialis GmbH & Co. KG and the GRASS Development Team
10+
#
11+
# This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation; either version 2 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
#############################################################################
22+
23+
from grass.gunittest.case import TestCase
24+
from grass.gunittest.main import test
25+
from grass.gunittest.gmodules import SimpleModule
26+
27+
28+
class TestGMessageStdout(TestCase):
29+
msg = "Hello World"
30+
31+
def test_message(self):
32+
"""Test if message is written to stdout"""
33+
g_message_stdout = SimpleModule("g.message.stdout", message=self.msg)
34+
self.assertModule(g_message_stdout)
35+
stdout = g_message_stdout.outputs.stdout
36+
stderr = g_message_stdout.outputs.stderr
37+
self.assertTrue(stdout)
38+
self.assertEqual(self.msg, stdout.strip())
39+
self.assertEqual("", stderr)
40+
41+
42+
if __name__ == "__main__":
43+
test()

0 commit comments

Comments
 (0)