Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from pathlib import Path
3import pytest
4# from py.xml import html
6from .bio import Alignment, Data, Sequence, Tree
7from .main import main as main
10def pytest_addoption(parser):
11 parser.addoption("--sequence", "-S", action="store", default=None, help="sequence file")
12 parser.addoption("--sequence-format", action="store", default='fasta', help="sequence file format")
13 parser.addoption("--tree", "-T", action="store", default=None, help="tree file")
14 parser.addoption("--tree-format", action="store", default='newick', help="tree file format")
15 parser.addoption("--data", "-D", action="store", default=None, help="data file")
16 parser.addoption("--data-format", action="store", default='csv', help="data file format")
17 parser.addoption(
18 "--apply-fixes", action="store_true", default=None, help="automatically apply fixes where possible"
19 )
22def pytest_generate_tests(metafunc):
23 sequence_path = metafunc.config.getoption("sequence")
24 if 'alignment' in metafunc.fixturenames:
25 if sequence_path is None:
26 raise ValueError(f"{metafunc.function.__name__} requires an alignment file")
27 fpth = Path(sequence_path)
28 if not fpth.exists():
29 raise FileNotFoundError(f"Unable to locate requested alignment file ({fpth})! 😱")
30 tree_path = metafunc.config.getoption("tree")
31 if 'tree' in metafunc.fixturenames:
32 if tree_path is None:
33 raise ValueError(f"{metafunc.function.__name__} requires a tree file")
34 fpth = Path(tree_path)
35 if not fpth.exists():
36 raise FileNotFoundError(f"Unable to locate requested tree file ({fpth})! 😱")
37 tree_format = metafunc.config.getoption("--tree-format")
38 trees = Tree.parse(tree_path, tree_format)
39 metafunc.parametrize("tree", trees, ids=lambda t: t.name)
40 data_path = metafunc.config.getoption("data")
41 if 'data' in metafunc.fixturenames:
42 if data_path is None:
43 raise ValueError(f"{metafunc.function.__name__} requires a data file")
44 fpth = Path(data_path)
45 if not fpth.exists():
46 raise FileNotFoundError(f"Unable to locate requested data file ({fpth})! 😱")
47 if "sequence" in metafunc.fixturenames:
48 if sequence_path is None:
49 raise ValueError(f"{metafunc.function.__name__} requires a sequence file")
50 fpth = Path(sequence_path)
51 if not fpth.exists():
52 raise FileNotFoundError(f"Unable to locate requested sequence file ({fpth})! 😱")
53 alignment_format = metafunc.config.getoption("--sequence-format")
54 sequences = Sequence.parse(sequence_path, alignment_format)
55 metafunc.parametrize("sequence", sequences, ids=lambda s: s.id)
58@pytest.fixture(scope="session", name="alignment")
59def _alignment_fixture(request):
60 alignment_path = request.config.getoption("sequence")
61 alignment_format = request.config.getoption("--sequence-format")
62 alignment = Alignment.read(alignment_path, alignment_format)
63 return alignment
66@pytest.fixture(scope="session", name="data")
67def _data_fixture(request):
68 data_path = request.config.getoption("data")
69 data_format = request.config.getoption("--data-format")
70 data = Data.read(data_path, data_format)
71 return data
74def pytest_html_report_title(report):
75 report.title = "report"