From 4150bda494f8f84c5d8add228f4d0d924db8d8cd Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:38:33 +0000 Subject: [PATCH 01/11] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..7d405f9ee --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,36 @@ +# Python package +# Create and test a Python package on multiple Python versions. +# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/python + +trigger: +- master + +pool: + vmImage: 'ubuntu-latest' +strategy: + matrix: + Python27: + python.version: '2.7' + Python35: + python.version: '3.5' + Python36: + python.version: '3.6' + Python37: + python.version: '3.7' + +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + displayName: 'Use Python $(python.version)' + +- script: | + python -m pip install --upgrade pip + pip install -r requirements.txt + displayName: 'Install dependencies' + +- script: | + pip install pytest pytest-azurepipelines + pytest + displayName: 'pytest' From 3f5bd46d1945e1594180cfeb9706c745b4a09bec Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:52:14 +0000 Subject: [PATCH 02/11] Update azure-pipelines.yml --- azure-pipelines.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7d405f9ee..eec939c66 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,8 +29,13 @@ steps: python -m pip install --upgrade pip pip install -r requirements.txt displayName: 'Install dependencies' +- script: | + python -m pip install flake8 + flake8 . + displayName: 'Run lint tests - script: | - pip install pytest pytest-azurepipelines - pytest - displayName: 'pytest' + pip install pytest + pip install pytest-cov + pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + displayName: 'Test with pytest' From 53e88fc744c8611457d4a205706b58babfb02688 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:53:11 +0000 Subject: [PATCH 03/11] Update azure-pipelines.yml --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index eec939c66..e997d908e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,9 +30,9 @@ steps: pip install -r requirements.txt displayName: 'Install dependencies' - script: | - python -m pip install flake8 - flake8 . - displayName: 'Run lint tests + python -m pip install flake8 + flake8 . + displayName: 'Run lint tests - script: | pip install pytest From c300eb26c615bb469921c12ebc0603e8c4d48215 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:53:50 +0000 Subject: [PATCH 04/11] Update azure-pipelines.yml --- azure-pipelines.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e997d908e..f01b8e7c2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,9 +33,3 @@ steps: python -m pip install flake8 flake8 . displayName: 'Run lint tests - -- script: | - pip install pytest - pip install pytest-cov - pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - displayName: 'Test with pytest' From 1290729d32adbc0b42dd047e44a30681aec145a4 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:54:12 +0000 Subject: [PATCH 05/11] Update azure-pipelines.yml --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f01b8e7c2..a1bc2c3d6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,4 +32,4 @@ steps: - script: | python -m pip install flake8 flake8 . - displayName: 'Run lint tests + displayName: 'Run lint tests' From e2bf4e92f72e146fce183b4fbebc1153d09bd501 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 13:57:50 +0000 Subject: [PATCH 06/11] Update azure-pipelines.yml --- azure-pipelines.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a1bc2c3d6..525c8772c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,7 +29,9 @@ steps: python -m pip install --upgrade pip pip install -r requirements.txt displayName: 'Install dependencies' + - script: | - python -m pip install flake8 - flake8 . - displayName: 'Run lint tests' + pip install pytest + pip install pytest-cov + pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + displayName: 'Test with pytest' From 0e8b4066a486463ab601349bc27d55e05ee7b3c6 Mon Sep 17 00:00:00 2001 From: Adam B Date: Mon, 20 Jan 2020 14:29:47 +0000 Subject: [PATCH 07/11] adding test --- .vscode/settings.json | 12 +++++++++++- hello_app/helloworld.py | 7 +++++++ hello_app/test_helloworld.py | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 hello_app/helloworld.py create mode 100644 hello_app/test_helloworld.py diff --git a/.vscode/settings.json b/.vscode/settings.json index b035bb43d..efe0b9062 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,13 @@ { - "python.pythonPath": "${workspaceFolder}\\env\\Scripts\\python.exe" + "python.pythonPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Anaconda3_64\\python.exe", + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": true } \ No newline at end of file diff --git a/hello_app/helloworld.py b/hello_app/helloworld.py new file mode 100644 index 000000000..a72f5f8be --- /dev/null +++ b/hello_app/helloworld.py @@ -0,0 +1,7 @@ +class helloWorld(): + def __init__(self): + pass + + def hello_world(self, person_name=None): + + return f"Hello {person_name}" \ No newline at end of file diff --git a/hello_app/test_helloworld.py b/hello_app/test_helloworld.py new file mode 100644 index 000000000..c62c59bf7 --- /dev/null +++ b/hello_app/test_helloworld.py @@ -0,0 +1,7 @@ +import unittest +from .helloworld import helloWorld + +class TestHelloWorldMethods(unittest.TestCase): + + def test_helloworld(self): + self.assertEqual(helloWorld.hello_world(self, "adam"), 'Hello adam') \ No newline at end of file From 558ca53a76a265573269c260b9b1f6dd9bcedf45 Mon Sep 17 00:00:00 2001 From: Adam B Date: Mon, 20 Jan 2020 14:36:18 +0000 Subject: [PATCH 08/11] updating pipeline --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 525c8772c..af564f213 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,5 +33,5 @@ steps: - script: | pip install pytest pip install pytest-cov - pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + pytest -k 'test_' --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html displayName: 'Test with pytest' From ab46583a74cacc7625c250acbb69860ec6b86bde Mon Sep 17 00:00:00 2001 From: Adam B Date: Mon, 20 Jan 2020 14:42:10 +0000 Subject: [PATCH 09/11] adding main() --- hello_app/test_helloworld.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hello_app/test_helloworld.py b/hello_app/test_helloworld.py index c62c59bf7..c09550e19 100644 --- a/hello_app/test_helloworld.py +++ b/hello_app/test_helloworld.py @@ -4,4 +4,7 @@ class TestHelloWorldMethods(unittest.TestCase): def test_helloworld(self): - self.assertEqual(helloWorld.hello_world(self, "adam"), 'Hello adam') \ No newline at end of file + self.assertEqual(helloWorld.hello_world(self, "adam"), 'Hello adam') + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From fb085b4936a7ee89f851c105db8143f9467ca397 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 14:43:15 +0000 Subject: [PATCH 10/11] Removing old python versions --- azure-pipelines.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index af564f213..3b433946c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,10 +10,6 @@ pool: vmImage: 'ubuntu-latest' strategy: matrix: - Python27: - python.version: '2.7' - Python35: - python.version: '3.5' Python36: python.version: '3.6' Python37: From ed55bd3b95e23cc6ed37b0c1fec5d7a7e9e5d530 Mon Sep 17 00:00:00 2001 From: adambdevops <60100751+adambdevops@users.noreply.github.com> Date: Mon, 20 Jan 2020 14:45:05 +0000 Subject: [PATCH 11/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d07d6d8ed..bad955ab9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Python/Flask tutorial sample for Visual Studio Code +[![Build Status](https://dev.azure.com/adambdevops/adambdevops/_apis/build/status/adambdevops.python-sample-vscode-flask-tutorial?branchName=master)](https://dev.azure.com/adambdevops/adambdevops/_build/latest?definitionId=2&branchName=master) + * This sample contains the completed program from the tutorial, make sure to visit the link: [Using Flask in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-flask). Intermediate steps are not included. * It also contains the Dockerfile and uwsgi.ini files necessary to build a container with a production server. The resulting image works both locally and when deployed to Azure App Service. See [Deploy Python using Docker containers](https://code.visualstudio.com/docs/python/tutorial-deploy-containers).