Skip to content

test_slurm_labelled_logs

Functions

empty_log

empty_log()
Source code in tests/test_slurm_labelled_logs.py
 8
 9
10
@pytest.fixture
def empty_log():
    return StringIO("")

mixed_log

mixed_log()
Source code in tests/test_slurm_labelled_logs.py
25
26
27
28
29
30
31
@pytest.fixture
def mixed_log():
    return StringIO("""16: libc.so.6          000014E08CBB15D0  Unknown               Unknown  Unknown
srun: Force Terminated StepId=1513744.0
Command exited with non-zero status 137
0.14user 0.40system 1:34.04elapsed 0%CPU (0avgtext+0avgdata 8320maxresident)k
""")

process_log

process_log()
Source code in tests/test_slurm_labelled_logs.py
13
14
15
16
17
18
19
20
21
22
@pytest.fixture
def process_log():
    return StringIO("""22:  USING DEFAULTS : area_radius1 =   3360.00000000000
26:  USING DEFAULTS : area_radius1 =   3360.00000000000   
26:            
 0:  USING DEFAULTS : area_radius1 =   3360.00000000000
 0:  GETIN area_radius1 =    3360.00000000000
12:  USING DEFAULTS : area_rotation_pre =  0.000000000000000E+000
12:  USING DEFAULTS : area_rotation =  0.000000000000000E+000
""")

test_empty_log

test_empty_log(empty_log)
Source code in tests/test_slurm_labelled_logs.py
34
35
def test_empty_log(empty_log):
    assert separate_labelled_log(empty_log) == {}

test_mixed_log

test_mixed_log(mixed_log)
Source code in tests/test_slurm_labelled_logs.py
106
107
108
109
110
111
112
113
114
115
116
def test_mixed_log(mixed_log):
    assert separate_labelled_log(mixed_log) == {
        16: [
            " libc.so.6          000014E08CBB15D0  Unknown               Unknown  Unknown"
        ],
        "slurm": [
            "srun: Force Terminated StepId=1513744.0",
            "Command exited with non-zero status 137",
            "0.14user 0.40system 1:34.04elapsed 0%CPU (0avgtext+0avgdata 8320maxresident)k",
        ],
    }

test_mixed_log_to_files

test_mixed_log_to_files(mixed_log, tmp_path)
Source code in tests/test_slurm_labelled_logs.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def test_mixed_log_to_files(mixed_log, tmp_path):
    separate_labelled_log_to_files(mixed_log, tmp_path, "mixed_{process_id}")

    output_16 = tmp_path / "mixed_16"
    output_slurm = tmp_path / "mixed_slurm"

    assert (
        output_16.read_text()
        == """ libc.so.6          000014E08CBB15D0  Unknown               Unknown  Unknown
"""
    )
    assert (
        output_slurm.read_text()
        == """srun: Force Terminated StepId=1513744.0
Command exited with non-zero status 137
0.14user 0.40system 1:34.04elapsed 0%CPU (0avgtext+0avgdata 8320maxresident)k
"""
    )

test_only_process_log

test_only_process_log(process_log)
Source code in tests/test_slurm_labelled_logs.py
38
39
40
41
42
43
44
45
46
47
48
49
50
def test_only_process_log(process_log):
    assert separate_labelled_log(process_log) == {
        0: [
            "  USING DEFAULTS : area_radius1 =   3360.00000000000",
            "  GETIN area_radius1 =    3360.00000000000",
        ],
        12: [
            "  USING DEFAULTS : area_rotation_pre =  0.000000000000000E+000",
            "  USING DEFAULTS : area_rotation =  0.000000000000000E+000",
        ],
        22: ["  USING DEFAULTS : area_radius1 =   3360.00000000000"],
        26: ["  USING DEFAULTS : area_radius1 =   3360.00000000000   ", "            "],
    }

test_only_process_log_to_files

test_only_process_log_to_files(process_log, tmp_path)
Source code in tests/test_slurm_labelled_logs.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def test_only_process_log_to_files(process_log, tmp_path):
    separate_labelled_log_to_files(process_log, tmp_path, "output_{process_id}.log")
    output_0 = tmp_path / "output_0.log"
    output_12 = tmp_path / "output_12.log"
    output_22 = tmp_path / "output_22.log"
    output_26 = tmp_path / "output_26.log"
    assert output_0.exists()
    assert output_12.exists()
    assert output_22.exists()
    assert output_26.exists()

    assert (
        output_0.read_text()
        == """  USING DEFAULTS : area_radius1 =   3360.00000000000
  GETIN area_radius1 =    3360.00000000000
"""
    )
    assert (
        output_12.read_text()
        == """  USING DEFAULTS : area_rotation_pre =  0.000000000000000E+000
  USING DEFAULTS : area_rotation =  0.000000000000000E+000
"""
    )
    assert (
        output_22.read_text()
        == """  USING DEFAULTS : area_radius1 =   3360.00000000000
"""
    )
    assert (
        output_26.read_text()
        == """  USING DEFAULTS : area_radius1 =   3360.00000000000   

"""
    )

test_only_process_log_to_files_remove_ws

test_only_process_log_to_files_remove_ws(
    process_log, tmp_path
)
Source code in tests/test_slurm_labelled_logs.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def test_only_process_log_to_files_remove_ws(process_log, tmp_path):
    separate_labelled_log_to_files(
        process_log,
        tmp_path,
        "output_{process_id}.log",
        remove_trailing_whitespaces=True,
    )
    output_26 = tmp_path / "output_26.log"
    assert output_26.exists()

    assert (
        output_26.read_text()
        == """  USING DEFAULTS : area_radius1 =   3360.00000000000
"""
    )