From 9b3d0c90da570eff829fc5aebd78d9bcd051900e Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Tue, 28 Feb 2017 14:07:34 +0100 Subject: [PATCH 1/3] mostly run analyzer tests on travis * [x] regonfigured the build matrix with more php jobs and a separate python job (we can add more python jobs later) * [x] run tests on travis' trusty beta container (it's closer to what we need anyway) * [x] install packages needed for analyzer tests in build env * [x] added docs on how to run nosetests locally * [x] don't run initctl in analyzer setup so setup can also be used on travis (and add it to the install script directly) * [x] ignore replaygain checks on travis (it has proven quite impossible to get the needed python-gi module to work in the provided virtualenv) I tried a lot of solutions to get the replaygain checks to run. I needed to decide that this has gone far enough, maybe someone who is more of a pythonista than me can take a crack at it and get it solved. Even without running those tests on CI/CD there are still plenty others. This PR only has parts of what are needed for getting python tests running on travis as per #15. I only took a quick shot at anything not analyzer and figured I would not be able to "fix" them without digging a bit deeper (ie. also getting rid of std_err_override). --- .travis.yml | 73 ++++++++++++++++++- docs/TESTING.md | 22 ++++++ install | 1 + python_apps/airtime_analyzer/setup.py | 10 +-- .../tests/replaygain_analyzer_tests.py | 28 ++++++- 5 files changed, 122 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f8eb9d97f..3fac6096a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,14 @@ +dist: trusty language: php php: -- '5.5' -- '5.4' +# the latest and greatest, has some issues that are excluded below in matrix.allow_failures +- 7.1 +# the 7.0 build demonstrates that everything is basically ok for 7.0, users might want to wait for 7.1 to run it +- 7.0 +# folks who prefer running on 5.x should be using 5.6 in most cases, 5.4 is no in the matrix since noone should use it +- 5.6 +# this is in for centos support, it's still the default on CentOS 7.3 and there were some lang changes after 5.4 +- 5.4 services: - postgresql - rabbitmq @@ -9,13 +16,71 @@ env: global: - ENVIRONMENT=testing - LIBRETIME_LOG_DIR=/tmp/log/libretime + matrix: + - PYTHON=false + - PYTHON=true +matrix: + allow_failures: + # there are currently some testing issues with DateTime precision on 7.1 + - env: PYTHON=false + php: 7.1 + exclude: + # by excluding all of python we make way to just runu python tests in one seperate instance + - env: PYTHON=true + include: + # using latest to run python on since it will last the longest + - php: 7.1 + env: PYTHON=true +addons: + apt: + packages: + - silan + - liquidsoap + - liquidsoap-plugin-mad + - liquidsoap-plugin-taglib + - liquidsoap-plugin-flac + - liquidsoap-plugin-ogg + - liquidsoap-plugin-lame + - liquidsoap-plugin-faad + - liquidsoap-plugin-vorbis + - liquidsoap-plugin-opus + - python-nose + - python-rgain + - python-gst-1.0 + - mp3gain install: -- composer install +- > + if [[ "$PYTHON" == false ]]; then + composer install + fi +- > + if [[ "$PYTHON" == true ]]; then + pushd python_apps/airtime_analyzer + python setup.py install --dry-run --no-init-script + popd + fi before_script: +# prepare the database as per docs/testing.md - psql -c 'CREATE DATABASE libretime;' -U postgres - psql -c "CREATE USER libretime WITH PASSWORD 'libretime';" -U postgres - psql -c 'GRANT CONNECT ON DATABASE libretime TO libretime;' -U postgres - psql -c 'ALTER USER libretime CREATEDB;' -U postgres - mkdir -p /tmp/log/libretime script: -- cd airtime_mvc/tests && ../../vendor/bin/phpunit +- > + if [[ "$PYTHON" == false ]]; then + pushd airtime_mvc/tests + ../../vendor/bin/phpunit + results=$? + popd + exit $results + fi +- > + if [[ "$PYTHON" == true ]]; then + pushd python_apps/airtime_analyzer + nosetests -a '!rgain' + results=$? + echo "replaygain tests where skipped due to not having a reliable replaygain install on travis." + popd + exit $results + fi diff --git a/docs/TESTING.md b/docs/TESTING.md index c0db83980..5fd140e74 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -50,3 +50,25 @@ cd airtime_mvc/tests # run a subset of tests ../../vendor/bin/phpunit --filter testEditReatingShowInstance ``` + +## Python + +The python tests are run through nosetest. To prepare your env you should install +it. + +```bash +# Debian/Ubuntu +apt-get install python-nose + +# CentOS +yum install -y python-nose +``` + +In most cases you need to install deps before the tets can be run. + +### Airtime Analyzer + +```bash +cd python_apps/airtime_analyzer +nosetests +``` diff --git a/install b/install index 85596ce6d..5603fd387 100755 --- a/install +++ b/install @@ -485,6 +485,7 @@ verbose "...Done" verbose "\n * Installing airtime_analyzer..." loudCmd "python ${AIRTIMEROOT}/python_apps/airtime_analyzer/setup.py install --install-scripts=/usr/bin" +loudCmd "initctl reload-configuration" verbose "...Done" for i in /etc/init/airtime*.template; do diff --git a/python_apps/airtime_analyzer/setup.py b/python_apps/airtime_analyzer/setup.py index c9f33f45a..574b8e050 100644 --- a/python_apps/airtime_analyzer/setup.py +++ b/python_apps/airtime_analyzer/setup.py @@ -48,11 +48,7 @@ setup(name='airtime_analyzer', zip_safe=False, data_files=data_files) -# Reload the initctl config so that "service start airtime_analyzer" works +# Remind users to reload the initctl config so that "service start airtime_analyzer" works if data_files: - print "Reloading initctl configuration" - call(['initctl', 'reload-configuration']) - print "Run \"sudo service airtime_analyzer restart\" now." - - -# TODO: Should we start the analyzer here or not? + print "Remember to reload the initctl configuration" + print "Run \"sudo initctl reload-configuration; sudo service airtime_analyzer restart\" now." diff --git a/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py b/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py index c9e98bfb3..4a4e8ca58 100644 --- a/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py +++ b/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py @@ -1,6 +1,21 @@ from nose.tools import * from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer +''' +The tests in here were all tagged with the 'rgain' tag so the can be exluded from being run +with nosetest -a '!rgain'. This was needed due to the fact that it is not readily possible +to install replaygain on a containerized travis instance. + +We can either give running replaygain test on travis another shot after ubuntu getsan updated +gi instrospection allowing us to install gi and gobject into the virtualenv, or we can switch +to a full machine and stop using 'sudo: false' on travis. + +Deactivating these tests is a bad fix for now and I plan on looking into it again after +most everything else is up and running. For those interesed the tests seem to work locally +albeit my results not being up to the given tolerance of 0.30 (which I'm assuming is my rig's +problem and would work on travis if replaygain was available). +''' + def check_default_metadata(metadata): ''' Check that the values extract by Silan/CuePointAnalyzer on our test audio files match what we expect. :param metadata: a metadata dictionary @@ -29,43 +44,54 @@ def test_invalid_filepath(): def test_mp3_utf8(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo-utf8.mp3', dict()) check_default_metadata(metadata) +test_mp3_utf8.rgain = True def test_mp3_dualmono(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-dualmono.mp3', dict()) check_default_metadata(metadata) +test_mp3_dualmono.rgain = True def test_mp3_jointstereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-jointstereo.mp3', dict()) check_default_metadata(metadata) +test_mp3_jointstereo.rgain = True def test_mp3_simplestereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-simplestereo.mp3', dict()) check_default_metadata(metadata) +test_mp3_simplestereo.rgain = True def test_mp3_stereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.mp3', dict()) check_default_metadata(metadata) +test_mp3_stereo.rgain = True def test_mp3_mono(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.mp3', dict()) check_default_metadata(metadata) +test_mp3_mono.rgain = True def test_ogg_stereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.ogg', dict()) check_default_metadata(metadata) +test_ogg_stereo = True def test_invalid_wma(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo-invalid.wma', dict()) +test_invalid_wma.rgain = True def test_mp3_missing_id3_header(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mp3-missingid3header.mp3', dict()) +test_mp3_missing_id3_header.rgain = True def test_m4a_stereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.m4a', dict()) check_default_metadata(metadata) +test_m4a_stereo.rgain = True ''' WAVE is not supported by python-rgain yet def test_wav_stereo(): metadata = ReplayGainAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo.wav', dict()) check_default_metadata(metadata) -''' \ No newline at end of file +test_wav_stereo.rgain = True +''' From 7a3d87a4b2f44f3eca3600e71957265f376170b0 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sat, 4 Mar 2017 09:48:25 +0100 Subject: [PATCH 2/3] Run tests in small scripts This is so we get a proper shell where running set -xe makes sense allowing travis to pick up nicely on how the tests run (ie. marking them as failed and not errored when the fail). --- .travis.yml | 19 ++----------------- travis/php.sh | 9 +++++++++ travis/python.sh | 10 ++++++++++ 3 files changed, 21 insertions(+), 17 deletions(-) create mode 100755 travis/php.sh create mode 100755 travis/python.sh diff --git a/.travis.yml b/.travis.yml index 3fac6096a..1ff3e2f56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,20 +67,5 @@ before_script: - psql -c 'ALTER USER libretime CREATEDB;' -U postgres - mkdir -p /tmp/log/libretime script: -- > - if [[ "$PYTHON" == false ]]; then - pushd airtime_mvc/tests - ../../vendor/bin/phpunit - results=$? - popd - exit $results - fi -- > - if [[ "$PYTHON" == true ]]; then - pushd python_apps/airtime_analyzer - nosetests -a '!rgain' - results=$? - echo "replaygain tests where skipped due to not having a reliable replaygain install on travis." - popd - exit $results - fi +- ./travis/php.sh +- ./travis/python.sh diff --git a/travis/php.sh b/travis/php.sh new file mode 100755 index 000000000..9c8c91b13 --- /dev/null +++ b/travis/php.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -xe + +[[ "$PYTHON" == true ]] && exit 0 + +pushd airtime_mvc/tests +../../vendor/bin/phpunit +popd diff --git a/travis/python.sh b/travis/python.sh new file mode 100755 index 000000000..2c61e0c3a --- /dev/null +++ b/travis/python.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -xe + +[[ "$PYTHON" == false ]] && exit 0 + +pushd python_apps/airtime_analyzer +nosetests -a '!rgain' +echo "replaygain tests where skipped due to not having a reliable replaygain install on travis." +popd From 69a6eeb7bb0af2e422c7bf9db3f3d59627eb25d5 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sat, 4 Mar 2017 16:40:23 +0100 Subject: [PATCH 3/3] Build docs from conditional python script --- .travis.yml | 1 - travis/python.sh | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be7aed736..e8dfecdf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,6 @@ before_script: script: - ./travis/php.sh - ./travis/python.sh -- mkdocs build --clean -q > /dev/null deploy: provider: pages skip_cleanup: true diff --git a/travis/python.sh b/travis/python.sh index 2c61e0c3a..27e4441f2 100755 --- a/travis/python.sh +++ b/travis/python.sh @@ -8,3 +8,7 @@ pushd python_apps/airtime_analyzer nosetests -a '!rgain' echo "replaygain tests where skipped due to not having a reliable replaygain install on travis." popd + +echo "Building docs..." +mkdocs build --clean -q > /dev/null +echo -n "done"