-
Notifications
You must be signed in to change notification settings - Fork 6
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
Config setup docs - through tests #634
base: main
Are you sure you want to change the base?
Conversation
93899f7
to
4d6fbb3
Compare
4d6fbb3
to
4db0aa4
Compare
it works until line 179 ( call to |
config_data = {
"env": {},
"sources": [
{"kind": "dodal", "module": "dodal.adsim"},
{"kind": "planFunctions", "module": "dls_bluesky_core.plans"},
{"kind": "planFunctions", "module": "dls_bluesky_core.stubs"},
],
"data_writing": {
"visit_directory": "/dls/p38/data/2023/cm33874-1",
"group_name": "BL38P",
},
}
does not map directly to this: perhaps config loading could be simplified, to mirror more closely the helm structure |
all good |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #634 +/- ##
=======================================
Coverage 92.56% 92.56%
=======================================
Files 35 35
Lines 1654 1655 +1
=======================================
+ Hits 1531 1532 +1
Misses 123 123 ☔ View full report in Codecov by Sentry. |
tests/unit_tests/test_config.py
Outdated
def temp_yaml_config_file(request): | ||
# Use the provided config data from test parameters | ||
config_data = request.param | ||
|
||
# Create a temporary YAML file with the configuration | ||
with tempfile.NamedTemporaryFile( | ||
suffix=".yaml", mode="w", delete=False | ||
) as temp_yaml_file: | ||
yaml.dump(config_data, temp_yaml_file) | ||
temp_yaml_file_path = temp_yaml_file.name | ||
|
||
# Provide the path and the config data | ||
yield Path(temp_yaml_file_path), config_data | ||
|
||
# Cleanup after test execution | ||
os.remove(temp_yaml_file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should: This seems like a lot of extra boilerplate compared to just writing the example config below into a YAML file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's an opinionated tradeoff (some more lines in a fixture + a dict-like test content) vs a bunch of test-data yaml files .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, the main motivation is that you may as well have the thing the user will write as an input to your test data
class BasicAuthentication(BaseModel):
"""
User credentials for basic authentication
"""
username: str = Field(description="Unique identifier for user")
password: Secret[str] = Field(description="Password to verify user's identity")
@field_validator("username", "password", mode="before")
@classmethod
def get_from_env(cls, v: str):
if v.startswith("${") and v.endswith("}"):
return os.environ[v.removeprefix("${").removesuffix("}").upper()]
return v
current error is coming from |
@ZohebShaikh any ideas? |
@stan-dot you need to unwrap the Secret[str] before using it. It fetches it from the ENV if configured to do so for injection of the RMQ password. If you want to adjust how the handling of that env var fetching is done to your override levels handling then feel free. @keithralphs needs to mount a bunch of tracing values as env vars, so having that handling in one place is preferable. But the type of the password should remain |
f567ae7
to
59226b9
Compare
odd, digging deeper |
FAILED tests/unit_tests/test_config.py::test_config_yaml_parsed_complete[temp_yaml_config_file0] - blueapi.utils.invalid_config_error.InvalidConfigError: Something is wrong with the configuration file:
{'type': 'model_type', 'loc': ('scratch', 'repositories', 0), 'msg': 'Input should be a valid dictionary or instance of ScratchRepository', 'input': 'dodal', 'ctx': {'class_name': 'ScratchRepository'}, 'url': 'https://errors.pydantic.dev/2.9/v/model_type'}
FAILED tests/unit_tests/test_config.py::test_config_yaml_parsed_complete[temp_yaml_config_file1] - blueapi.utils.invalid_config_error.InvalidConfigError: Something is wrong with the configuration file:
{'type': 'model_type', 'loc': ('scratch', 'repositories', 0), 'msg': 'Input should be a valid dictionary or instance of ScratchRepository', 'input': 'dodal', 'ctx': {'class_name': 'ScratchRepository'}, 'url': 'https://errors.pydantic.dev/2.9/v/model_type'}
FAILED tests/unit_tests/worker/test_task_worker.py::test_worker_and_data_events_produce_in_order - concurrent.futures._base.TimeoutError
============= 3 failed,
got a more specific error |
please validate the directional correctness of the test first. #tdd