feat: support pathlib.Path as argument of TortoiseConfig.from_config_file#2184
Open
waketzheng wants to merge 6 commits into
Open
feat: support pathlib.Path as argument of TortoiseConfig.from_config_file#2184waketzheng wants to merge 6 commits into
TortoiseConfig.from_config_file#2184waketzheng wants to merge 6 commits into
Conversation
7 tasks
seladb
reviewed
May 13, 2026
Comment on lines
+102
to
+114
| yaml_file = file.with_suffix(".yml") | ||
| with yaml_file.open("w") as f: | ||
| yaml.safe_dump(dict(simple), f, default_flow_style=False) | ||
| yaml_file_2 = file.with_suffix(".yaml") | ||
| with yaml_file_2.open("w") as f2: | ||
| yaml.safe_dump(simple, f2, default_flow_style=False) | ||
| assert ( | ||
| TortoiseConfig.from_config_file(yaml_file) | ||
| == TortoiseConfig.from_config_file(str(yaml_file)) | ||
| == TortoiseConfig.from_config_file(yaml_file_2) | ||
| == TortoiseConfig.from_config_file(file) | ||
| == TortoiseConfig.resolve_args(config_file=yaml_file) | ||
| ) |
Contributor
There was a problem hiding this comment.
I think we can move yaml to a separate test
Contributor
Author
There was a problem hiding this comment.
We need to verify that the JSON file and YAML file produce the same result when dumped from the same dictionary, so put them in a single function.
Contributor
There was a problem hiding this comment.
Oh ok, I guess it's ok to leave it as is 👍
Comment on lines
+117
to
+130
| simple = { | ||
| "connections": {"default": "sqlite://db.sqlite3"}, | ||
| "apps": { | ||
| "app": { | ||
| "models": ["app.models"], | ||
| "default_connection": "default", | ||
| } | ||
| }, | ||
| } | ||
| db_url = simple["connections"]["default"] | ||
| modules = {"app": simple["apps"]["app"]["models"]} | ||
| typed_config = TortoiseConfig.from_db_url_and_modules(db_url, modules) | ||
| assert typed_config == TortoiseConfig.resolve_args(db_url=db_url, modules=modules) | ||
| assert typed_config.apps == TortoiseConfig.from_dict(simple).apps |
Contributor
There was a problem hiding this comment.
nit: a nicer way to write this test:
def test_from_db_url_and_modules(self):
db_url = "sqlite://db.sqlite3"
models = ["app.models"]
simple = {
"connections": {"default": db_url},
"apps": {
"app": {
"models": models,
"default_connection": "default",
}
},
}
modules = {"app": models}
typed_config = TortoiseConfig.from_db_url_and_modules(db_url, modules)
assert typed_config == TortoiseConfig.resolve_args(db_url=db_url, modules=modules)
assert typed_config.apps == TortoiseConfig.from_dict(simple).apps
Contributor
Author
There was a problem hiding this comment.
Updated to use fixture instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
To support Path as argument of
TortoiseConfig.from_config_file/resolve_args, for example: