Skip to content

Commit

Permalink
Adds commit hash and date to baseline files
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonb5 committed Oct 31, 2023
1 parent f71bec9 commit f7868d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CIME/baselines/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import gzip
import logging
from CIME.config import Config
from CIME.utils import expect
from CIME.utils import expect, get_src_root, get_current_commit, get_timestamp

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -238,7 +238,12 @@ def write_baseline_file(baseline_file, value):
value : str
Value to write.
"""
commit_hash = get_current_commit(repo=get_src_root())

timestamp = get_timestamp(timestamp_format="%Y-%m-%d_%H:%M:%S")

with open(baseline_file, "w") as fd:
fd.write(f"# sha:{commit_hash} date: {timestamp}\n")
fd.write(value)


Expand Down
11 changes: 7 additions & 4 deletions CIME/tests/test_unit_system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import tempfile
import gzip
import re
from re import A
import unittest
from unittest import mock
Expand Down Expand Up @@ -508,14 +509,16 @@ def test_generate_baseline(self):
with open(baseline_dir / "cpl-tput.log") as fd:
lines = fd.readlines()

assert len(lines) == 1
assert lines[0] == "719.635"
assert len(lines) == 2
assert re.match("# sha:.* date:.*", lines[0])
assert lines[1] == "719.635"

with open(baseline_dir / "cpl-mem.log") as fd:
lines = fd.readlines()

assert len(lines) == 1
assert lines[0] == "1673.89"
assert len(lines) == 2
assert re.match("# sha:.* date:.*", lines[0])
assert lines[1] == "1673.89"

def test_kwargs(self):
case = mock.MagicMock()
Expand Down

0 comments on commit f7868d3

Please sign in to comment.