Skip to content

Commit 53d295c

Browse files
authored
chore:add server to context (#10)
1 parent 0814328 commit 53d295c

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

py_spring_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from py_spring_core.event.commons import ApplicationEvent
1717
from py_spring_core.event.application_event_handler_registry import EventListener
1818

19-
__version__ = "0.0.15"
19+
__version__ = "0.0.16"
2020

2121
__all__ = [
2222
"PySpringApplication",

py_spring_core/core/application/context/application_context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_origin,
1313
)
1414

15+
from fastapi import FastAPI
1516
from loguru import logger
1617
from pydantic import BaseModel
1718

@@ -57,7 +58,8 @@ class ApplicationContext:
5758
The `ApplicationContext` class is designed to follow the Singleton design pattern, ensuring that there is a single instance of the application context throughout the application's lifetime.
5859
"""
5960

60-
def __init__(self, config: ApplicationContextConfig) -> None:
61+
def __init__(self, config: ApplicationContextConfig, server: FastAPI) -> None:
62+
self.server = server
6163
self.all_file_paths: set[str] = set()
6264
self.primitive_types = (bool, str, int, float, type(None))
6365

py_spring_core/core/application/py_spring_application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def __init__(
7979
self.app_context_config = ApplicationContextConfig(
8080
properties_path=self.app_config.properties_file_path
8181
)
82-
self.app_context = ApplicationContext(config=self.app_context_config)
8382
self.fastapi = FastAPI()
83+
self.app_context = ApplicationContext(config=self.app_context_config, server=self.fastapi)
84+
8485

8586
self.classes_with_handlers: dict[
8687
Type[AppEntities], Callable[[Type[Any]], None]

tests/test_application_context.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from fastapi import FastAPI
12
import pytest
23

34
from py_spring_core.core.application.context.application_context import (
@@ -12,9 +13,13 @@
1213

1314
class TestApplicationContext:
1415
@pytest.fixture
15-
def app_context(self):
16+
def server(self) -> FastAPI:
17+
return FastAPI()
18+
19+
@pytest.fixture
20+
def app_context(self, server: FastAPI):
1621
config = ApplicationContextConfig(properties_path="")
17-
return ApplicationContext(config)
22+
return ApplicationContext(config, server=server)
1823

1924
def test_register_entities_correctly(self, app_context: ApplicationContext):
2025
class TestComponent(Component): ...

tests/test_component_features.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from abc import ABC
22
from typing import Annotated
33

4+
from fastapi import FastAPI
45
import pytest
56

67
from py_spring_core.core.application.context.application_context import (
@@ -14,10 +15,14 @@ class TestComponentFeatures:
1415
"""Test suite for component features including primary components, qualifiers, and registration validation."""
1516

1617
@pytest.fixture
17-
def app_context(self):
18+
def server(self) -> FastAPI:
19+
return FastAPI()
20+
21+
@pytest.fixture
22+
def app_context(self, server: FastAPI):
1823
"""Fixture that provides a fresh ApplicationContext instance for each test."""
1924
config = ApplicationContextConfig(properties_path="")
20-
return ApplicationContext(config)
25+
return ApplicationContext(config, server=server)
2126

2227
def test_qualifier_based_injection(self, app_context: ApplicationContext):
2328
"""

tests/test_entity_provider.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from fastapi import FastAPI
12
import pytest
23

34
from py_spring_core.core.application.context.application_context import (
@@ -18,12 +19,16 @@ class TestEntityProvider:
1819
@pytest.fixture
1920
def test_entity_provider(self):
2021
return EntityProvider(depends_on=[TestComponent])
22+
23+
@pytest.fixture
24+
def server(self) -> FastAPI:
25+
return FastAPI()
2126

2227
@pytest.fixture
2328
def test_app_context(
24-
self, test_entity_provider: EntityProvider
29+
self, test_entity_provider: EntityProvider, server: FastAPI
2530
) -> ApplicationContext:
26-
app_context = ApplicationContext(ApplicationContextConfig(properties_path=""))
31+
app_context = ApplicationContext(ApplicationContextConfig(properties_path=""), server=server)
2732
app_context.providers.append(test_entity_provider)
2833
return app_context
2934

0 commit comments

Comments
 (0)