From f79fe5612a1626cf15a38d7ad02a639308298df3 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Thu, 23 May 2024 22:29:16 -0500 Subject: [PATCH] Adjustments to test with python 3.12 --- .github/workflows/build-and-test.yaml | 2 +- tests/unit/test_sysctl.py | 23 +++++++++++++++-------- tox.ini | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index ebdf9dc2..80ca4556 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - python-version: ["3.8", "3.10"] + python-version: ["3.8", "3.10", "3.12"] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/tests/unit/test_sysctl.py b/tests/unit/test_sysctl.py index 471ce504..59cf188e 100644 --- a/tests/unit/test_sysctl.py +++ b/tests/unit/test_sysctl.py @@ -208,8 +208,9 @@ def test_create_snapshot(self, mock_load, mock_output): config._desired_config = {"vm.swappiness": "0", "other_value": "10"} snapshot = config._create_snapshot() - assert mock_output.called_with(["sysctl", "vm.swappiness", "-n"]) - assert mock_output.called_with(["sysctl", "other_value", "-n"]) + mock_output.assert_called_once_with( + ["sysctl", "-n", "vm.swappiness", "other_value"], stderr=-2, universal_newlines=True + ) assert snapshot == {"vm.swappiness": "1", "other_value": "5"} @patch("charms.operator_libs_linux.v0.sysctl.check_output") @@ -222,7 +223,9 @@ def test_restore_snapshot(self, mock_load, mock_output): snapshot = {"vm.swappiness": "1", "other_value": "5"} config._restore_snapshot(snapshot) - assert mock_output.called_with(["sysctl", "vm.swappiness=1", "other_value=5"]) + mock_output.assert_called_once_with( + ["sysctl", "vm.swappiness=1", "other_value=5"], stderr=-2, universal_newlines=True + ) @patch("charms.operator_libs_linux.v0.sysctl.check_output") @patch("charms.operator_libs_linux.v0.sysctl.Config._load_data") @@ -233,7 +236,9 @@ def test_syctl(self, mock_load, mock_output): result = config._sysctl(["-n", "vm.swappiness"]) - assert mock_output.called_with(["sysctl", "-n", "vm.swappiness"]) + mock_output.assert_called_once_with( + ["sysctl", "-n", "vm.swappiness"], stderr=-2, universal_newlines=True + ) assert result == ["1"] @patch("charms.operator_libs_linux.v0.sysctl.check_output") @@ -246,7 +251,9 @@ def test_syctl_error(self, mock_load, mock_output): with self.assertRaises(sysctl.CommandError) as e: config._sysctl(["exception"]) - assert mock_output.called_with(["sysctl", "exception"]) + mock_output.assert_called_once_with( + ["sysctl", "exception"], stderr=-2, universal_newlines=True + ) assert e.exception.message == "Error executing '['sysctl', 'exception']': error on command" @patch("charms.operator_libs_linux.v0.sysctl.Config._sysctl") @@ -259,7 +266,7 @@ def test_apply_without_failed_values(self, mock_load, mock_sysctl): config._desired_config = {"vm.swappiness": "0"} config._apply() - assert mock_sysctl.called_with(["vm.swappiness=0"]) + mock_sysctl.assert_called_with(["vm.swappiness=0"]) @patch("charms.operator_libs_linux.v0.sysctl.Config._sysctl") @patch("charms.operator_libs_linux.v0.sysctl.Config._load_data") @@ -272,7 +279,7 @@ def test_apply_with_failed_values(self, mock_load, mock_sysctl): with self.assertRaises(sysctl.ApplyError) as e: config._apply() - assert mock_sysctl.called_with(["vm.swappiness=0"]) + mock_sysctl.assert_called_with(["vm.swappiness=0"]) self.assertEqual(e.exception.message, "Unable to set params: ['vm.swappiness']") @patch("charms.operator_libs_linux.v0.sysctl.Config._sysctl") @@ -286,7 +293,7 @@ def test_apply_with_partial_failed_values(self, mock_load, mock_sysctl): with self.assertRaises(sysctl.ApplyError) as e: config._apply() - assert mock_sysctl.called_with(["vm.swappiness=0", "net.ipv4.tcp_max_syn_backlog=4096"]) + mock_sysctl.assert_called_with(["vm.swappiness=0", "net.ipv4.tcp_max_syn_backlog=4096"]) self.assertEqual(e.exception.message, "Unable to set params: ['vm.swappiness']") @patch("charms.operator_libs_linux.v0.sysctl.Config._load_data") diff --git a/tox.ini b/tox.ini index b87321b5..9d33c65b 100644 --- a/tox.ini +++ b/tox.ini @@ -52,7 +52,7 @@ deps = pytest coverage[toml] -r{toxinidir}/requirements.txt - pyfakefs==4.4.0 + pyfakefs==5.5.0 dbus-fast==1.90.2 commands = coverage run --source={[vars]lib_dir} \