Skip to content

Commit 780d675

Browse files
Merge pull request #602 from matthijskooijman/ci-testing-action
Run flake8 and unittests on pullrequests and pushes
2 parents 29ac49d + f6b08cd commit 780d675

File tree

5 files changed

+148
-1
lines changed

5 files changed

+148
-1
lines changed

.flake8

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[flake8]
2+
exclude=wscript,waf,waflib
3+
builtins=_
4+
5+
# This just ignores everything that currently fails. Over time, most of these
6+
# should probably be fixed in the code and removed here.
7+
extend-ignore =
8+
E117, # over-indented
9+
E122, # continuation line missing indentation or outdented
10+
E124, # closing bracket does not match visual indentation
11+
E125, # continuation line with same indent as next logical line
12+
E127, # continuation line over-indented for visual indent
13+
E128, # continuation line under-indented for visual indent
14+
E129, # visually indented line with same indent as next logical line
15+
E131, # continuation line unaligned for hanging indent
16+
E202, # whitespace before ')'
17+
E203, # whitespace before ':'
18+
E211, # whitespace before '('
19+
E221, # multiple spaces before operator
20+
E222, # multiple spaces after operator
21+
E225, # missing whitespace around operator
22+
E227, # missing whitespace around bitwise or shift operator
23+
E231, # missing whitespace after ':'
24+
E251, # unexpected spaces around keyword / parameter equals
25+
E261, # at least two spaces before inline comment
26+
E262, # inline comment should start with '# '
27+
E265, # block comment should start with '# '
28+
E271, # multiple spaces after keyword
29+
E272, # multiple spaces before keyword
30+
E301, # expected 1 blank line, found 0
31+
E302, # expected 2 blank lines, found 1
32+
E303, # too many blank lines (2)
33+
E305, # expected 2 blank lines after class or function definition, found 1
34+
E306, # expected 1 blank line before a nested definition, found 0
35+
E401, # multiple imports on one line
36+
E402, # module level import not at top of file
37+
E501, # line too long
38+
E502, # the backslash is redundant between brackets
39+
E701, # multiple statements on one line (colon)
40+
E703, # statement ends with a semicolon
41+
E711, # comparison to None should be 'if cond is not None:'
42+
E712, # comparison to False should be 'if cond is False:' or 'if not cond:'
43+
E722, # do not use bare 'except'
44+
E731, # do not assign a lambda expression, use a def
45+
F401, # 'xxx' imported but unused
46+
F811, # redefinition of unused 'xxx' from line 32
47+
F841, # local variable 'xxx' is assigned to but never used
48+
W605, # invalid escape sequence
49+

.github/workflows/testing.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Testing
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test:
6+
# This runs the test suite. Since we need some system dependencies
7+
# (e.g. pygobject) that cannot easily be installed inside a
8+
# virtualenv using pip (that requires installing a dozen -dev
9+
# packages and building parts of pygobject from source, which makes
10+
# things way too complicated), this just runs with the Ubuntu system
11+
# python (e.g. not using the standard setup-python action, which
12+
# sets up a virtualenv).
13+
name: Run test suite
14+
strategy:
15+
# Complete all combinations, even if one fails
16+
fail-fast: false
17+
matrix:
18+
include:
19+
# Test 3.5, which is our minimum version, on 16.04 since the
20+
# latest Ubuntu does not have it.
21+
- os: ubuntu-16.04
22+
python-version: 3.5
23+
# On the latest ubuntu, just test the default 3.x version.
24+
- os: ubuntu-latest
25+
python-version: 3
26+
runs-on: ${{matrix.os}}
27+
steps:
28+
- name: Prepare repo
29+
uses: actions/checkout@v2
30+
- name: Install system packages
31+
run: |
32+
PACKAGES=""
33+
# Install a specific python version as configured
34+
PACKAGES="$PACKAGES python${{matrix.python-version}}"
35+
# Normal dependencies
36+
PACKAGES="$PACKAGES gettext intltool python3-gi python3-cairo python3-dbus python3-xdg libglib2.0-dev libglib2.0-bin gir1.2-gtk-3.0"
37+
# The gtk-update-icon-cache used to live in libgtk2.0-bin,
38+
# but was moved to its own package. Similar for distutils
39+
# (included by default in python stdlib).
40+
if [ "${{ matrix.os }}" == "ubuntu-16.04" ]; then
41+
PACKAGES="$PACKAGES libgtk2.0-bin"
42+
else
43+
PACKAGES="$PACKAGES gtk-update-icon-cache"
44+
PACKAGES="$PACKAGES python3-distutils"
45+
fi
46+
# For dbus-launch
47+
PACKAGES="$PACKAGES dbus-x11"
48+
49+
sudo apt-get update
50+
sudo apt-get install ${PACKAGES}
51+
- name: Install hamster
52+
# This serves two purposes:
53+
# 1) Verify build and install still works and
54+
# 2) install the needed stuff (e.g. gsettings schemas) to allow
55+
# running the tests
56+
run: |
57+
./waf configure build
58+
sudo ./waf install
59+
60+
- name: Run tests
61+
run: |
62+
dbus-launch python${{ matrix.python-version }} -m unittest
63+
64+
flake8:
65+
name: Run code linting and checks
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Prepare repo
69+
uses: actions/checkout@v2
70+
- name: Set up Python
71+
uses: actions/setup-python@v1
72+
with:
73+
python-version: '3.5'
74+
- name: Install flake8
75+
run: |
76+
pip install flake8
77+
- name: Run flake8
78+
run: |
79+
flake8 --count --show-source --statistics

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ commands). Older versions are not supported.
6969
###### Ubuntu (tested in 19.04 and 18.04)
7070

7171
```bash
72-
sudo apt install gettext intltool python3-gi-cairo python3-distutils python3-dbus python3-xdg libglib2.0-dev
72+
sudo apt install gettext intltool python3-gi python3-cairo python3-distutils python3-dbus python3-xdg libglib2.0-dev libglib2.0-bin gir1.2-gtk-3.0 gtk-update-icon-cache
7373
# and for documentation
7474
sudo apt install itstool yelp
7575
```
@@ -160,6 +160,24 @@ D-Bus, so that all the traces are visible.
160160
Note: You'll need recent version of hamster installed on your system (or
161161
[this workaround](https://github.com/projecthamster/hamster/issues/552#issuecomment-585166000)).
162162

163+
#### Running tests
164+
165+
Hamster has a limited test suite, that can be run using Python's builtin
166+
unittest module. From the top-level directory, just run:
167+
168+
python3 -m unittest
169+
170+
This will let unittest automatically find all testcases in all files
171+
called `test_*.py`, and runs them.
172+
173+
To run a subset of tests, specify the import path towards it. For
174+
example, to run just a single test file, class or method respectively
175+
run:
176+
177+
python3 -m unittest tests.test_stuff
178+
python3 -m unittest tests.test_stuff.TestFactParsing
179+
python3 -m unittest tests.test_stuff.TestFactParsing.test_plain_name
180+
163181
#### Migrating from hamster-applet
164182

165183
Previously Hamster was installed everywhere under `hamster-applet`. As

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# - coding: utf-8 -
File renamed without changes.

0 commit comments

Comments
 (0)