Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test_main and test_storage #1199

Merged
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
Loading