From 19f2700d87d7c7fda12949bad8c787ee8e245418 Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Mon, 24 Oct 2022 18:08:42 +0200 Subject: [PATCH 01/13] Python template: - Add .gitignore - Add requirements.txt - Add "add" function - Add pytest config - Add feature file - Add steps - Add README --- python/.gitignore | 160 +++++++++++++++++++++++ python/README.md | 41 ++++++ python/currency_converter/__init__.py | 0 python/currency_converter/calculator.py | 2 + python/pytest.ini | 6 + python/requirements.txt | Bin 0 -> 504 bytes python/tests/__init__.py | 0 python/tests/features/calculator.feature | 23 ++++ python/tests/steps/__init__.py | 0 python/tests/steps/test_calculator.py | 64 +++++++++ 10 files changed, 296 insertions(+) create mode 100644 python/.gitignore create mode 100644 python/README.md create mode 100644 python/currency_converter/__init__.py create mode 100644 python/currency_converter/calculator.py create mode 100644 python/pytest.ini create mode 100644 python/requirements.txt create mode 100644 python/tests/__init__.py create mode 100644 python/tests/features/calculator.feature create mode 100644 python/tests/steps/__init__.py create mode 100644 python/tests/steps/test_calculator.py diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..6769e21 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..9b9e40b --- /dev/null +++ b/python/README.md @@ -0,0 +1,41 @@ +# Automation BDD Python Quickstart + +Ce projet template vous permettra de commencer rapidement à créer la glue entre les scénarios BDD issus de la phase de _BDD formulation_ et les tests logiciels. + +Il existe plusieurs packages python capables de supporter cette glue, les plus connus étant [pytest-bdd](https://pytest-bdd.readthedocs.io/en/stable/) et [behave](https://behave.readthedocs.io/en/stable/). Le parti pris est ici celui de [pytest-bdd](https://pytest-bdd.readthedocs.io/en/stable/) car vous permettra de réutiliser tout ce que vous savez déjà sur [pytest](https://docs.pytest.org/). + +## Pré-requis + +Il vous faut une version de Python>=3.7. + +## Installation de [pytest-bdd](https://pytest-bdd.readthedocs.io/en/stable/) + +Vous n'utilisez pas un environnement virtuel Python ? On ne vous en voudra pas, mais ce serait top de vous y intéresser. + +Environnement virtuel ou non, il s'agit de se placer dans le dossier projet _python_ du repository puis de saisir la commande suivante : + +``` +> pip install -r requirements.txt +``` + +## Vérifier que ça fonctionne + +Il suffit de saisir la commande suivante : + +``` +> pytest +``` + +Vous pouvez essayer, c'est sans danger. Ce sera avec ce mot _pytest_ que vous lancerez tous vos tests. + +## Comment ça marche ? + +Les scénario écrit au format Gherkin sont placés dans le dossier _tests/features_. + +Les steps quant à eux se trouvent dans des fichiers python dans le dossier _tests/steps_, comme vous le feriez normalement avec [pytest](https://docs.pytest.org/). + +Allez, c'est parti regardez dans ces fichiers comment faire la glue ! + +## Ah oui, un dernier détail + +Pour éviter certaines galères avec les _Scenario Outlines_ vérifiez bien que l'encodage de vos fichiers sont en UTF-8. diff --git a/python/currency_converter/__init__.py b/python/currency_converter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/currency_converter/calculator.py b/python/currency_converter/calculator.py new file mode 100644 index 0000000..19cf2a0 --- /dev/null +++ b/python/currency_converter/calculator.py @@ -0,0 +1,2 @@ +def add(a, b): + return a + b \ No newline at end of file diff --git a/python/pytest.ini b/python/pytest.ini new file mode 100644 index 0000000..78720da --- /dev/null +++ b/python/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +testpaths = tests/ +log_cli = True +log_cli_level = INFO +log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) +log_cli_date_format = %Y-%m-%d %H:%M:%S \ No newline at end of file diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8408a102b59f7db55aa48e315252f74e1353b37 GIT binary patch literal 504 zcmYjOOAdli5bN5+qd>$Tap4hMc>+Kn#2*1nIX7Ujy;pdkviS!JewBtx*<0!-Dqg9sNxjN@ zW79$!VlUJ<^SeN9tRY=wteQwhRzh|8xyRbHTt^J;=F{$cpo?!ep#g8u)603 + And the second number is: + When the two numbers are added + Then the result should be: + + Examples: + | first_number | second_number | sum | comment | + | 50 | 70 | 120 | Happy path | + | 70 | 50 | 120 | Happy path swapped | + | 50 | -50 | 0 | A number plus its opposite yields to identity element | + | 50 | 0 | 50 | A number plus identity element yields to the number | + diff --git a/python/tests/steps/__init__.py b/python/tests/steps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py new file mode 100644 index 0000000..45bfc0c --- /dev/null +++ b/python/tests/steps/test_calculator.py @@ -0,0 +1,64 @@ +import pytest +from pytest_bdd import given, scenario, then, when, parsers + +from currency_converter.calculator import add + +######################################################################################################################## +# How to glue a scenario +######################################################################################################################## + +# Arguments: feature file path, scenario name +@scenario("../features/calculator.feature", "Add two numbers") +def test_add_two_numbers() -> None: + pass + + +@given("the first number is 50", target_fixture="context") +def initialize_first_number_equal_to_50(): + return {"first_number": 50} + + +@given("the second number is 70") +def initialize_second_number_equal_to_70(context) -> None: + context["second_number"] = 70 + + +@when("the two numbers are added") +def add_context_numbers(context) -> None: + context["addition_result"] = add(context["first_number"], context["second_number"]) + + +@then("the result should be 120") +def check_if_addition_value_is_120(context) -> None: + assert context["addition_result"] == 120 + + +######################################################################################################################## +# How to glue a scenario outline +######################################################################################################################## + + +@scenario("../features/calculator.feature", "Add two numbers with templating") +def test_add_two_numbers_with_templating() -> None: + pass + + +@given(parsers.parse("the first number is: {first_number:d}"), target_fixture="context") +def initialize_first_number(first_number): + return {"first_number": first_number} + + +@given(parsers.parse("the second number is: {second_number:d}")) +def initialize_second_number(context, second_number) -> None: + context["second_number"] = second_number + + +# Reuse When step! +@when("the two numbers are added") +def add_context_numbers(context) -> None: + context["addition_result"] = add(context["first_number"], context["second_number"]) + + +@then(parsers.parse("the result should be: {sum:d}")) +def check_addition(context, sum) -> None: + assert context["addition_result"] == sum From 6c3941390e674e8cb7a504591139a4942ec93468 Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Mon, 24 Oct 2022 18:13:37 +0200 Subject: [PATCH 02/13] Simplify .gitignore --- .gitignore | 352 +---------------------------------------------------- 1 file changed, 1 insertion(+), 351 deletions(-) diff --git a/.gitignore b/.gitignore index a890c85..ed8ebf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,351 +1 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ -/csharp/CurrencyConverter/LivingDoc.html +__pycache__ \ No newline at end of file From 0fb0a467788981258da2f45568cce7b6fe5589bd Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 11:21:43 +0200 Subject: [PATCH 03/13] remove block comment and format with black --- python/tests/steps/test_calculator.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index 45bfc0c..d82edfe 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -3,10 +3,6 @@ from currency_converter.calculator import add -######################################################################################################################## -# How to glue a scenario -######################################################################################################################## - # Arguments: feature file path, scenario name @scenario("../features/calculator.feature", "Add two numbers") def test_add_two_numbers() -> None: @@ -33,11 +29,6 @@ def check_if_addition_value_is_120(context) -> None: assert context["addition_result"] == 120 -######################################################################################################################## -# How to glue a scenario outline -######################################################################################################################## - - @scenario("../features/calculator.feature", "Add two numbers with templating") def test_add_two_numbers_with_templating() -> None: pass From 8487927210b52d0e4fafab6df4487f1918136151 Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 11:55:05 +0200 Subject: [PATCH 04/13] format with black --- python/currency_converter/calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/currency_converter/calculator.py b/python/currency_converter/calculator.py index 19cf2a0..4693ad3 100644 --- a/python/currency_converter/calculator.py +++ b/python/currency_converter/calculator.py @@ -1,2 +1,2 @@ def add(a, b): - return a + b \ No newline at end of file + return a + b From 508d8cef89326a5d31f91f4568135142339258ad Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 11:57:31 +0200 Subject: [PATCH 05/13] reduce code duplication between initialize_first_number_equal_to_50 and initialize_second_number_equal_to_70 --- python/tests/steps/test_calculator.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index d82edfe..dcb9f95 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -10,13 +10,12 @@ def test_add_two_numbers() -> None: @given("the first number is 50", target_fixture="context") -def initialize_first_number_equal_to_50(): - return {"first_number": 50} - - @given("the second number is 70") -def initialize_second_number_equal_to_70(context) -> None: - context["second_number"] = 70 +def initialize_first_number_equal_to_50_and_the_second_number_is_equal_to_70(): + return { + "first_number": 50, + "second_number": 70, + } @when("the two numbers are added") From 18d0670a7da38ee2a15b6577911197dbf9859458 Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 12:09:30 +0200 Subject: [PATCH 06/13] Remove uneeded comments --- python/tests/steps/test_calculator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index dcb9f95..a864eef 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -3,7 +3,7 @@ from currency_converter.calculator import add -# Arguments: feature file path, scenario name + @scenario("../features/calculator.feature", "Add two numbers") def test_add_two_numbers() -> None: pass @@ -43,7 +43,6 @@ def initialize_second_number(context, second_number) -> None: context["second_number"] = second_number -# Reuse When step! @when("the two numbers are added") def add_context_numbers(context) -> None: context["addition_result"] = add(context["first_number"], context["second_number"]) From 4d7dc9d9def86ea745f8f2e6fc32476b8b807e0b Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 14:37:58 +0200 Subject: [PATCH 07/13] auto detection for scenarios --- python/tests/steps/test_calculator.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index a864eef..28e5d30 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -1,12 +1,10 @@ import pytest -from pytest_bdd import given, scenario, then, when, parsers +from pytest_bdd import given, scenario, then, when, parsers, scenarios from currency_converter.calculator import add -@scenario("../features/calculator.feature", "Add two numbers") -def test_add_two_numbers() -> None: - pass +scenarios("../features/calculator.feature") @given("the first number is 50", target_fixture="context") @@ -28,11 +26,6 @@ def check_if_addition_value_is_120(context) -> None: assert context["addition_result"] == 120 -@scenario("../features/calculator.feature", "Add two numbers with templating") -def test_add_two_numbers_with_templating() -> None: - pass - - @given(parsers.parse("the first number is: {first_number:d}"), target_fixture="context") def initialize_first_number(first_number): return {"first_number": first_number} From 6c0a29e1473a6a8dcc9806b0ec69dbc180e4cf39 Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 14:46:01 +0200 Subject: [PATCH 08/13] remove unused import --- python/tests/steps/test_calculator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index 28e5d30..db77a38 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -1,5 +1,4 @@ -import pytest -from pytest_bdd import given, scenario, then, when, parsers, scenarios +from pytest_bdd import given, then, when, parsers, scenarios from currency_converter.calculator import add From 89c0315384699293eafd1ca47ea66e0aee48420e Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 14:48:20 +0200 Subject: [PATCH 09/13] remove pytest.ini --- python/pytest.ini | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 python/pytest.ini diff --git a/python/pytest.ini b/python/pytest.ini deleted file mode 100644 index 78720da..0000000 --- a/python/pytest.ini +++ /dev/null @@ -1,6 +0,0 @@ -[pytest] -testpaths = tests/ -log_cli = True -log_cli_level = INFO -log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) -log_cli_date_format = %Y-%m-%d %H:%M:%S \ No newline at end of file From 0057ee4580803b490d585115323c94b723dfcb9e Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Tue, 25 Oct 2022 16:08:13 +0200 Subject: [PATCH 10/13] python: remove unused tag This fixes a pytest warning --- python/tests/features/calculator.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/python/tests/features/calculator.feature b/python/tests/features/calculator.feature index 8daadb5..4e663e8 100644 --- a/python/tests/features/calculator.feature +++ b/python/tests/features/calculator.feature @@ -1,7 +1,6 @@ Feature: Calculator Simple calculator for adding **two** numbers - @mytag Scenario: Add two numbers Given the first number is 50 And the second number is 70 From c3dd6ca47750e05ca0c1be39e1c40c2bcf203ec4 Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 17:03:37 +0200 Subject: [PATCH 11/13] remove global gitignore and simplify python gitignore --- .gitignore | 1 - python/.gitignore | 162 +--------------------------------------------- 2 files changed, 2 insertions(+), 161 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ed8ebf5..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ \ No newline at end of file diff --git a/python/.gitignore b/python/.gitignore index 6769e21..b0f2192 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -1,160 +1,2 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +__pycache__ +.venv \ No newline at end of file From 3386cf1b5a153cb26a0d1eca46c68e5650750112 Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Tue, 25 Oct 2022 17:09:18 +0200 Subject: [PATCH 12/13] change scenario to be like in other languages then use parameterized tests --- python/tests/features/calculator.feature | 14 ----------- python/tests/steps/test_calculator.py | 31 +++++------------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/python/tests/features/calculator.feature b/python/tests/features/calculator.feature index 4e663e8..9e6f408 100644 --- a/python/tests/features/calculator.feature +++ b/python/tests/features/calculator.feature @@ -6,17 +6,3 @@ Feature: Calculator And the second number is 70 When the two numbers are added Then the result should be 120 - - Scenario Outline: Add two numbers with templating - Given the first number is: - And the second number is: - When the two numbers are added - Then the result should be: - - Examples: - | first_number | second_number | sum | comment | - | 50 | 70 | 120 | Happy path | - | 70 | 50 | 120 | Happy path swapped | - | 50 | -50 | 0 | A number plus its opposite yields to identity element | - | 50 | 0 | 50 | A number plus identity element yields to the number | - diff --git a/python/tests/steps/test_calculator.py b/python/tests/steps/test_calculator.py index db77a38..7a2cdb3 100644 --- a/python/tests/steps/test_calculator.py +++ b/python/tests/steps/test_calculator.py @@ -6,40 +6,21 @@ scenarios("../features/calculator.feature") -@given("the first number is 50", target_fixture="context") -@given("the second number is 70") -def initialize_first_number_equal_to_50_and_the_second_number_is_equal_to_70(): - return { - "first_number": 50, - "second_number": 70, - } - - -@when("the two numbers are added") -def add_context_numbers(context) -> None: - context["addition_result"] = add(context["first_number"], context["second_number"]) - - -@then("the result should be 120") -def check_if_addition_value_is_120(context) -> None: - assert context["addition_result"] == 120 - - -@given(parsers.parse("the first number is: {first_number:d}"), target_fixture="context") +@given(parsers.parse("the first number is {first_number:d}"), target_fixture="context") def initialize_first_number(first_number): return {"first_number": first_number} -@given(parsers.parse("the second number is: {second_number:d}")) -def initialize_second_number(context, second_number) -> None: +@given(parsers.parse("the second number is {second_number:d}")) +def initialize_second_number(context, second_number): context["second_number"] = second_number @when("the two numbers are added") -def add_context_numbers(context) -> None: +def add_context_numbers(context): context["addition_result"] = add(context["first_number"], context["second_number"]) -@then(parsers.parse("the result should be: {sum:d}")) -def check_addition(context, sum) -> None: +@then(parsers.parse("the result should be {sum:d}")) +def check_addition(context, sum): assert context["addition_result"] == sum From 5549bf85231fc7b38411a4a63570df6d11f4903f Mon Sep 17 00:00:00 2001 From: Tristan Chaput Date: Wed, 26 Oct 2022 09:57:11 +0200 Subject: [PATCH 13/13] convert requirements.txt to utf-8 --- python/requirements.txt | Bin 504 -> 238 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/python/requirements.txt b/python/requirements.txt index c8408a102b59f7db55aa48e315252f74e1353b37..8e7667efb012e6199be97a5b6357e1e8e547cd49 100644 GIT binary patch literal 238 zcmW+w$qmCG5d71N5#S`2A6r6RsbGB}WNZ*%Db$unN=gga<+pR}%=|uIEG16%iN$Tap4hMc>+Kn#2*1nIX7Ujy;pdkviS!JewBtx*<0!-Dqg9sNxjN@ zW79$!VlUJ<^SeN9tRY=wteQwhRzh|8xyRbHTt^J;=F{$cpo?!ep#g8u)603