Skip to content

Commit

Permalink
test: refactor test_main.py and test_storage.py (#1199)
Browse files Browse the repository at this point in the history
Refactor test_storage.py and test_main.py to pytest style.
  • Loading branch information
IronCore864 authored May 16, 2024
1 parent f1ff257 commit 6557b10
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 292 deletions.
1 change: 1 addition & 0 deletions .github/workflows/framework-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
exclude:
- {python-version: "3.8", os: "macos-latest"} # macos-14 is arm64, and there's no Python 3.8 build for arm64
- {python-version: "3.9", os: "macos-latest"} # macos-14 is arm64, and there's no Python 3.9 build for arm64

steps:
- uses: actions/checkout@v3
Expand Down
35 changes: 0 additions & 35 deletions test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,3 @@ def test_fake_script_clear(self):
assert fake_script_calls(self, clear=True) == [['bar', 'd e', 'f']]

assert fake_script_calls(self, clear=True) == []


class BaseTestCase(unittest.TestCase):

def create_framework(self,
*,
model: typing.Optional[ops.Model] = None,
tmpdir: typing.Optional[pathlib.Path] = None):
"""Create a Framework object.
By default operate in-memory; pass a temporary directory via the 'tmpdir'
parameter if you wish to instantiate several frameworks sharing the
same dir (e.g. for storing state).
"""
if tmpdir is None:
data_fpath = ":memory:"
charm_dir = 'non-existant'
else:
data_fpath = tmpdir / "framework.data"
charm_dir = tmpdir

framework = ops.Framework(
SQLiteStorage(data_fpath),
charm_dir,
meta=model._cache._meta if model else ops.CharmMeta(),
model=model) # type: ignore
self.addCleanup(framework.close)
return framework

def create_model(self):
"""Create a Model object."""
backend = _ModelBackend(unit_name='myapp/0')
meta = ops.CharmMeta()
model = ops.Model(meta, backend)
return model
Loading

0 comments on commit 6557b10

Please sign in to comment.