diff --git a/.gitignore b/.gitignore index 227a0bd..bc1fbe0 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,7 @@ ENV/ *.txt *.pickle *.zip + +# BDD Testing +testing/ +!test-requirements.txt \ No newline at end of file diff --git a/README.rst b/README.rst index 92201c4..47a6b6e 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 testing/bin/activate + pip install --upgrade pip + pip install -r test-requirements.txt + + # Running Behave and all BDD tests + behave Example ------- 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/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..95374bb --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +behave==1.2.6 +pandas==0.25.1 +PyHamcrest==2.0.2 \ No newline at end of file diff --git a/tests/environment.py b/tests/environment.py new file mode 100644 index 0000000..2a309e9 --- /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/allele.feature b/tests/features/allele.feature new file mode 100644 index 0000000..6ddaabc --- /dev/null +++ b/tests/features/allele.feature @@ -0,0 +1,23 @@ +Feature: Alleles + + 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 | + + | 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/glstring.feature b/tests/features/glstring.feature new file mode 100644 index 0000000..c53c61b --- /dev/null +++ b/tests/features/glstring.feature @@ -0,0 +1,21 @@ +Feature: GL (Genotype List) Strings + + 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: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 diff --git a/tests/features/mac.feature b/tests/features/mac.feature new file mode 100644 index 0000000..101000e --- /dev/null +++ b/tests/features/mac.feature @@ -0,0 +1,14 @@ +Feature: MAC (Multiple Allele Code) + + 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..e706140 --- /dev/null +++ b/tests/features/p_g_group.feature @@ -0,0 +1,12 @@ +Feature: P and G Groups + + 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 diff --git a/tests/steps/redux_allele.py b/tests/steps/redux_allele.py new file mode 100644 index 0000000..3a07e1f --- /dev/null +++ b/tests/steps/redux_allele.py @@ -0,0 +1,19 @@ +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) + +@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