forked from nickdelgrosso/XCaliburMethodReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_reader.py
More file actions
69 lines (46 loc) · 2.12 KB
/
Copy pathtest_reader.py
File metadata and controls
69 lines (46 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pathlib import Path
from XCaliburMethodReader import main
from xcalibur_method_reader import XCaliburMethod, extract_gradients, plot_gradient
TEST_FILE = Path("data/test.meth")
def test_parser_accepts_file(capsys):
main((str(TEST_FILE),))
captured = capsys.readouterr()
assert "Proxeon" in captured.out
assert "Thermo Exactive" in captured.out
def test_stream_text_output(capsys):
main((str(TEST_FILE), "-s", "Thermo Exactive"))
captured = capsys.readouterr()
assert "Method" in captured.out
main((str(TEST_FILE), "-s", "Proxeon_EASY-nLC", "--to", "text"))
captured = capsys.readouterr()
assert "Sample" in captured.out
def test_stream_machine_readable_output(capsys):
main((str(TEST_FILE), "-s", "Thermo Exactive", "--to", "json"))
captured = capsys.readouterr()
assert captured.out[0] == "{"
assert captured.out.strip()[-1] == "}"
main((str(TEST_FILE), "-s", "Thermo Exactive", "--to", "xml"))
captured = capsys.readouterr()
assert captured.out[:5] == "<?xml"
assert captured.out.strip()[-1] == ">"
def test_reader_api_lists_and_reads_streams():
method = XCaliburMethod(TEST_FILE)
assert method.stream_names() == ["AuditData", "LCQ Header", "Proxeon_EASY-nLC", "Thermo Exactive"]
assert "InstrumentSetupMethod" in method.read_dict("Thermo Exactive")
assert method.readable_xml_streams() == ["Proxeon_EASY-nLC", "Thermo Exactive"]
def test_extract_gradients_from_easy_nlc_xml():
gradient = extract_gradients(TEST_FILE)
assert list(gradient["percent_b"]) == [5, 30, 60, 95, 95, 5, 5]
assert list(gradient["time_min"]) == [0, 95, 100, 105, 110, 115, 120]
assert set(gradient["pump"]) == {"LC"}
def test_cli_prints_gradients(capsys):
main((str(TEST_FILE), "--gradients"))
captured = capsys.readouterr()
assert "time_min,pump,percent_b" in captured.out
assert "95.0,LC,30" in captured.out
def test_plot_gradient_writes_png(tmp_path):
output = tmp_path / "gradient.png"
ax = plot_gradient(TEST_FILE, output=output)
assert output.exists()
assert output.stat().st_size > 0
assert ax.get_xlabel() == "Time [min]"