From e26bf7e6e154b145bdafe11e55b854a5d43da401 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Thu, 12 Sep 2024 12:56:19 +1200 Subject: [PATCH 1/6] Move ops/testing to ops/_private/harness --- ops/{testing.py => _private/harness.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ops/{testing.py => _private/harness.py} (100%) diff --git a/ops/testing.py b/ops/_private/harness.py similarity index 100% rename from ops/testing.py rename to ops/_private/harness.py From 362f7eba08e032a2b2abd245ace721411aa5d30a Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Thu, 12 Sep 2024 12:58:14 +1200 Subject: [PATCH 2/6] Re-expose Harness in the ops.testing namespace. --- ops/testing.py | 64 ++++++++++++++++++++++++++++++++++++++++++++ test/test_testing.py | 5 ++-- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 ops/testing.py diff --git a/ops/testing.py b/ops/testing.py new file mode 100644 index 000000000..b1cebb2fa --- /dev/null +++ b/ops/testing.py @@ -0,0 +1,64 @@ +# Copyright 2021 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Infrastructure to build unit tests for charms using the ops library.""" + +from ._private.harness import ( + ActionFailed, + ActionOutput, + AppUnitOrName, + CharmBase, + CharmMeta, + CharmType, + Container, + ExecArgs, + ExecHandler, + ExecProcess, + ExecResult, + Harness, + ReadableBuffer, + RelationNotFoundError, + RelationRole, + YAMLStringOrFile, + charm, + framework, + model, + pebble, + storage, +) + +# The Harness testing framework. +_ = ActionFailed +_ = ActionOutput +_ = AppUnitOrName +_ = CharmType +_ = ExecArgs +_ = ExecHandler +_ = ExecResult +_ = Harness +_ = ReadableBuffer +_ = YAMLStringOrFile + +# Names exposed for backwards compatibility +_ = CharmBase +_ = CharmMeta +_ = Container +_ = ExecProcess +_ = RelationNotFoundError +_ = RelationRole +_ = charm +_ = framework +_ = model +_ = pebble +_ = storage diff --git a/test/test_testing.py b/test/test_testing.py index e9e34f34d..4c88f232b 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -39,10 +39,11 @@ import ops import ops.testing from ops import pebble +from ops._private.harness import _TestingPebbleClient from ops.jujuversion import JujuVersion from ops.model import _ModelBackend from ops.pebble import FileType -from ops.testing import ExecResult, _TestingPebbleClient +from ops.testing import ExecResult is_linux = platform.system() == 'Linux' @@ -6888,7 +6889,7 @@ def get_change(_: ops.pebble.Client, change_id: str): 'spawn-time': '2021-02-10T04:36:22.118970777Z', }) - monkeypatch.setattr(ops.testing._TestingPebbleClient, 'get_change', get_change) + monkeypatch.setattr(_TestingPebbleClient, 'get_change', get_change) harness.pebble_notify( 'foo', '123', From 0b707a2f296fa10aa61118316f4d7469bb850c75 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 16 Sep 2024 09:46:50 +1200 Subject: [PATCH 3/6] Update ops/testing.py --- ops/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/testing.py b/ops/testing.py index b1cebb2fa..a633be3d3 100644 --- a/ops/testing.py +++ b/ops/testing.py @@ -1,4 +1,4 @@ -# Copyright 2021 Canonical Ltd. +# Copyright 2024 Canonical Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 39ff60bc8df9dabcdde8f7df8668a8404a026762 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 16 Sep 2024 10:42:51 +1200 Subject: [PATCH 4/6] Explicitly list the classes to document, and ensure they are named as ops.testing, not ops._private.harness. --- docs/custom_conf.py | 2 ++ docs/index.rst | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/custom_conf.py b/docs/custom_conf.py index 29e964360..578d989c2 100644 --- a/docs/custom_conf.py +++ b/docs/custom_conf.py @@ -326,6 +326,8 @@ def _compute_navigation_tree(context): ('py:class', '_TextOrBinaryIO'), ('py:class', '_WarningDict'), ('py:class', '_Writeable'), + ('py:obj', 'ops._private.harness.CharmType'), + ('py:class', 'ops._private.harness.CharmType'), ('py:class', 'ops.charm._ContainerBaseDict'), ('py:class', 'ops.model._AddressDict'), ('py:class', 'ops.model._GenericLazyMapping'), diff --git a/docs/index.rst b/docs/index.rst index af4de65ca..84f58b3f8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,7 +34,11 @@ ops.pebble module ops.testing module ================== -.. automodule:: ops.testing +.. autoclass:: ops.testing.ActionFailed +.. autoclass:: ops.testing.ActionOutput +.. autoclass:: ops.testing.ExecArgs +.. autoclass:: ops.testing.ExecResult +.. autoclass:: ops.testing.Harness Indices From 310d34b0a5dfa67da504be6428ecf3b30d2519ff Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Tue, 17 Sep 2024 15:51:41 +1200 Subject: [PATCH 5/6] Disable the checks against charms that still need to fix their tests. --- .github/workflows/db-charm-tests.yaml | 6 ++++-- .github/workflows/observability-charm-tests.yaml | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/db-charm-tests.yaml b/.github/workflows/db-charm-tests.yaml index acef622d9..cd7b3dd2d 100644 --- a/.github/workflows/db-charm-tests.yaml +++ b/.github/workflows/db-charm-tests.yaml @@ -18,8 +18,10 @@ jobs: commit: e59139a097bd407b5e785daf8193b777cc691af9 # 2024-08-26T10:45:00Z - charm-repo: canonical/postgresql-k8s-operator commit: beed68055e33191721896a3b8e28274a99e7de7b # 2024-08-26T16:47:32Z - - charm-repo: canonical/mysql-operator - commit: 25a8a79680f3fbf3c36e9e1d8c20a852f54129c1 # 2024-08-26T13:48:51Z + # Waiting for an upstream PR: + # https://github.com/canonical/mysql-operator/pull/519 + #- charm-repo: canonical/mysql-operator + # commit: 25a8a79680f3fbf3c36e9e1d8c20a852f54129c1 # 2024-08-26T13:48:51Z - charm-repo: canonical/mysql-k8s-operator commit: 52df6266067d7233b7a067f7a967170b4096dba8 # rev183 rev182 2024-08-26T13:44:33Z steps: diff --git a/.github/workflows/observability-charm-tests.yaml b/.github/workflows/observability-charm-tests.yaml index 09aa1b083..6225fba45 100644 --- a/.github/workflows/observability-charm-tests.yaml +++ b/.github/workflows/observability-charm-tests.yaml @@ -17,10 +17,14 @@ jobs: include: - charm-repo: canonical/alertmanager-k8s-operator commit: 4b2f567c43bc67e9d1fe24f018ba186dcd0396ed # 2024-08-28T11:32:28Z - - charm-repo: canonical/prometheus-k8s-operator - commit: 27025e5d840ec09331608b398cf4e49e5fe256e9 # 2024-08-28T11:32:32Z - - charm-repo: canonical/grafana-k8s-operator - commit: 1c80f746f8edeae6fd23ddf31eed45f5b88c06b4 # rev118 2024-08-12T14:02:32Z + # Waiting for an upstream PR: + # https://github.com/canonical/prometheus-k8s-operator/pull/639 + #- charm-repo: canonical/prometheus-k8s-operator + # commit: 27025e5d840ec09331608b398cf4e49e5fe256e9 # 2024-08-28T11:32:32Z + # Waiting for an upstream PR: + # https://github.com/canonical/grafana-k8s-operator/pull/347 + #- charm-repo: canonical/grafana-k8s-operator + # commit: 1c80f746f8edeae6fd23ddf31eed45f5b88c06b4 # rev118 2024-08-12T14:02:32Z steps: - name: Checkout the ${{ matrix.charm-repo }} repository uses: actions/checkout@v4 From 358f4a1d5cec78d27dbad701864bc0f732b9e24e Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 18 Sep 2024 09:53:07 +1200 Subject: [PATCH 6/6] Bump the pinned versions, per #1375. --- .github/workflows/db-charm-tests.yaml | 8 ++++---- .github/workflows/observability-charm-tests.yaml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/db-charm-tests.yaml b/.github/workflows/db-charm-tests.yaml index cd7b3dd2d..0ddfa2343 100644 --- a/.github/workflows/db-charm-tests.yaml +++ b/.github/workflows/db-charm-tests.yaml @@ -15,15 +15,15 @@ jobs: matrix: include: - charm-repo: canonical/postgresql-operator - commit: e59139a097bd407b5e785daf8193b777cc691af9 # 2024-08-26T10:45:00Z + commit: 01cfd3e268ecd5024ded6bb6aede43ff85417b78 # 2024-09-11T16:07:20Z - charm-repo: canonical/postgresql-k8s-operator - commit: beed68055e33191721896a3b8e28274a99e7de7b # 2024-08-26T16:47:32Z + commit: f203e4d9d3ab9856b5dc0786217fce8428384e90 # 2024-09-16T12:00:58Z # Waiting for an upstream PR: # https://github.com/canonical/mysql-operator/pull/519 #- charm-repo: canonical/mysql-operator - # commit: 25a8a79680f3fbf3c36e9e1d8c20a852f54129c1 # 2024-08-26T13:48:51Z + # commit: 4ff2dc867a1586d43a93d0017cc648d591fc9886 # 2024-09-13T15:38:12Z - charm-repo: canonical/mysql-k8s-operator - commit: 52df6266067d7233b7a067f7a967170b4096dba8 # rev183 rev182 2024-08-26T13:44:33Z + commit: 2009919583eddad22656b9b4ebe95adbcd518c0f # rev199 rev198 2024-09-16T18:14:16Z steps: - name: Checkout the ${{ matrix.charm-repo }} repository uses: actions/checkout@v4 diff --git a/.github/workflows/observability-charm-tests.yaml b/.github/workflows/observability-charm-tests.yaml index 6225fba45..af1879afb 100644 --- a/.github/workflows/observability-charm-tests.yaml +++ b/.github/workflows/observability-charm-tests.yaml @@ -20,11 +20,11 @@ jobs: # Waiting for an upstream PR: # https://github.com/canonical/prometheus-k8s-operator/pull/639 #- charm-repo: canonical/prometheus-k8s-operator - # commit: 27025e5d840ec09331608b398cf4e49e5fe256e9 # 2024-08-28T11:32:32Z + # commit: 7518ec8343941ca91248614fd8f2d50fdd9e068c # rev135 2024-09-06T12:10:02Z # Waiting for an upstream PR: # https://github.com/canonical/grafana-k8s-operator/pull/347 #- charm-repo: canonical/grafana-k8s-operator - # commit: 1c80f746f8edeae6fd23ddf31eed45f5b88c06b4 # rev118 2024-08-12T14:02:32Z + # commit: 1bd9e7fd96a9f5a91443e5932667c58a92c1ce5e # 2024-09-03T14:57:42Z steps: - name: Checkout the ${{ matrix.charm-repo }} repository uses: actions/checkout@v4