Skip to content

Commit

Permalink
Fixing test that was broke on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed May 20, 2024
1 parent a72a732 commit 3f97d2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
27 changes: 27 additions & 0 deletions armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ def _getSystemInfoWindows():
return subprocess.run(cmd, capture_output=True, text=True, shell=True).stdout


def _getSystemInfoMac():
"""Get system information, assuming the system is MacOS.
Returns
-------
str
Basic system information: OS name, OS version, basic processor information
Examples
--------
Example results:
System Software Overview:
System Version: macOS 12.1 (21C52)
Kernel Version: Darwin 21.2.0
...
Hardware Overview:
Model Name: MacBook Pro
...
"""
cmd = "system_profiler SPSoftwareDataType SPHardwareDataType"
return subprocess.run(cmd, capture_output=True, text=True, shell=True).stdout


def _getSystemInfoLinux():
"""Get system information, assuming the system is Linux.
Expand Down Expand Up @@ -369,6 +394,8 @@ def getSystemInfo():
return _getSystemInfoWindows()
elif "linux" in sys.platform:
return _getSystemInfoLinux()
elif "darwin" in sys.platform:
return _getSystemInfoMac()
else:
runLog.warning(
f"Cannot get system information for {sys.platform} because ARMI only "
Expand Down
8 changes: 7 additions & 1 deletion armi/bookkeeping/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import subprocess
import sys
import unittest
from unittest.mock import patch

Expand Down Expand Up @@ -98,7 +99,12 @@ def test_getSystemInfo(self):
to fail if the test is run on some other OS.
"""
out = getSystemInfo()
substrings = ["OS ", "Processor(s):"]

if "darwin" in sys.platform:
substrings = ["System Software", "Hardware Overview"]
else:
substrings = ["OS ", "Processor(s):"]

for sstr in substrings:
self.assertIn(sstr, out)

Expand Down

0 comments on commit 3f97d2f

Please sign in to comment.