From 8c2b856ead25b5423d104b94cc05c40265573590 Mon Sep 17 00:00:00 2001 From: Melvin Alappat <melvin.alappat@unibas.ch> Date: Mon, 20 Dec 2021 21:06:08 +0100 Subject: [PATCH] added: tests for priming_prob.py and CLI --- tests/test_cli_priming_prob.py | 39 ++++++++++++++++++++++++++++++++++ tests/test_priming_prob.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/test_cli_priming_prob.py create mode 100644 tests/test_priming_prob.py diff --git a/tests/test_cli_priming_prob.py b/tests/test_cli_priming_prob.py new file mode 100644 index 0000000..76e561a --- /dev/null +++ b/tests/test_cli_priming_prob.py @@ -0,0 +1,39 @@ +"""Unit tests for module ``CLI_PrimingProb.py``.""" +import pytest +from pathlib import Path +from src.primingprob import cli_priming_prob as CPb +from unittest.mock import patch, MagicMock + +PACKAGE_DIR = Path(__file__).resolve().parents[1] +TEST_FILE = "./tests/resources/Energies_test.txt" + + +class TestParseArgs: + """Test ``parse_args()`` function.""" + + def test_no_positional_args(self): + """Call without positional args.""" + with pytest.raises(SystemExit) as exc: + CPb.parse_args() + assert exc.value.code != 0 + + +class TestMain: + """Test ``main()`` function.""" + + def test_without_args(self): + """Call without args.""" + with pytest.raises(SystemExit) as exc: + CPb.main() + assert exc.value.code != 0 + + def test_last_line(self): + """Test name equals main.""" + # Arrange + with patch.object(CPb, "main", MagicMock()) as mock_main: + with patch.object(CPb, "__name__", "__main__"): + # Act + CPb.init() + + # Assert + mock_main.assert_called_once() diff --git a/tests/test_priming_prob.py b/tests/test_priming_prob.py new file mode 100644 index 0000000..ad351ad --- /dev/null +++ b/tests/test_priming_prob.py @@ -0,0 +1,35 @@ +"""Unit tests for module ``PrimingProb_CI``.""" +import os +from src.primingprob.priming_prob import Probability as Pbt + +Energy_file = "./tests/resources/Energies_test.txt" +Fasta_file = "./tests/resources/transcript.fasta" +Output_file = "./tests/resources/Potential_Priming_Sites.txt" + + +def test_inter_para(): + """Tests InterPara function.""" + testdata = Pbt.inter_para(Energy_file) + assert len(testdata) == 3 # Number of interactions + assert type(testdata) is list + for i in range(0, len(testdata)): + assert testdata[i][0].isdigit() + + return testdata + + +testdata2 = test_inter_para() + + +def test_inter_prob(): + """Tests InterProb function.""" + Pbt.inter_prob(testdata2, Fasta_file, Output_file) + assert os.path.exists(Output_file) is True # Check whether file exists + + mytestfile = open(Output_file, "r") # Test whether gff file start with transcript ID + for mylinecounter in mytestfile: + assert mylinecounter.startswith("NW_005196756.1:c68260-66684") + + with open(Output_file, "r") as tt: # Check whether number of interactions is right + x = len(tt.readlines()) + assert x == 3 -- GitLab