Skip to content
Snippets Groups Projects
Commit 8c2b856e authored by Melvin Alappat's avatar Melvin Alappat
Browse files

added: tests for priming_prob.py and CLI

parent 56a52990
Branches
No related tags found
1 merge request!16Issue_4
Pipeline #13862 failed
"""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()
"""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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment