Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #37

Merged
merged 12 commits into from
Jan 5, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `gc_clamp` property
- `single_runs` property
### Changed
- Test system modified
### Removed
- `property` deleter & setter
## [0.1] - 2024-11-27
Expand Down
1 change: 1 addition & 0 deletions autopep8.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python -m autopep8 opr --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 otherfiles --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 tests --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 setup.py --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose
1 change: 1 addition & 0 deletions autopep8.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
python -m autopep8 opr --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 otherfiles --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 tests --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose --ignore=E721
python -m autopep8 setup.py --recursive --aggressive --aggressive --in-place --pep8-passes 2000 --max-line-length 120 --verbose
34 changes: 34 additions & 0 deletions tests/test_cache.py
AHReccese marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from opr import Primer, MeltingTemperature

TEST_CASE_NAME = "Cache tests"


def test_mwc():
oprimer = Primer("ATCGATCGATCGATCGAT")
molecular_weight = oprimer.molecular_weight
assert round(oprimer.molecular_weight, 1) == round(molecular_weight, 1)


def test_gc_content():
oprimer = Primer("ATTCG")
gc_content = oprimer.gc_content
assert oprimer.gc_content == gc_content


def test_gc_clamp():
oprimer = Primer("ATCGATCGATCGATCGGTCG")
gc_clamp = oprimer.gc_clamp
assert oprimer.gc_clamp == gc_clamp


def test_melt_temp():
oprimer = Primer("ATCGATCGATCGATCGATCG")
basic_melt_temp = oprimer.melting_temperature(MeltingTemperature.BASIC)
assert round(oprimer.melting_temperature(MeltingTemperature.BASIC), 1) == round(basic_melt_temp, 1)


def test_single_runs():
oprimer = Primer("AAAAATTCGGGGATCCCCG")
runs = oprimer.single_runs
assert oprimer.single_runs['A'] == runs['A'] and oprimer.single_runs['T'] == runs[
'T'] and oprimer.single_runs['C'] == runs['C'] and oprimer.single_runs['G'] == runs['G']
41 changes: 26 additions & 15 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
from opr import Primer
from opr.primer import MeltingTemperature
from opr import Primer, MeltingTemperature

TEST_CASE_NAME = "Calculations tests"


def test_mwc():
oprimer = Primer("ATCGATCGATCGATCGAT")
assert round(oprimer.molecular_weight, 1) == 5498.7

def test_gc_content_1(): #Reference: https://jamiemcgowan.ie/bioinf/gc_content.html

def test_gc_content_1(): # Reference: https://jamiemcgowan.ie/bioinf/gc_content.html
oprimer = Primer("ATCG")
assert oprimer.gc_content == 0.5

def test_gc_content_2(): #Reference: https://jamiemcgowan.ie/bioinf/gc_content.html

def test_gc_content_2(): # Reference: https://jamiemcgowan.ie/bioinf/gc_content.html
oprimer = Primer("ATTCG")
assert oprimer.gc_content == 0.4

def test_gc_content_3(): #Reference: https://jamiemcgowan.ie/bioinf/gc_content.html

def test_gc_content_3(): # Reference: https://jamiemcgowan.ie/bioinf/gc_content.html
oprimer = Primer("ATTTTTT")
assert oprimer.gc_content == 0

def test_gc_clamp_1(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html

def test_gc_clamp_1(): # Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ATCGATCGATCGATCGGTCG")
assert oprimer.gc_clamp == 4

def test_gc_clamp_2(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html

def test_gc_clamp_2(): # Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ATCG")
assert oprimer.gc_clamp == 0

def test_gc_clamp_3(): #Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html

def test_gc_clamp_3(): # Reference: https://www.bioinformatics.org/sms2/pcr_primer_stats.html
oprimer = Primer("ACTTA")
assert oprimer.gc_clamp == 1

def test_melt_temp_1(): #Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html

def test_melt_temp_1(): # Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
oprimer = Primer("ATCGATCGATCGATCGATCG")
basic_melt_temp = oprimer.melting_temperature(MeltingTemperature.BASIC)
assert round(basic_melt_temp,1) == 51.8
assert round(basic_melt_temp, 1) == 51.8


def test_melt_temp_2(): #Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
def test_melt_temp_2(): # Reference: http://biotools.nubic.northwestern.edu/OligoCalc.html
oprimer = Primer("ATCG")
basic_melt_temp = oprimer.melting_temperature(method=MeltingTemperature.BASIC)
assert round(basic_melt_temp,1) == 12
assert round(basic_melt_temp, 1) == 12

def test_single_runs_1(): #Reference: https://www.oligoevaluator.com/OligoCalcServlet

def test_single_runs_1(): # Reference: https://www.oligoevaluator.com/OligoCalcServlet
oprimer = Primer("ATCGATCG")
runs = oprimer.single_runs
assert runs['A'] == 0 and runs['T'] == 0 and runs['C'] == 0 and runs['G'] == 0

def test_single_runs_2(): #Reference: https://www.oligoevaluator.com/OligoCalcServlet

def test_single_runs_2(): # Reference: https://www.oligoevaluator.com/OligoCalcServlet
oprimer = Primer("ATTCGATCCCCG")
runs = oprimer.single_runs
assert runs['A'] == 0 and runs['T'] == 2 and runs['C'] == 4 and runs['G'] == 0

def test_single_runs_3(): #Reference: https://www.oligoevaluator.com/OligoCalcServlet

def test_single_runs_3(): # Reference: https://www.oligoevaluator.com/OligoCalcServlet
oprimer = Primer("AAAAATTCGGGGATCCCCG")
runs = oprimer.single_runs
assert runs['A'] == 5 and runs['T'] == 2 and runs['C'] == 4 and runs['G'] == 4
32 changes: 32 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
from opr import Primer, MeltingTemperature, OPRBaseError

TEST_CASE_NAME = "Errors tests"


def test_addition():
oprimer = Primer("ATCGATCGATCGATCGAT")
with pytest.raises(OPRBaseError, match=r"You can only add two Primer objects."):
oprimer + 2


def test_multiply():
oprimer = Primer("ATCGATCGATCGATCGAT")
with pytest.raises(OPRBaseError, match=r"The primer sequence can only be multiplied by an integer."):
oprimer * "2"


def test_validate_primer_1():
with pytest.raises(OPRBaseError, match=r"Primer sequence should be a string variable."):
oprimer = Primer(222)


def test_validate_primer_2():
with pytest.raises(OPRBaseError, match=r"Primer sequence should only contain the nucleotide bases A, T, C, and G."):
oprimer = Primer("ATCGATCGATCGATCGAF")


def test_melting_temperature():
oprimer = Primer("ATCGATCGATCGATCGAT")
with pytest.raises(NotImplementedError, match=r"This method for calculating melting temperature has not been implemented."):
oprimer.melting_temperature(method=MeltingTemperature.NEAREST_NEIGHBOR)
26 changes: 18 additions & 8 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,76 @@
from opr import Primer

TEST_CASE_NAME = "operations testcase"
TEST_CASE_NAME = "Operations tests"

def test_reverse_1(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter

def test_reverse_1(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGATCGATCGATCGAT")
oprimer_reversed = oprimer.reverse(inplace=False)
assert oprimer_reversed.sequence == "TAGCTAGCTAGCTAGCTA"

def test_reverse_2(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter

def test_reverse_2(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGATCGATCGATCGAT")
oprimer_reversed = oprimer.reverse()
assert oprimer_reversed.sequence == "TAGCTAGCTAGCTAGCTA"

def test_reverse_3(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter

def test_reverse_3(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGATCGATCGATCGAT")
oprimer.reverse(inplace=True)
assert oprimer.sequence == "TAGCTAGCTAGCTAGCTA"


def test_complement_1(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
def test_complement_1(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGGCTAAATCGGCTAA")
oprimer_complemented = oprimer.complement(inplace=False)
assert oprimer_complemented.sequence == "TAGCCGATTTAGCCGATT"

def test_complement_2(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter

def test_complement_2(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGGCTAAATCGGCTAA")
oprimer_complemented = oprimer.complement()
assert oprimer_complemented.sequence == "TAGCCGATTTAGCCGATT"

def test_complement_3(): #Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter

def test_complement_3(): # Reference: https://www.qiagen.com/us/applications/enzymes/tools-and-calculators/reverse-complement-converter
oprimer = Primer("ATCGGCTAAATCGGCTAA")
oprimer.complement(inplace=True)
assert oprimer.sequence == "TAGCCGATTTAGCCGATT"


def test_length():
oprimer = Primer("ATCGGCTAAATCGGCTAA")
assert len(oprimer) == 18


def test_addition():
oprimer_1 = Primer("ATCG")
oprimer_2 = Primer("GATC")
oprimer_concat = oprimer_1 + oprimer_2
assert oprimer_concat.sequence == "ATCGGATC"


def test_multiply():
oprimer_1 = Primer("ATCG")
oprimer_concat = oprimer_1 * 4
assert oprimer_concat.sequence == "ATCGATCGATCGATCG"


def test_equality1():
oprimer_1 = Primer("ATCG")
oprimer_2 = Primer("ATCG")
assert oprimer_1 == oprimer_2


def test_equality2():
oprimer_1 = Primer("ATCG")
oprimer_2 = Primer("ATCGC")
assert oprimer_1 != oprimer_2


def test_str():
oprimer_1 = Primer("ATCG")
oprimer_2 = Primer("ATCGC")
oprimer_concat = oprimer_1 + oprimer_2
assert str(oprimer_1) + str(oprimer_2) == oprimer_concat.sequence