test_RapidPeptidesGenerator.py 4.18 KB
Newer Older
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
1
2
3
4
5
6
7
8
9
10
11
""" Test for RapidPeptidesGenerator.py"""
import pytest
from .context import rpg
from rpg import RapidPeptidesGenerator

def test_restricted_float(capsys):
    """Test function 'restricted_float(mc_val)'"""
    # Error test
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        RapidPeptidesGenerator.restricted_float(-10)
    _, err = capsys.readouterr()
12
    assert err == "Value Error: miscleavage value should be between 0 and "\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
13
14
15
16
17
18
                  "100.\n"
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == 1
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        RapidPeptidesGenerator.restricted_float("z")
    _, err = capsys.readouterr()
19
    assert err == "Type Error: miscleavage value should be a float between"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
                  " 0 and 100.\n"
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == 1
    # Normal test
    assert RapidPeptidesGenerator.restricted_float(3) == 3.0

def test_restricted_enzyme_id(capsys):
    """Test function 'restricted_enzyme_id(enz_id)'"""
    # Error test
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        RapidPeptidesGenerator.restricted_enzyme_id(-10)
    _, err = capsys.readouterr()
    assert err == "Input Error: id -10 does not correspond to any enzyme. Use"\
                  " -l to get enzyme ids.\n"
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == 1
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        RapidPeptidesGenerator.restricted_enzyme_id("z")
    _, err = capsys.readouterr()
    assert err == "Type Error: Enzyme id should be an integer.\n"
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == 1
    # Normal test
    assert RapidPeptidesGenerator.restricted_enzyme_id(3) == 3

def test_list_enzyme(capsys):
    """Test function 'list_enzyme()'
    This test should be run with empty user file
    """
    RapidPeptidesGenerator.list_enzyme()
    out, _ = capsys.readouterr()
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
51
    assert out == "1: Arg-C\n2: Asp-N\n3: BNPS-Skatole\n4: Bromelain\n5: Casp"\
52
53
54
55
56
57
58
59
60
    "ase-1\n6: Caspase-2\n7: Caspase-3\n8: Caspase-4\n9: Caspase-5\n10: Caspa"\
    "se-6\n11: Caspase-7\n12: Caspase-8\n13: Caspase-9\n14: Caspase-10\n15: C"\
    "hymotrypsin-high\n16: Chymotrypsin-low\n17: Clostripain\n18: CNBr\n19: E"\
    "nterokinase\n20: Factor-Xa\n21: Ficin\n22: Formic-acid\n23: Glu-C\n24: G"\
    "lutamyl-endopeptidase\n25: Granzyme-B\n26: Hydroxylamine\n27: Iodosobenz"\
    "oic-acid\n28: Lys-C\n29: Lys-N\n30: Neutrophil-elastase\n31: NTCB\n32: P"\
    "apain\n33: Pepsin-pH1.3\n34: Pepsin-pH>=2\n35: Proline-endopeptidase\n36"\
    ": Proteinase-K\n37: Staphylococcal-peptidase-I\n38: Thermolysin\n39: Thr"\
    "ombin\n40: Thrombin-SG\n41: Tobacco-Etch-Virus\n42: Trypsin\n"
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
61
62

def test_create_enzymes_to_use(capsys):
63
    """Test function 'create_enzymes_to_use(enzymes, miscleavage)'"""
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
64
    enzymes = [23, 31, 29]
65
66
    miscleavage = [1.1, 20]
    res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
67
    assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.1"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
68
                           "0%\nRules: [index=0\nletter=D\ncut=True\npos=1\n,"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
69
                           " index=0\nletter=E\ncut=True\npos=1\n]\n, Id: 31"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
70
                           "\nName: NTCB\nRatio Miscleavage: 20.00%\nRules"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
71
                           ": [index=0\nletter=C\ncut=True\npos=0\n]\n, Id: "\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
72
                           "29\nName: Lys-N\nRatio Miscleavage: 0.00%\nRul"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
73
                           "es: [index=0\nletter=K\ncut=True\npos=0\n]\n]"
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
74
    enzymes = [23, 31]
75
76
    miscleavage = [1.1, 20, 40]
    res = RapidPeptidesGenerator.create_enzymes_to_use(enzymes, miscleavage)
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
77
    _, err = capsys.readouterr()
78
    assert err == "Warning: Too much miscleavage values. Last values will "\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
79
                  "be ignored.\n"
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
80
    assert res.__repr__() == "[Id: 23\nName: Glu-C\nRatio Miscleavage: 1.1"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
81
                           "0%\nRules: [index=0\nletter=D\ncut=True\npos=1\n,"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
82
                           " index=0\nletter=E\ncut=True\npos=1\n]\n, Id: 31"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
83
                           "\nName: NTCB\nRatio Miscleavage: 20.00%\nRules"\
Nicolas  MAILLET's avatar
Nicolas MAILLET committed
84
                           ": [index=0\nletter=C\ncut=True\npos=0\n]\n]"