Projet

Général

Profil

0003-tests-add-a-tox.ini-and-other-tox-pytest-related-fil.patch

Paul Marillonnet, 26 janvier 2022 11:16

Télécharger (4,77 ko)

Voir les différences:

Subject: [PATCH 3/3] tests: add a tox.ini and other tox/pytest-related files
 (#61045)

 check-migrations.sh | 27 ++++++++++++++
 getlasso3.sh        | 22 ++++++++++++
 pylint.sh           | 13 +++++++
 tox.ini             | 85 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+)
 create mode 100755 check-migrations.sh
 create mode 100755 getlasso3.sh
 create mode 100755 pylint.sh
 create mode 100644 tox.ini
check-migrations.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5

  
6
# https://stackoverflow.com/questions/49778988/makemigrations-in-dev-machine-without-database-instance
7
CHECK_MIGRATIONS_SETTINGS=`mktemp`
8
trap "rm -f ${CHECK_MIGRATIONS_SETTINGS}" EXIT
9
cat <<EOF >${CHECK_MIGRATIONS_SETTINGS}
10
DATABASES = {
11
    'default': {
12
        'ENGINE': 'django.db.backends.dummy',
13
    }
14
}
15
EOF
16
TEMPFILE=`mktemp`
17
trap "rm -f ${TEMPFILE} ${CHECK_MIGRATIONS_SETTINGS}" EXIT
18

  
19
DJANGO_SETTINGS_MODULE=authentic2.settings AUTHENTIC2_SETTINGS_FILE=${CHECK_MIGRATIONS_SETTINGS}  django-admin makemigrations --dry-run --noinput authentic2_auth_fedict >${TEMPFILE} 2>&1 || true
20

  
21
if ! grep 'No changes detected' -q ${TEMPFILE}; then
22
   echo '!!! Missing migration detected !!!'
23
   cat ${TEMPFILE}
24
   exit 1
25
else
26
   exit 0
27
fi
getlasso3.sh
1
#!/bin/sh
2

  
3
# Get venv site-packages path
4
DSTDIR=`python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
5

  
6
# Get not venv site-packages path
7
# Remove first path (assuming that is the venv path)
8
NONPATH=`echo $PATH | sed 's/^[^:]*://'`
9
SRCDIR=`PATH=$NONPATH python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
10

  
11
# Clean up
12
rm -f $DSTDIR/lasso.*
13
rm -f $DSTDIR/_lasso.*
14

  
15
# Link
16
ln -sv /usr/lib/python3/dist-packages/lasso.py $DSTDIR/
17
for SOFILE in /usr/lib/python3/dist-packages/_lasso.cpython-*.so
18
do
19
  ln -sv $SOFILE $DSTDIR/
20
done
21

  
22
exit 0
pylint.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
6
	PYLINT_RC=/var/lib/jenkins/pylint.django.rc
7
elif [ -f pylint.django.rc ]; then
8
	PYLINT_RC=pylint.django.rc
9
else
10
	echo No pylint RC found
11
	exit 0
12
fi
13
pylint -f parseable --rcfile ${PYLINT_RC} "$@" > pylint.out || /bin/true
tox.ini
1
# Tox (http://tox.testrun.org/) is a tool for running tests
2
# in multiple virtualenvs. This configuration file will run the
3
# test suite on all supported python versions. To use it, "pip install tox"
4
# and then run "tox" from this directory.
5

  
6
[tox]
7
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic2-auth-fedict/{env:BRANCH_NAME:}
8
envlist =
9
  py3-dj22
10

  
11
[tox:jenkins]
12
envlist =
13
  pylint
14
  code-style
15
  py3-dj22
16

  
17

  
18
[testenv]
19
setenv =
20
  AUTHENTIC2_SETTINGS_FILE=tests/settings.py
21
  DJANGO_SETTINGS_MODULE=authentic2.settings
22

  
23
  JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
24
  COVERAGE={tty::--junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=src/ --cov-config .coveragerc}
25
passenv=
26
  BRANCH_NAME
27
  # support for pg_virtualenv
28
  PGPORT
29
  PGHOST
30
  PGUSER
31
  PGPASSWORD
32
usedevelop = true
33
deps =
34
  !local: https://git.entrouvert.org/authentic.git/snapshot/authentic-main.tar.gz
35
  local: ../authentic2
36
  # dependency constraints for authentic
37
  py3: file-magic
38
  djangorestframework>=3.12,<3.13
39
  dj22: django<2.3
40
  django-tables<2.0
41
  psycopg2-binary<2.9
42
  oldldap: python-ldap<3
43
  ldaptools
44

  
45
  # pytest requirements
46
  pytest
47
  pytest-cov
48
  pytest-django
49
  pytest-freezegun
50
  pytest-random
51
  django-webtest
52
  pyquery
53
  astroid!=2.5.7
54

  
55
commands =
56
  py3: ./getlasso3.sh
57
  ./check-migrations.sh
58
  py.test {env:COVERAGE:} {env:JUNIT:} {tty:--sw:} {posargs:tests/}
59

  
60
[testenv:pylint]
61
usedevelop = true
62
basepython = python3
63
deps =
64
    https://git.entrouvert.org/authentic.git/snapshot/authentic-main.tar.gz
65
    Django<2.3
66
    pylint<1.8
67
    pylint-django<0.8.1
68
commands =
69
    /bin/bash -c "./pylint.sh src/*/"
70

  
71
[testenv:code-style]
72
skip_install = true
73
deps =
74
  pre-commit
75
commands =
76
  pre-commit run --all-files --show-diff-on-failure
77

  
78
[pytest]
79
junit_family=xunit2
80
filterwarnings =
81
  once
82
  ignore:::django\..*
83
  ignore:::authentic2\..*
84
  ignore:::rest_framework\..*
85
  ignore:::gettext\..*
0
-