diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8819bda --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.swp +*.swo +*.pyc +__pycache__ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6eccd83..41c0022 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,50 +7,79 @@ trigger: - master pool: + #name: TradeMetrics-Build vmImage: 'ubuntu-latest' + + strategy: matrix: - Python35: - PYTHON_VERSION: '3.5' Python37: PYTHON_VERSION: '3.7' maxParallel: 3 +variables: + DEBIAN_FRONTEND: 'noninteractive' + steps: -- task: UsePythonVersion@0 - inputs: - versionSpec: '$(PYTHON_VERSION)' - architecture: 'x64' -- task: PythonScript@0 - displayName: 'Export project path' - inputs: - scriptSource: 'inline' - script: | - """Search all subdirectories for `manage.py`.""" - from glob import iglob - from os import path - # Python >= 3.5 - manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None) - if not manage_py: - raise SystemExit('Could not find a Django project') - project_location = path.dirname(path.abspath(manage_py)) - print('Found Django project in', project_location) - print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location)) +- script: | + set -x + # The total size of the env variables must be less than ARG_MAX + # or you will get an "Argument list too long" error. + # This is normally 2097152 bytes (2,048 KB). A single env variable + # is must be no greater than 1/16 of ARG_MAX or 128 KB. + getconf ARG_MAX + env | wc -c + echo "TESTPATH=$TESTPATH" + echo "DEBIAN_FRONTEND=$DEBIAN_FRONTEND" + displayName: 'Display env' + env: + TESTPATH: '$(System.DefaultWorkingDirectory)/fakebin' - script: | + echo "Test script" + date + ls + pwd + which env + echo "GLOB TEST:" * + env | sort + displayName: 'Test script task' + env: + PATH: '$(System.DefaultWorkingDirectory)/fakebin:/usr/share/rust/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin' + +- script: | + DEBIAN_FRONTEND=noninteractive apt update + DEBIAN_FRONTEND=noninteractive apt install -y wget bzip2 + wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh + rm -Rf /root/miniconda3 + bash Miniconda3-latest-Linux-x86_64.sh -b + source $HOME/miniconda3/bin/activate + conda env update -q -f server/environment.yml > /dev/null + source /home/vsts/miniconda3/etc/profile.d/conda.sh + conda activate python -m pip install --upgrade pip setuptools wheel - pip install -r requirements.txt pip install unittest-xml-reporting displayName: 'Install prerequisites' - script: | - pushd '$(projectRoot)' - python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input + pushd 'server' + source /home/vsts/miniconda3/etc/profile.d/conda.sh + conda activate + #python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input + pytest -vv displayName: 'Run tests' - task: PublishTestResults@2 inputs: - testResultsFiles: "**/TEST-*.xml" + testResultsFiles: "**/test-*.xml" testRunTitle: 'Python $(PYTHON_VERSION)' condition: succeededOrFailed() + +- task: PublishCodeCoverageResults@1 + inputs: + # pytest-cov creates a coverage.xml file in the same format as Cobertura. + codeCoverageTool: Cobertura + summaryFileLocation: '**/coverage.xml' + reportDirectory: '**/htmlcov' + condition: succeededOrFailed() diff --git a/fakebin/bash b/fakebin/bash new file mode 100755 index 0000000..0da6a26 --- /dev/null +++ b/fakebin/bash @@ -0,0 +1,29 @@ +#!/bin/bash + +set -x +echo "OVERRIDE bash interpreter" +echo "ARGS: $0 $*" +echo "PWD: $PWD" +echo "PATH=$PATH" +which bash +PATH=/bin:/usr/bin +echo "new PATH=$PATH" +which bash +cd /usr +echo "Arg count: $#" +start_args=${@:1:$[ $# - 1 ]} +echo "All but last arg: $start_args" +last_arg=${@:$#:$[ $# + 1 ]} +echo "Last arg: $last_arg" + +# Bash does not allow "GNU long options" such as "--norc" +# to be after short options such as "-x". +echo "Do not execute, just evaluate:" +/bin/bash $start_args -nv $last_arg + +echo "Execute without GLOB support:" +/bin/bash $start_args -xf $last_arg + +echo "Execute with GLOB support:" +/bin/bash $start_args -x $last_arg + diff --git a/server/citrial/models.py b/server/citrial/models.py new file mode 100644 index 0000000..c6cd7f0 --- /dev/null +++ b/server/citrial/models.py @@ -0,0 +1,10 @@ + + + +def foo(): + x = 1 + return x + +def bar(): + y = 2 + return y diff --git a/server/citrial/tests.py b/server/citrial/tests.py new file mode 100644 index 0000000..955b2cb --- /dev/null +++ b/server/citrial/tests.py @@ -0,0 +1,15 @@ +from unittest import TestCase + + +class TestPractice(TestCase): + def testGood(self): + self.assertEqual(1, 1) + + def testBad(self): + self.assertEqual(1, 0) + + +def test_pytest_testfinder(): + from citrial.models import foo + foo() + assert 1 == 0 diff --git a/server/environment.yml b/server/environment.yml index c270c0e..856dc3e 100644 --- a/server/environment.yml +++ b/server/environment.yml @@ -10,6 +10,8 @@ dependencies: - gunicorn - pytest - pytest-django + - pytest-azurepipelines + - pytest-cov - pandas - xlrd - ujson diff --git a/server/pytest.ini b/server/pytest.ini new file mode 100644 index 0000000..c21c5db --- /dev/null +++ b/server/pytest.ini @@ -0,0 +1,8 @@ +[pytest] +DJANGO_SETTINGS_MODULE=citrial.settings + +# Use conftest.py to ignore directories or files. +# https://docs.pytest.org/en/latest/example/pythoncollection.html#customizing-test-collection +python_files = tests.py test_*.py *_tests.py +#addopts = -q -r fExXp --disable-warnings --disable-pytest-warnings --showlocals --no-migrations +addopts = --durations=0 -r fExXp --tb=line --capture=no --doctest-modules --disable-warnings --disable-pytest-warnings --showlocals --reuse-db --cov=citrial --cov-report=html