diff --git a/tests/test_cli_priming_prob.py b/tests/test_cli_priming_prob.py new file mode 100644 index 0000000000000000000000000000000000000000..76e561aef396dce7dd130c443bbbd3cfa237ef2e --- /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 0000000000000000000000000000000000000000..ad351ad2d9c40d3e74b3c5a2059ee61ad134dd01 --- /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