Skip to content

Commit 9ab0d49

Browse files
author
Shane Snyder
committed
updated pytests for job_stats/file_stats
1 parent 60a4724 commit 9ab0d49

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

darshan-util/pydarshan/darshan/tests/test_file_stats.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
from unittest import mock
33
from darshan.log_utils import get_log_path
44
from darshan.cli import file_stats
5+
import pandas as pd
6+
import io
57
import pytest
8+
69
@pytest.mark.parametrize(
710
"argv", [
8-
[get_log_path("e3sm_io_heatmap_only.darshan"),
9-
"-mSTDIO",
10-
"-oSTDIO_BYTES_READ",
11-
"-n5"],
11+
[get_log_path("shane_macsio_id29959_5-22-32552-7035573431850780836_1590156158.darshan"),
12+
"--csv",
13+
"--module=POSIX",
14+
"--order_by=bytes_written",
15+
"--limit=5"],
1216
]
1317
)
1418
def test_file_stats(argv, capsys):
@@ -19,7 +23,38 @@ def test_file_stats(argv, capsys):
1923
file_stats.setup_parser(parser=parser)
2024
# parse the input arguments
2125
args = parser.parse_args(argv)
26+
# run once with CSV output and spot check some of the output
2227
file_stats.main(args=args)
2328
captured = capsys.readouterr()
24-
assert "15920181672442173319" in captured.out
25-
29+
assert not captured.err
30+
assert captured.out
31+
df = pd.read_csv(io.StringIO(captured.out))
32+
assert len(df) == 3
33+
# check the first file (most bytes written)
34+
expected_first = {
35+
'file': '/tmp/test/macsio_hdf5_000.h5',
36+
'bytes_read': 39816960,
37+
'bytes_written': 54579416,
38+
'reads': 6,
39+
'writes': 7699,
40+
'total_jobs': 1
41+
}
42+
row = df.iloc[0]
43+
for key, value in expected_first.items():
44+
assert row[key] == value
45+
# check the last file (least bytes written)
46+
expected_last = {
47+
'file': '/tmp/test/macsio-timings.log',
48+
'bytes_read': 0,
49+
'bytes_written': 12460,
50+
'reads': 0,
51+
'writes': 51,
52+
'total_jobs': 1
53+
}
54+
row = df.iloc[-1]
55+
for key, value in expected_last.items():
56+
assert row[key] == value
57+
assert expected_first['bytes_written'] > expected_last['bytes_written']
58+
# run again to ensure default Rich print mode runs successfully
59+
args.csv = False
60+
file_stats.main(args=args)

darshan-util/pydarshan/darshan/tests/test_job_stats.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
from unittest import mock
33
from darshan.log_utils import get_log_path
44
from darshan.cli import job_stats
5+
from numpy.testing import assert_allclose
6+
import pandas as pd
7+
import io
58
import pytest
9+
610
@pytest.mark.parametrize(
711
"argv", [
8-
[get_log_path("e3sm_io_heatmap_only.darshan"),
9-
"-mSTDIO",
10-
"-ototal_bytes",
11-
"-n5"],
12+
[get_log_path("sample-badost.darshan"),
13+
"--csv",
14+
"--module=STDIO",
15+
"--order_by=total_bytes",
16+
"--limit=5"],
1217
]
1318
)
1419
def test_job_stats(argv, capsys):
@@ -19,6 +24,30 @@ def test_job_stats(argv, capsys):
1924
job_stats.setup_parser(parser=parser)
2025
# parse the input arguments
2126
args = parser.parse_args(argv)
27+
# run once with CSV output and spot check some of the output
2228
job_stats.main(args=args)
2329
captured = capsys.readouterr()
24-
assert "3.258853" in captured.out
30+
assert not captured.err
31+
assert captured.out
32+
df = pd.read_csv(io.StringIO(captured.out))
33+
assert len(df) == 1
34+
expected = {
35+
'log_file': 'sample-badost.darshan',
36+
'job_id': 6265799,
37+
'nprocs': 2048,
38+
'run_time': 780.0,
39+
'perf_by_slowest': 8.249708e+06,
40+
'time_by_slowest': 0.200828,
41+
'total_bytes': 1656773,
42+
'total_files': 3,
43+
'partial_flag': False
44+
}
45+
row = df.iloc[0]
46+
for key, value in expected.items():
47+
if key == 'perf_by_slowest' or key == 'time_by_slowest':
48+
assert_allclose(row[key], value, rtol=1e-5, atol=1e-8)
49+
else:
50+
assert row[key] == value
51+
# run again to ensure default Rich print mode runs successfully
52+
args.csv = False
53+
job_stats.main(args=args)

0 commit comments

Comments
 (0)