Skip to content

Commit f4ee924

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
Add tests via github actions (#667)
* tests on macOS and ubuntu * first pytest scenario * keep copyright test for now Co-authored-by: Benedikt Volkel <benedikt.volkel@cern.ch>
1 parent 59c905f commit f4ee924

8 files changed

Lines changed: 342 additions & 51 deletions

File tree

.github/workflows/baseline.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Baseline test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- ml-dev
8+
paths:
9+
- "machine_learning_hep/**/*.py"
10+
- "machine_learning_hep/data/**/*"
11+
push:
12+
branches:
13+
- master
14+
- ml-dev
15+
paths:
16+
- "machine_learning_hep/**/*.py"
17+
- "machine_learning_hep/data/**/*"
18+
19+
jobs:
20+
# A baseline test, independent of OS at the moment
21+
baseline:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
max-parallel: 6
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Test copyright
29+
if: github.event_name == 'push'
30+
run: |
31+
changed_files="$(find $(pwd -P) -name '*.py' -a -not -name setup.py)"
32+
ci/run-test-copyright.sh $changed_files
33+
34+
- name: Test copyright
35+
if: github.event_name == 'pull_request'
36+
run: |
37+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
38+
changed_files="$(git diff --name-only origin/${{ github.base_ref }} | grep -E '\.py' | grep -vE 'setup.py')"
39+
ci/run-test-copyright.sh $changed_files
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Test package
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- ml-dev
8+
paths:
9+
- "machine_learning_hep/**/*.py"
10+
- "machine_learning_hep/data/**/*"
11+
push:
12+
branches:
13+
- master
14+
- ml-dev
15+
paths:
16+
- "machine_learning_hep/**/*.py"
17+
- "machine_learning_hep/data/**/*"
18+
19+
jobs:
20+
build-os-latest:
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
max-parallel: 6
24+
matrix:
25+
os: [ubuntu-latest, macOS-latest]
26+
python-version: [3.6]
27+
#test-tool: [pylint, flake8, pytest]
28+
test-tool: [pylint, pytest]
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v1
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install -r requirements.txt
40+
- name: Install test tool ${{ matrix.test-tool }}
41+
run: |
42+
pip install ${{ matrix.test-tool }}
43+
- name: Run on pull_request
44+
if: github.event_name == 'pull_request'
45+
run: |
46+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
47+
changed_files="$(git diff --name-only origin/${{ github.base_ref }} | grep -E '\.py' | grep -vE 'setup.py')"
48+
ci/run-tests.sh --tests ${{ matrix.test-tool }} --files $changed_files
49+
- name: Run on push
50+
if: github.event_name == 'push'
51+
run: |
52+
changed_files="$(find . -name '*.py' -a -not -name setup.py)"
53+
ci/run-tests.sh --tests ${{ matrix.test-tool }} --files $changed_files

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ install: |
1111
script: |
1212
set -e
1313
set -o pipefail
14-
ci/run-tests.sh
14+
#ci/run-tests.sh
15+
echo "Travis"
1516
branches:
1617
only:
17-
- master
18-
- /^v\d+\.\d+(\.\d+)?(-rc\d+)?$/
18+
# just exclude for now
19+
- master-old
20+
#- /^v\d+\.\d+(\.\d+)?(-rc\d+)?$/

ci/pytest/test_general.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from machine_learning_hep.io import parse_yaml
2+
3+
YAML_PATH="ci/pytest/yaml.yaml"
4+
5+
def test_yaml():
6+
assert isinstance(parse_yaml(YAML_PATH), dict)

ci/pytest/yaml.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test:
2+
test1: [42, "test", Null]
3+
test2:
4+
tea: False
5+
coffee: True
6+
list_of_lists:
7+
- [1, 2, 3,4, 5]
8+
- ["ABC", "DEF", "GHI"]
9+
- [Null, False, True, true, false, null]
10+
test3: 42

ci/run-test-copyright.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash -e
2+
3+
TEST=$1
4+
set -o pipefail
5+
cd "$(dirname "$0")"/..
6+
7+
#############################################################################
8+
## © Copyright CERN 2018. All rights not expressly granted are reserved. ##
9+
## Author: Gian.Michele.Innocenti@cern.ch ##
10+
## This program is free software: you can redistribute it and/or modify it ##
11+
## under the terms of the GNU General Public License as published by the ##
12+
## Free Software Foundation, either version 3 of the License, or (at your ##
13+
## option) any later version. This program is distributed in the hope that ##
14+
## it will be useful, but WITHOUT ANY WARRANTY; without even the implied ##
15+
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
16+
## See the GNU General Public License for more details. ##
17+
## You should have received a copy of the GNU General Public License ##
18+
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
19+
#############################################################################
20+
21+
function check_copyright() {
22+
local COPYRIGHT="$(cat <<'EOF'
23+
#############################################################################
24+
## © Copyright CERN 2018. All rights not expressly granted are reserved. ##
25+
## Author: Gian.Michele.Innocenti@cern.ch ##
26+
## This program is free software: you can redistribute it and/or modify it ##
27+
## under the terms of the GNU General Public License as published by the ##
28+
## Free Software Foundation, either version 3 of the License, or (at your ##
29+
## option) any later version. This program is distributed in the hope that ##
30+
## it will be useful, but WITHOUT ANY WARRANTY; without even the implied ##
31+
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
32+
## See the GNU General Public License for more details. ##
33+
## You should have received a copy of the GNU General Public License ##
34+
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
35+
#############################################################################
36+
EOF
37+
)"
38+
local COPYRIGHT_LINES=$(echo "$COPYRIGHT" | wc -l)
39+
[[ "$(head -n$COPYRIGHT_LINES "$1")" == "$COPYRIGHT" ]] || { printf "$1: missing or malformed copyright notice\n"; return 1; }
40+
return 0
41+
}
42+
43+
44+
FILES_CHANGED="$1"
45+
46+
ERR=0
47+
48+
# Find only python files
49+
50+
echo "$FILES_CHANGED"
51+
52+
for PY in $FILES_CHANGED; do
53+
check_copyright "$PY" || ERR=1
54+
done
55+
exit $ERR

0 commit comments

Comments
 (0)