From 86247a9f763949f802d32ff1f36beca6aa01292d Mon Sep 17 00:00:00 2001 From: John Stilley <1831479+john-science@users.noreply.github.com> Date: Fri, 24 May 2024 08:53:23 -0700 Subject: [PATCH] Adding the MacOS to CI (#1713) --- .github/workflows/mac_tests.yaml | 28 +++++++++++++++++++ armi/bookkeeping/report/reportingUtils.py | 29 +++++++++++++++++++- armi/bookkeeping/report/tests/test_report.py | 24 ++++++++++++++++ doc/release/0.3.rst | 1 + doc/user/inputs.rst | 2 +- 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/mac_tests.yaml diff --git a/.github/workflows/mac_tests.yaml b/.github/workflows/mac_tests.yaml new file mode 100644 index 000000000..77da1919c --- /dev/null +++ b/.github/workflows/mac_tests.yaml @@ -0,0 +1,28 @@ +name: ARMI MacOS Tests + +on: + push: + paths-ignore: + - 'doc/**' + pull_request: + paths-ignore: + - 'doc/**' + +jobs: + build: + + runs-on: macos-14 + + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + - name: Upgrade PIP + run: python -m pip install --upgrade pip + - name: Run Unit Tests on MacOS + run: | + brew install openmpi + pip install -e .[memprof,mpi,test] + pytest armi diff --git a/armi/bookkeeping/report/reportingUtils.py b/armi/bookkeeping/report/reportingUtils.py index b1a2291b6..c8526cdda 100644 --- a/armi/bookkeeping/report/reportingUtils.py +++ b/armi/bookkeeping/report/reportingUtils.py @@ -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.check_output(cmd, shell=True).decode("utf-8") + + def _getSystemInfoLinux(): """Get system information, assuming the system is Linux. @@ -369,10 +394,12 @@ 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 " - + "supports Linux and Windows." + + "supports Linux, Windows, and MacOS." ) return "" diff --git a/armi/bookkeeping/report/tests/test_report.py b/armi/bookkeeping/report/tests/test_report.py index 87298060e..9d70fce63 100644 --- a/armi/bookkeeping/report/tests/test_report.py +++ b/armi/bookkeeping/report/tests/test_report.py @@ -16,6 +16,7 @@ import logging import os import subprocess +import sys import unittest from unittest.mock import patch @@ -24,6 +25,7 @@ from armi.bookkeeping.report import data, reportInterface from armi.bookkeeping.report.reportingUtils import ( _getSystemInfoLinux, + _getSystemInfoMac, _getSystemInfoWindows, getNodeName, getSystemInfo, @@ -91,14 +93,36 @@ def test_getSystemInfoWindows(self, mockSubprocess): out = _getSystemInfoWindows() self.assertEqual(out, windowsResult) + @patch("subprocess.run") + def test_getSystemInfoMac(self, mockSubprocess): + """Test _getSystemInfoMac() on any operating system, by mocking the system call.""" + macResult = b"""System Software Overview: + + System Version: macOS 12.1 (21C52) + Kernel Version: Darwin 21.2.0 + ... + Hardware Overview: + Model Name: MacBook Pro + ...""" + + mockSubprocess.return_value = _MockReturnResult(macResult) + + out = _getSystemInfoMac() + self.assertEqual(out, macResult.decode("utf-8")) + def test_getSystemInfo(self): """Basic sanity check of getSystemInfo() running in the wild. This test should pass if it is run on Window or mainstream Linux distros. But we expect this to fail if the test is run on some other OS. """ + if "darwin" in sys.platform: + # too comlicated to test MacOS in this method + return + out = getSystemInfo() substrings = ["OS ", "Processor(s):"] + for sstr in substrings: self.assertIn(sstr, out) diff --git a/doc/release/0.3.rst b/doc/release/0.3.rst index 6ed9df78b..8c236a780 100644 --- a/doc/release/0.3.rst +++ b/doc/release/0.3.rst @@ -55,6 +55,7 @@ Bug Fixes Quality Work ------------ +#. Supporting MacOS in CI. (`PR#1713 `_) #. We now enforce a maximum line length of 120 characters, using ``ruff``. (`PR#1646 `_) #. Move ``.coveragerc`` file information into ``pyproject.toml``. (`PR#1692 `_) #. TBD diff --git a/doc/user/inputs.rst b/doc/user/inputs.rst index 3cc3916a6..fda2d0726 100644 --- a/doc/user/inputs.rst +++ b/doc/user/inputs.rst @@ -478,7 +478,7 @@ The ARMI data model is represented schematically below, and the blueprints are d Defines :py:class:`~armi.reactor.components.component.Component` inputs for a :py:class:`~armi.reactor.blocks.Block`. -:ref:`asssemblies `: +:ref:`assemblies `: Defines vertical stacks of blocks used to define the axial profile of an :py:class:`~armi.reactor.assemblies.Assembly`.