33
44import importlib
55import re
6- import warnings
76from pathlib import Path
8- from types import ModuleType
9- from typing import Dict , List , Optional , Set , Tuple , TypedDict , cast
7+ from typing import Dict , List , Set , Tuple , TypedDict , cast
108
119import pytest
1210
13- from juju .client import connection
11+ from juju .client import connection , _definitions
1412
1513
1614class Versions (TypedDict , total = True ):
@@ -26,9 +24,8 @@ def project_root(pytestconfig: pytest.Config) -> Path:
2624
2725
2826def test_client_facades (project_root : Path ) -> None :
29- good_facades = make_client_facades_from_generated_code (project_root )
3027 client_facades = cast (ClientFacades , connection .client_facades )
31-
28+ good_facades = make_client_facades_from_generated_code ( project_root )
3229 assert {
3330 k : v ['versions' ] for k , v in client_facades .items ()
3431 } == {
@@ -47,12 +44,12 @@ def make_client_facades_from_generated_code(project_root: Path) -> ClientFacades
4744
4845 # _clientN.py files import * from _definitions
4946 # so we will ignore any names from there
50- ignore = dir (importlib . import_module ( 'juju.client. _definitions' ) )
47+ ignore = dir (_definitions )
5148
5249 facades_by_version : Dict [int , Set [str ]] = {}
5350 # {facade_version: {facade_name, ...}, ...}
5451 for version , file in files_by_version :
55- module = _try_import (f'juju.client.{ file .stem } ' )
52+ module = importlib . import_module (f'juju.client.{ file .stem } ' )
5653 facades = {
5754 name .removesuffix ("Facade" )
5855 for name in dir (module )
@@ -75,19 +72,8 @@ def make_client_facades_from_generated_code(project_root: Path) -> ClientFacades
7572 client_facades [name ] = {'versions' : versions }
7673 return client_facades
7774
78- def _try_import (module_name : str ) -> Optional [ModuleType ]:
79- try :
80- return importlib .import_module (module_name )
81- except NameError as e :
82- warnings .warn (f'error on importing { module_name } :\n { type (e ).__name__ } : { e } ' )
83- return None
8475
8576def _version_from_filename (path : Path ) -> int :
8677 match = re .search ('_client([0-9]+).py' , path .name )
8778 assert match
8879 return int (match .group (1 ))
89-
90- def _versions_from_facades (facades : ClientFacades , name : str ) -> Optional [List [int ]]:
91- if name not in facades :
92- return None
93- return facades [name ]['versions' ]
0 commit comments