tests.test_scans

 1import os
 2from csi_images import csi_scans
 3
 4
 5def test_from_yaml():
 6    # Should be able to read and autopopulate scan.yaml component
 7    scan = csi_scans.Scan.load_yaml("tests/data")
 8    scan2 = csi_scans.Scan.load_yaml("tests/data/scan.yaml")
 9    assert scan == scan2
10
11    # Write, read, then delete the scan.yaml
12    scan.save_yaml("tests/data/temp.yaml")
13    scan3 = csi_scans.Scan.load_yaml("tests/data/temp.yaml")
14    assert scan == scan3
15    os.remove("tests/data/temp.yaml")
16
17
18def test_from_txt():
19    # Should be able to read and autopopulate scan.txt component
20    scan = csi_scans.Scan.load_txt("tests/data")
21    scan2 = csi_scans.Scan.load_txt("tests/data/slideinfo.txt")
22    assert scan == scan2
23
24
25def test_names_and_indices():
26    # Should be able to get the correct indices for the channels
27    scan = csi_scans.Scan.load_txt("tests/data")
28    correct_channel_order = ["DAPI", "TRITC", "CY5", "FITC"]
29    assert scan.get_channel_indices(correct_channel_order) == [0, 1, 2, 3]
30
31    # Should return -1 for None
32    assert scan.get_channel_indices([None]) == [-1]
33
34    # Should raise an error if the channel is not found
35    try:
36        scan.get_channel_indices(["DAPI", "TRITC", "CY5", "FITC", "INVALID"])
37        assert False
38    except ValueError:
39        assert True
def test_from_yaml():
 6def test_from_yaml():
 7    # Should be able to read and autopopulate scan.yaml component
 8    scan = csi_scans.Scan.load_yaml("tests/data")
 9    scan2 = csi_scans.Scan.load_yaml("tests/data/scan.yaml")
10    assert scan == scan2
11
12    # Write, read, then delete the scan.yaml
13    scan.save_yaml("tests/data/temp.yaml")
14    scan3 = csi_scans.Scan.load_yaml("tests/data/temp.yaml")
15    assert scan == scan3
16    os.remove("tests/data/temp.yaml")
def test_from_txt():
19def test_from_txt():
20    # Should be able to read and autopopulate scan.txt component
21    scan = csi_scans.Scan.load_txt("tests/data")
22    scan2 = csi_scans.Scan.load_txt("tests/data/slideinfo.txt")
23    assert scan == scan2
def test_names_and_indices():
26def test_names_and_indices():
27    # Should be able to get the correct indices for the channels
28    scan = csi_scans.Scan.load_txt("tests/data")
29    correct_channel_order = ["DAPI", "TRITC", "CY5", "FITC"]
30    assert scan.get_channel_indices(correct_channel_order) == [0, 1, 2, 3]
31
32    # Should return -1 for None
33    assert scan.get_channel_indices([None]) == [-1]
34
35    # Should raise an error if the channel is not found
36    try:
37        scan.get_channel_indices(["DAPI", "TRITC", "CY5", "FITC", "INVALID"])
38        assert False
39    except ValueError:
40        assert True