From 36af8765017c73ce00ddc105b4cf04cefa845d95 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Tue, 8 Sep 2020 11:48:19 -0500 Subject: [PATCH 01/10] add files for BDD tests --- behave.ini | 7 +++++++ tests/environment.py | 4 ++++ tests/features/no_mac.feature | 16 ++++++++++++++++ tests/steps/redux_allele.py | 14 ++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 behave.ini create mode 100644 tests/environment.py create mode 100644 tests/features/no_mac.feature create mode 100644 tests/steps/redux_allele.py diff --git a/behave.ini b/behave.ini new file mode 100644 index 0000000..40723be --- /dev/null +++ b/behave.ini @@ -0,0 +1,7 @@ +[behave] +paths=tests +format=pretty +show_snippets=false + +; Development +stop=true \ No newline at end of file diff --git a/tests/environment.py b/tests/environment.py new file mode 100644 index 0000000..37b2178 --- /dev/null +++ b/tests/environment.py @@ -0,0 +1,4 @@ + +from pyard import ARD +def before_all(context): + context.ard = ARD(verbose=True) \ No newline at end of file diff --git a/tests/features/no_mac.feature b/tests/features/no_mac.feature new file mode 100644 index 0000000..5d838fb --- /dev/null +++ b/tests/features/no_mac.feature @@ -0,0 +1,16 @@ +Feature: Reduce alleles (no MAC) + + Scenario Outline: + + Given the allele as + When reducing on the level + Then the reduced allele is found to be + + Examples: + | Allele | Level | Redux Allele | + | A*01:01:01 | G | A*01:01:01G | + | A*01:01:01 | lg | A*01:01g | + | A*01:01:01 | lgx | A*01:01 | + | HLA-A*01:01:01 | G | HLA-A*01:01:01G | + | HLA-A*01:01:01 | lg | HLA-A*01:01g | + | HLA-A*01:01:01 | lgx | HLA-A*01:01 | \ No newline at end of file diff --git a/tests/steps/redux_allele.py b/tests/steps/redux_allele.py new file mode 100644 index 0000000..cc06742 --- /dev/null +++ b/tests/steps/redux_allele.py @@ -0,0 +1,14 @@ +from hamcrest import assert_that, is_ + +@given('the allele as {allele}') +def step_impl(context, allele): + context.allele = allele + +@when('reducing on the {level} level') +def step_impl(context, level): + context.level = level + context.redux_allele = context.ard.redux(context.allele, level) + +@then('the reduced allele is found to be {redux_allele}') +def step_impl(context, redux_allele): + assert_that(context.redux_allele, is_(redux_allele)) \ No newline at end of file From 206e6cb062b393d8be7ce1f4917c2bd959742173 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 11:04:10 -0500 Subject: [PATCH 02/10] differentiate between reduxing functions in step file --- tests/environment.py | 2 +- tests/steps/redux_allele.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/environment.py b/tests/environment.py index 37b2178..2a309e9 100644 --- a/tests/environment.py +++ b/tests/environment.py @@ -1,4 +1,4 @@ - from pyard import ARD + def before_all(context): context.ard = ARD(verbose=True) \ No newline at end of file diff --git a/tests/steps/redux_allele.py b/tests/steps/redux_allele.py index cc06742..3a07e1f 100644 --- a/tests/steps/redux_allele.py +++ b/tests/steps/redux_allele.py @@ -9,6 +9,11 @@ def step_impl(context, level): context.level = level context.redux_allele = context.ard.redux(context.allele, level) +@when('reducing on the {level} level (ambiguous)') +def step_impl(context, level): + context.level = level + context.redux_allele = context.ard.redux_gl(context.allele, level) + @then('the reduced allele is found to be {redux_allele}') def step_impl(context, redux_allele): assert_that(context.redux_allele, is_(redux_allele)) \ No newline at end of file From 58dd1241b66ed4c09876759aeaaf1a4fc553ef11 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 11:51:24 -0500 Subject: [PATCH 03/10] add MAC BDD tests --- tests/features/with_mac.feature | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/features/with_mac.feature diff --git a/tests/features/with_mac.feature b/tests/features/with_mac.feature new file mode 100644 index 0000000..52c3bd2 --- /dev/null +++ b/tests/features/with_mac.feature @@ -0,0 +1,14 @@ +Feature: MAC (Multiple Allele Codes) + + Scenario Outline: + + Given the allele as + When reducing on the level (ambiguous) + Then the reduced allele is found to be + + Examples: + | Allele | Level | Redux Allele | + | A*01:AB | G | A*01:01:01G/A*01:02 | + | A*01:AB | lgx | A*01:01/A*01:02 | + | HLA-A*01:AB | G | HLA-A*01:01:01G/HLA-A*01:02 | + | HLA-A*01:AB | lgx | HLA-A*01:01/HLA-A*01:02 | \ No newline at end of file From d34f26b7b7242806048989a021658ca8445545fa Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:05:48 -0500 Subject: [PATCH 04/10] add more tests (P/G and GLstrings) --- tests/features/no_mac.feature | 9 ++++++++- tests/features/with_mac.feature | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/features/no_mac.feature b/tests/features/no_mac.feature index 5d838fb..0d308e9 100644 --- a/tests/features/no_mac.feature +++ b/tests/features/no_mac.feature @@ -11,6 +11,13 @@ Feature: Reduce alleles (no MAC) | A*01:01:01 | G | A*01:01:01G | | A*01:01:01 | lg | A*01:01g | | A*01:01:01 | lgx | A*01:01 | + | HLA-A*01:01:01 | G | HLA-A*01:01:01G | | HLA-A*01:01:01 | lg | HLA-A*01:01g | - | HLA-A*01:01:01 | lgx | HLA-A*01:01 | \ No newline at end of file + | HLA-A*01:01:01 | lgx | HLA-A*01:01 | + + | DRB1*14:05:01 | lgx | DRB1*14:05 | + | DRB1*14:05:01 | lg | DRB1*14:05g | + + | DRB1*14:06:01 | lgx | DRB1*14:06 | + | DRB1*14:06:01 | lg | DRB1*14:06g | \ No newline at end of file diff --git a/tests/features/with_mac.feature b/tests/features/with_mac.feature index 52c3bd2..e9d6f66 100644 --- a/tests/features/with_mac.feature +++ b/tests/features/with_mac.feature @@ -11,4 +11,19 @@ Feature: MAC (Multiple Allele Codes) | A*01:AB | G | A*01:01:01G/A*01:02 | | A*01:AB | lgx | A*01:01/A*01:02 | | HLA-A*01:AB | G | HLA-A*01:01:01G/HLA-A*01:02 | - | HLA-A*01:AB | lgx | HLA-A*01:01/HLA-A*01:02 | \ No newline at end of file + | HLA-A*01:AB | lgx | HLA-A*01:01/HLA-A*01:02 | + + | A*02:01P | lgx | A*02:01 | + | A*02:01:01G | lgx | A*02:01 | + + | A*01:01:01:01+A*01:01:01:01 | G | A*01:01:01G+A*01:01:01G | + | HLA-A*01:01:01:01+HLA-A*01:01:01:01 | G | HLA-A*01:01:01G+HLA-A*01:01:01G | + | A*01:01:01:01+A*01:01:01:01 | lg | A*01:01g+A*01:01g | + | HLA-A*01:01:01:01+HLA-A*01:01:01:01 | lg | HLA-A*01:01g+HLA-A*01:01g | + | A*01:01:01:01+A*01:01:01:01 | lgx | A*01:01+A*01:01 | + | HLA-A*01:01:01:01+HLA-A*01:01:01:01 | lgx | HLA-A*01:01+HLA-A*01:01 | + | A*01:01+A*01:01^B*07:02+B*07:02 | G | A*01:01:01G+A*01:01:01G^B*07:02:01G+B*07:02:01G | + | A*01:01+A*01:01^B*07:02+B*07:02 | lg | A*01:01g+A*01:01g^B*07:02g+B*07:02g | + | A*01:01~B*07:02+A*01:01~B*07:02 | G | A*01:01:01G~B*07:02:01G+A*01:01:01G~B*07:02:01G | + | A*01:01~B*07:02+A*01:01~B*07:02 | lg | A*01:01g~B*07:02g+A*01:01g~B*07:02g | + | A*01:01~B*07:02+A*01:01~B*07:02\|A*02:01~B*07:02+A*02:01~B*07:02 | lg | A*01:01g~B*07:02g+A*01:01g~B*07:02g\|A*02:01g~B*07:02g+A*02:01g~B*07:02g | \ No newline at end of file From 0cb451f30a218d6bb787383d378ce152a78ff779 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:07:58 -0500 Subject: [PATCH 05/10] split up into categories into different feature files --- tests/features/{no_mac.feature => allele.feature} | 0 .../{with_mac.feature => glstring.feature} | 8 -------- tests/features/mac.feature | 14 ++++++++++++++ tests/features/p_g_group.feature | 12 ++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) rename tests/features/{no_mac.feature => allele.feature} (100%) rename tests/features/{with_mac.feature => glstring.feature} (76%) create mode 100644 tests/features/mac.feature create mode 100644 tests/features/p_g_group.feature diff --git a/tests/features/no_mac.feature b/tests/features/allele.feature similarity index 100% rename from tests/features/no_mac.feature rename to tests/features/allele.feature diff --git a/tests/features/with_mac.feature b/tests/features/glstring.feature similarity index 76% rename from tests/features/with_mac.feature rename to tests/features/glstring.feature index e9d6f66..d95b580 100644 --- a/tests/features/with_mac.feature +++ b/tests/features/glstring.feature @@ -8,14 +8,6 @@ Feature: MAC (Multiple Allele Codes) Examples: | Allele | Level | Redux Allele | - | A*01:AB | G | A*01:01:01G/A*01:02 | - | A*01:AB | lgx | A*01:01/A*01:02 | - | HLA-A*01:AB | G | HLA-A*01:01:01G/HLA-A*01:02 | - | HLA-A*01:AB | lgx | HLA-A*01:01/HLA-A*01:02 | - - | A*02:01P | lgx | A*02:01 | - | A*02:01:01G | lgx | A*02:01 | - | A*01:01:01:01+A*01:01:01:01 | G | A*01:01:01G+A*01:01:01G | | HLA-A*01:01:01:01+HLA-A*01:01:01:01 | G | HLA-A*01:01:01G+HLA-A*01:01:01G | | A*01:01:01:01+A*01:01:01:01 | lg | A*01:01g+A*01:01g | diff --git a/tests/features/mac.feature b/tests/features/mac.feature new file mode 100644 index 0000000..52c3bd2 --- /dev/null +++ b/tests/features/mac.feature @@ -0,0 +1,14 @@ +Feature: MAC (Multiple Allele Codes) + + Scenario Outline: + + Given the allele as + When reducing on the level (ambiguous) + Then the reduced allele is found to be + + Examples: + | Allele | Level | Redux Allele | + | A*01:AB | G | A*01:01:01G/A*01:02 | + | A*01:AB | lgx | A*01:01/A*01:02 | + | HLA-A*01:AB | G | HLA-A*01:01:01G/HLA-A*01:02 | + | HLA-A*01:AB | lgx | HLA-A*01:01/HLA-A*01:02 | \ No newline at end of file diff --git a/tests/features/p_g_group.feature b/tests/features/p_g_group.feature new file mode 100644 index 0000000..3b902f9 --- /dev/null +++ b/tests/features/p_g_group.feature @@ -0,0 +1,12 @@ +Feature: MAC (Multiple Allele Codes) + + Scenario Outline: + + Given the allele as + When reducing on the level (ambiguous) + Then the reduced allele is found to be + + Examples: + | Allele | Level | Redux Allele | + | A*02:01P | lgx | A*02:01 | + | A*02:01:01G | lgx | A*02:01 | \ No newline at end of file From 280fe8e6744b07f648ab939fe6e6eaa8c2ec35ae Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:09:38 -0500 Subject: [PATCH 06/10] fix feature titles for split files --- tests/features/allele.feature | 2 +- tests/features/glstring.feature | 2 +- tests/features/mac.feature | 2 +- tests/features/p_g_group.feature | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/features/allele.feature b/tests/features/allele.feature index 0d308e9..6ddaabc 100644 --- a/tests/features/allele.feature +++ b/tests/features/allele.feature @@ -1,4 +1,4 @@ -Feature: Reduce alleles (no MAC) +Feature: Alleles Scenario Outline: diff --git a/tests/features/glstring.feature b/tests/features/glstring.feature index d95b580..c53c61b 100644 --- a/tests/features/glstring.feature +++ b/tests/features/glstring.feature @@ -1,4 +1,4 @@ -Feature: MAC (Multiple Allele Codes) +Feature: GL (Genotype List) Strings Scenario Outline: diff --git a/tests/features/mac.feature b/tests/features/mac.feature index 52c3bd2..101000e 100644 --- a/tests/features/mac.feature +++ b/tests/features/mac.feature @@ -1,4 +1,4 @@ -Feature: MAC (Multiple Allele Codes) +Feature: MAC (Multiple Allele Code) Scenario Outline: diff --git a/tests/features/p_g_group.feature b/tests/features/p_g_group.feature index 3b902f9..e706140 100644 --- a/tests/features/p_g_group.feature +++ b/tests/features/p_g_group.feature @@ -1,4 +1,4 @@ -Feature: MAC (Multiple Allele Codes) +Feature: P and G Groups Scenario Outline: From e24f574844ef23f6edd06f58483cb116f78155c0 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:31:57 -0500 Subject: [PATCH 07/10] add documentation and ignore testing virtual environment --- .gitignore | 3 +++ README.rst | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.gitignore b/.gitignore index 227a0bd..b0cafce 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,9 @@ coverage.xml *.cover .hypothesis/ +# BDD Testing +testing/ + # Translations *.mo *.pot diff --git a/README.rst b/README.rst index 92201c4..30fa132 100644 --- a/README.rst +++ b/README.rst @@ -34,6 +34,21 @@ Install from PyPi pip install py-ard +Testing + +------- +To run behavior-driven development (BDD) tests locally via the behave framework, +you'll need to set up a virtual environment. + +.. code-block:: + # Virtual environment setup + python3 -m venv testing + source venv/bin/activate + pip install --upgrade pip + pip install -r test-requirements.txt + + # Running Behave and all BDD tests + behave Example ------- From 9be8639d5aa49039678819f903085ec5e494aeeb Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:32:35 -0500 Subject: [PATCH 08/10] rename venv to testing --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 30fa132..47a6b6e 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ you'll need to set up a virtual environment. .. code-block:: # Virtual environment setup python3 -m venv testing - source venv/bin/activate + source testing/bin/activate pip install --upgrade pip pip install -r test-requirements.txt From 48b6dcf93186509e4867938e62087fa9a61b7864 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:34:55 -0500 Subject: [PATCH 09/10] don't ignore test-requirements; added --- .gitignore | 7 ++++--- test-requirements.txt | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 test-requirements.txt diff --git a/.gitignore b/.gitignore index b0cafce..bc1fbe0 100644 --- a/.gitignore +++ b/.gitignore @@ -46,9 +46,6 @@ coverage.xml *.cover .hypothesis/ -# BDD Testing -testing/ - # Translations *.mo *.pot @@ -107,3 +104,7 @@ ENV/ *.txt *.pickle *.zip + +# BDD Testing +testing/ +!test-requirements.txt \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..1de171e --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +behave==1.2.6 +PyHamcrest==2.0.2 +pandas==0.25.1 \ No newline at end of file From cea323ebc42b695a50631ccc0730a804bb7256a7 Mon Sep 17 00:00:00 2001 From: rsajulga-nmdp Date: Wed, 9 Sep 2020 12:37:06 -0500 Subject: [PATCH 10/10] reorder requirements --- test-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 1de171e..95374bb 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,3 @@ behave==1.2.6 -PyHamcrest==2.0.2 -pandas==0.25.1 \ No newline at end of file +pandas==0.25.1 +PyHamcrest==2.0.2 \ No newline at end of file