From 7e25d1e1eb150d7488947325322f6b74704c3bbd Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Thu, 20 Jun 2024 14:23:33 +0800 Subject: [PATCH 1/3] chore: rename charms.yaml file to interface.yaml --- README.md | 4 ++-- interface_tester/collector.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5bdc9d4..b83dc51 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Interface-tester-pytest +# pytest-interface-tester This repository contains a library meant to facilitate compliance testing of charm relation interfaces. The problem is best stated as follows: @@ -74,7 +74,7 @@ The flow is (from the POV of the spec repo): ## Customizing the fixture's address -You can customize name and location of the fixture, but you will need to include that data when registering your charm with the interface. In `charms.yaml`, you can then specify: +You can customize name and location of the fixture, but you will need to include that data when registering your charm with the interface. In `interface.yaml`, you can then specify: ```yaml - name: my-charm-name # required url: https://github.com/foo/my-charm-name # required diff --git a/interface_tester/collector.py b/interface_tester/collector.py index d297455..bd76873 100644 --- a/interface_tester/collector.py +++ b/interface_tester/collector.py @@ -9,6 +9,7 @@ schemas for one, you can execute this file to ascertain that all relevant data is being gathered correctly. """ + import dataclasses import importlib import inspect @@ -61,7 +62,7 @@ def __hash__(self): class _CharmsDotYamlSpec(TypedDict): - """Specification of the `charms.yaml` file each interface/version dir should contain.""" + """Specification of the `interface.yaml` file each interface/version dir should contain.""" providers: List[_CharmTestConfig] requirers: List[_CharmTestConfig] @@ -152,19 +153,19 @@ def get_schemas(file: Path) -> Dict[Literal["requirer", "provider"], Type[DataBa def _gather_charms_for_version(version_dir: Path) -> Optional[_CharmsDotYamlSpec]: - """Attempt to read the `charms.yaml` for this version sudir. + """Attempt to read the `interface.yaml` for this version sudir. On failure, return None. """ - charms_yaml = version_dir / "charms.yaml" - if not charms_yaml.exists(): + interface_yaml = version_dir / "interface.yaml" + if not interface_yaml.exists(): return None charms = None try: - charms = yaml.safe_load(charms_yaml.read_text()) + charms = yaml.safe_load(interface_yaml.read_text()) except (json.JSONDecodeError, yaml.YAMLError) as e: - logger.error("failed to decode %s: verify that it is valid yaml: %s" % (charms_yaml, e)) + logger.error("failed to decode %s: verify that it is valid yaml: %s" % (interface_yaml, e)) except FileNotFoundError as e: logger.error("not found: %s" % e) if not charms: @@ -175,10 +176,10 @@ def _gather_charms_for_version(version_dir: Path) -> Optional[_CharmsDotYamlSpec if not isinstance(providers, list) or not isinstance(requirers, list): raise TypeError( - f"{charms_yaml} file has unexpected providers/requirers spec; " + f"{interface_yaml} file has unexpected providers/requirers spec; " f"expected two lists of dicts (yaml mappings); " f"got {type(providers)}/{type(requirers)}. " - f"Invalid charms.yaml format." + f"Invalid interface.yaml format." ) provider_configs = [] @@ -190,7 +191,7 @@ def _gather_charms_for_version(version_dir: Path) -> Optional[_CharmsDotYamlSpec except TypeError: logger.error( "failure parsing %s to _CharmTestConfig; invalid charm test " - "configuration in %s/charms.yaml:providers" % (item, version_dir) + "configuration in %s/interface.yaml:providers" % (item, version_dir) ) continue destination.append(cfg) From f4e951e21aa2b1d6f52c8ecd0dee8c37f637f784 Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Thu, 20 Jun 2024 14:30:36 +0800 Subject: [PATCH 2/3] test: fix ut --- .../interfaces/database/v1/{charms.yaml => interface.yaml} | 0 .../interfaces/tracing/v42/{charms.yaml => interface.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/resources/cri-like-path/interfaces/database/v1/{charms.yaml => interface.yaml} (100%) rename tests/resources/cri-like-path/interfaces/tracing/v42/{charms.yaml => interface.yaml} (100%) diff --git a/tests/resources/cri-like-path/interfaces/database/v1/charms.yaml b/tests/resources/cri-like-path/interfaces/database/v1/interface.yaml similarity index 100% rename from tests/resources/cri-like-path/interfaces/database/v1/charms.yaml rename to tests/resources/cri-like-path/interfaces/database/v1/interface.yaml diff --git a/tests/resources/cri-like-path/interfaces/tracing/v42/charms.yaml b/tests/resources/cri-like-path/interfaces/tracing/v42/interface.yaml similarity index 100% rename from tests/resources/cri-like-path/interfaces/tracing/v42/charms.yaml rename to tests/resources/cri-like-path/interfaces/tracing/v42/interface.yaml From dbcd1de4de836434aee3b3aafe1ca1b849841bdc Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Mon, 24 Jun 2024 18:06:07 +0800 Subject: [PATCH 3/3] chore: refactor after review --- interface_tester/collector.py | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface_tester/collector.py b/interface_tester/collector.py index bd76873..5ef08b3 100644 --- a/interface_tester/collector.py +++ b/interface_tester/collector.py @@ -61,7 +61,7 @@ def __hash__(self): return hash((self.name, self.url, self.branch)) -class _CharmsDotYamlSpec(TypedDict): +class _InterfacesDotYamlSpec(TypedDict): """Specification of the `interface.yaml` file each interface/version dir should contain.""" providers: List[_CharmTestConfig] @@ -152,8 +152,8 @@ def get_schemas(file: Path) -> Dict[Literal["requirer", "provider"], Type[DataBa return out -def _gather_charms_for_version(version_dir: Path) -> Optional[_CharmsDotYamlSpec]: - """Attempt to read the `interface.yaml` for this version sudir. +def _gather_charms_for_version(version_dir: Path) -> Optional[_InterfacesDotYamlSpec]: + """Attempt to read the `interface.yaml` for this version_dir. On failure, return None. """ @@ -196,7 +196,7 @@ def _gather_charms_for_version(version_dir: Path) -> Optional[_CharmsDotYamlSpec continue destination.append(cfg) - spec: _CharmsDotYamlSpec = {"providers": provider_configs, "requirers": requirer_configs} + spec: _InterfacesDotYamlSpec = {"providers": provider_configs, "requirers": requirer_configs} return spec diff --git a/pyproject.toml b/pyproject.toml index d06c1c2..d9a5404 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta" [project] name = "pytest-interface-tester" -version = "2.0.1" +version = "3.0.0" authors = [ { name = "Pietro Pasotti", email = "pietro.pasotti@canonical.com" }, ]