-
-
Notifications
You must be signed in to change notification settings - Fork 441
fix(test): Fix tests to pass on windows without disrupting other platforms #903
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
064e63c
create and delete tmp directory for tests
zfbx 19ddb9e
Update tests/conftest.py
zfbx 28d078c
Update tests/conftest.py
zfbx 957d528
remove unused import
zfbx f3eea14
cleanup and added type hints
zfbx 7877f63
fix mypy assignment error
zfbx 1abf77d
swap gettempdir() with TemporaryDirectory()
zfbx 5a5ab18
reuse temp library for more tests + cleanup
zfbx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,26 @@ | ||
| from pathlib import Path | ||
| from tempfile import TemporaryDirectory | ||
|
|
||
| from tagstudio.core.global_settings import GlobalSettings, Theme | ||
|
|
||
|
|
||
| def test_read_settings(): | ||
| with TemporaryDirectory() as tmp_dir: | ||
| settings_path = Path(tmp_dir) / "settings.toml" | ||
| with open(settings_path, "a") as settings_file: | ||
| settings_file.write(""" | ||
| language = "de" | ||
| open_last_loaded_on_startup = true | ||
| autoplay = true | ||
| show_filenames_in_grid = true | ||
| page_size = 1337 | ||
| show_filepath = 0 | ||
| dark_mode = 2 | ||
| """) | ||
| def test_read_settings(library_dir: Path): | ||
| settings_path = library_dir / "settings.toml" | ||
| with open(settings_path, "a") as settings_file: | ||
| settings_file.write(""" | ||
| language = "de" | ||
| open_last_loaded_on_startup = true | ||
| autoplay = true | ||
| show_filenames_in_grid = true | ||
| page_size = 1337 | ||
| show_filepath = 0 | ||
| dark_mode = 2 | ||
| """) | ||
|
|
||
| settings = GlobalSettings.read_settings(settings_path) | ||
| assert settings.language == "de" | ||
| assert settings.open_last_loaded_on_startup | ||
| assert settings.autoplay | ||
| assert settings.show_filenames_in_grid | ||
| assert settings.page_size == 1337 | ||
| assert settings.show_filepath == 0 | ||
| assert settings.theme == Theme.SYSTEM | ||
| settings = GlobalSettings.read_settings(settings_path) | ||
| assert settings.language == "de" | ||
| assert settings.open_last_loaded_on_startup | ||
| assert settings.autoplay | ||
| assert settings.show_filenames_in_grid | ||
| assert settings.page_size == 1337 | ||
| assert settings.show_filepath == 0 | ||
| assert settings.theme == Theme.SYSTEM |
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
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.
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'm not sure what the difference between the default scope vs the session scope here in practice, as they both seem to generate different temp directories when this fixture is called.
The only tangible effect I can observe is having
(scope="session")causes the tests intest_refresh_new_files()to fail if using my suggested removal of the strange pre-existing "hasattr" code...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.
For this my understanding of it is that when you use the
scope="session"fixture it runs the code inside it once and then any further calls to it return the same temporary directory path so it can be reused across multiple tests and then when the session is complete it runs cleanup and deletes the directory which is why the yield is used instead of return because return causes the program to end before TempDir does it's cleanup leaving the files in the temp directory.Which leads to the other comment, Yeah, I did notice you had more uses of TemporaryDirectory in other test but I wasn't sure if there was a reason for it maybe needing fresh directories for different tests. I only built it this way because it seemed test_file_path_options:test_title_update() depended on the path being exactly the same as used with conftest:library() which is probably why you had it the way you did.
I hope any of this made sense cause I'm only like 80% following my own words here myself