Skip to content

Commit 7772bb9

Browse files
authored
✅ add alias hook tests
1 parent 5d3e438 commit 7772bb9

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

githubkit/module_hooks/alias_module.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]:
4848
if self.name in sys.modules:
4949
return sys.modules[self.name]
5050

51-
alias_module = importlib.import_module(self.alias_fullname)
51+
try:
52+
alias_module = importlib.import_module(self.alias_fullname)
53+
except ModuleNotFoundError:
54+
raise ModuleNotFoundError(f"No module named {self.name!r}")
5255
module = AliasModule(self.name)
5356
module.__alias_fullname__ = self.alias_fullname
5457
module.__alias_module__ = alias_module

tests/test_versions/test_models.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# import some commonly used models to ensure they are available
22

33
# SimpleUser
4+
# backport
5+
from githubkit.versions.ghec_v2022_11_28.models import ( # noqa: F401
6+
SimpleUser as BackportSimpleUserGhecV2022_11_28,
7+
)
8+
from githubkit.versions.ghec_v2026_03_10.models import ( # noqa: F401
9+
SimpleUser as BackportSimpleUserGhecV2026_03_10,
10+
)
11+
from githubkit.versions.latest.models import ( # noqa: F401
12+
SimpleUser as BackportSimpleUserLatest,
13+
)
14+
from githubkit.versions.v2022_11_28.models import ( # noqa: F401
15+
SimpleUser as BackportSimpleUserV2022_11_28,
16+
)
17+
from githubkit.versions.v2026_03_10.models import ( # noqa: F401
18+
SimpleUser as BackportSimpleUserV2026_03_10,
19+
)
20+
21+
# direct
422
from githubkit_schemas.ghec_v2022_11_28.models import ( # noqa: F401
523
SimpleUser as SimpleUserGhecV2022_11_28,
624
)
@@ -20,6 +38,24 @@
2038
# isort: split
2139

2240
# Repository
41+
# backport
42+
from githubkit.versions.ghec_v2022_11_28.models import ( # noqa: F401
43+
Repository as BackportRepositoryGhecV2022_11_28,
44+
)
45+
from githubkit.versions.ghec_v2026_03_10.models import ( # noqa: F401
46+
Repository as BackportRepositoryGhecV2026_03_10,
47+
)
48+
from githubkit.versions.latest.models import ( # noqa: F401
49+
Repository as BackportRepositoryLatest,
50+
)
51+
from githubkit.versions.v2022_11_28.models import ( # noqa: F401
52+
Repository as BackportRepositoryV2022_11_28,
53+
)
54+
from githubkit.versions.v2026_03_10.models import ( # noqa: F401
55+
Repository as BackportRepositoryV2026_03_10,
56+
)
57+
58+
# direct
2359
from githubkit_schemas.ghec_v2022_11_28.models import ( # noqa: F401
2460
Repository as RepositoryGhecV2022_11_28,
2561
)
@@ -39,6 +75,24 @@
3975
# isort: split
4076

4177
# OrganizationFull
78+
# backport
79+
from githubkit.versions.ghec_v2022_11_28.models import ( # noqa: F401
80+
OrganizationFull as BackportOrganizationFullGhecV2022_11_28,
81+
)
82+
from githubkit.versions.ghec_v2026_03_10.models import ( # noqa: F401
83+
OrganizationFull as BackportOrganizationFullGhecV2026_03_10,
84+
)
85+
from githubkit.versions.latest.models import ( # noqa: F401
86+
OrganizationFull as BackportOrganizationFullLatest,
87+
)
88+
from githubkit.versions.v2022_11_28.models import ( # noqa: F401
89+
OrganizationFull as BackportOrganizationFullV2022_11_28,
90+
)
91+
from githubkit.versions.v2026_03_10.models import ( # noqa: F401
92+
OrganizationFull as BackportOrganizationFullV2026_03_10,
93+
)
94+
95+
# direct
4296
from githubkit_schemas.ghec_v2022_11_28.models import ( # noqa: F401
4397
OrganizationFull as OrganizationFullGhecV2022_11_28,
4498
)
@@ -58,6 +112,24 @@
58112
# isort: split
59113

60114
# CustomProperty
115+
# backport
116+
from githubkit.versions.ghec_v2022_11_28.models import ( # noqa: F401
117+
CustomProperty as BackportCustomPropertyGhecV2022_11_28,
118+
)
119+
from githubkit.versions.ghec_v2026_03_10.models import ( # noqa: F401
120+
CustomProperty as BackportCustomPropertyGhecV2026_03_10,
121+
)
122+
from githubkit.versions.latest.models import ( # noqa: F401
123+
CustomProperty as BackportCustomPropertyLatest,
124+
)
125+
from githubkit.versions.v2022_11_28.models import ( # noqa: F401
126+
CustomProperty as BackportCustomPropertyV2022_11_28,
127+
)
128+
from githubkit.versions.v2026_03_10.models import ( # noqa: F401
129+
CustomProperty as BackportCustomPropertyV2026_03_10,
130+
)
131+
132+
# direct
61133
from githubkit_schemas.ghec_v2022_11_28.models import ( # noqa: F401
62134
CustomProperty as CustomPropertyGhecV2022_11_28,
63135
)

tests/test_versions/test_types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# backport
2+
from githubkit.versions.ghec_v2022_11_28.types import ( # noqa: F401
3+
SimpleUserType as BackportSimpleUserGhecV2022_11_28Type,
4+
)
5+
from githubkit.versions.ghec_v2026_03_10.types import ( # noqa: F401
6+
SimpleUserType as BackportSimpleUserGhecV2026_03_10Type,
7+
)
8+
from githubkit.versions.latest.types import ( # noqa: F401
9+
SimpleUserType as BackportSimpleUserLatestType,
10+
)
11+
from githubkit.versions.v2022_11_28.types import ( # noqa: F401
12+
SimpleUserType as BackportSimpleUserV2022_11_28Type,
13+
)
14+
from githubkit.versions.v2026_03_10.types import ( # noqa: F401
15+
SimpleUserType as BackportSimpleUserV2026_03_10Type,
16+
)
17+
18+
# direct
119
from githubkit_schemas.ghec_v2022_11_28.types import ( # noqa: F401
220
SimpleUserType as SimpleUserGhecV2022_11_28Type,
321
)

0 commit comments

Comments
 (0)