-
Notifications
You must be signed in to change notification settings - Fork 0
add missing tests #85
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
Open
viseshrp
wants to merge
37
commits into
main
Choose a base branch
from
maint/optim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b5f09b3
workaround a dateparser bug
viseshrp 38dc03e
select UUID for efficient delete-subquery
viseshrp 8086fac
Merge branch 'main' into maint/optim
viseshrp 5e8ea8b
use prefetch to get tag data
viseshrp 72e7ca1
Merge branch 'maint/optim' of https://github.com/viseshrp/workedon in…
viseshrp ebc3a84
add index for duration
viseshrp c225920
Revert "use prefetch to get tag data"
viseshrp 3da33fe
Update uv.lock
viseshrp 5f27073
fix partial date test
viseshrp d414491
add prefetch for tags
viseshrp 527064e
Update README.md
viseshrp 12e716b
Update workedon.py
viseshrp 76ce41f
improve tag filter queries
viseshrp 4d4a26a
delay COUNT query until later
viseshrp fbf7086
Update workedon.py
viseshrp 2bbbe53
add tests by Codex and Claude
viseshrp 09bdd8d
Merge branch 'main' into maint/optim
viseshrp 24345c4
fix ruff warnings
viseshrp 1ebc442
remove unnecessary guard and test
viseshrp c55ed46
Update test_integration.py
viseshrp e9699ab
Update test_integration.py
viseshrp 3b104f7
fix lint
viseshrp 780be7b
cleanup
viseshrp 313cd82
Freeze every test at a fixed date
viseshrp b8e656e
fix flaky test_parse_datetime_edge_of_midnight with double freeze
viseshrp a868469
Update test_conf.py
viseshrp 1f76a0e
Merge branch 'main' into maint/optim
viseshrp 028152c
fix debug check
viseshrp ad1c488
refactor cli tests
viseshrp 5f47d7b
Update test_utils.py
viseshrp 9dd82e1
add check constraint for empty tags
viseshrp ab1b58c
normalize tags
viseshrp abeff07
update tag tests
viseshrp 4bc8372
Reduce redundant CLI/parser test cases
viseshrp bee2fc8
Revert "Reduce redundant CLI/parser test cases"
viseshrp 76c3ae2
Update lockfile to fix pip-audit
viseshrp eabaea1
Normalize fetch tag filters and document behavior
viseshrp 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
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from workedon import conf | ||
| from workedon.conf import Settings | ||
| from workedon.constants import SETTINGS_HEADER | ||
| from workedon.exceptions import CannotCreateSettingsError, CannotLoadSettingsError | ||
|
|
||
|
|
||
| def test_settings_getattr_and_setattr() -> None: | ||
| settings = Settings() | ||
| settings.FOO = "bar" | ||
| assert settings.FOO == "bar" | ||
| assert settings["FOO"] == "bar" | ||
|
|
||
|
|
||
| def test_configure_creates_settings_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
|
|
||
| settings = Settings() | ||
| settings.configure() | ||
|
|
||
| assert conf_path.exists() | ||
| assert SETTINGS_HEADER.strip() in conf_path.read_text() | ||
|
|
||
|
|
||
| def test_configure_loads_user_settings(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| conf_path.write_text('TIME_FORMAT = "%H:%M"\n') | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
|
|
||
| settings = Settings() | ||
| settings.configure() | ||
|
|
||
| assert settings.TIME_FORMAT == "%H:%M" | ||
|
|
||
|
|
||
| def test_configure_merges_user_settings(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| conf_path.write_text('DATE_FORMAT = "%Y"\n') | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
|
|
||
| settings = Settings() | ||
| settings.configure(user_settings={"DATE_FORMAT": "%d"}) | ||
|
|
||
| assert settings.DATE_FORMAT == "%d" | ||
|
|
||
|
|
||
| def test_configure_raises_on_bad_spec(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| conf_path.write_text("# ok\n") | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
| monkeypatch.setattr(conf, "spec_from_file_location", lambda *args, **kwargs: None) | ||
|
|
||
| settings = Settings() | ||
| with pytest.raises(CannotLoadSettingsError): | ||
| settings.configure() | ||
|
|
||
|
|
||
| def test_configure_raises_on_exec_module_failure( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| conf_path.write_text("raise RuntimeError('boom')\n") | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
|
|
||
| settings = Settings() | ||
| with pytest.raises(CannotLoadSettingsError) as excinfo: | ||
| settings.configure() | ||
| assert "boom" in str(excinfo.value) | ||
|
|
||
|
|
||
| def test_configure_raises_on_settings_file_creation_failure( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| conf_path = tmp_path / "wonfile.py" | ||
| monkeypatch.setattr(conf, "CONF_PATH", conf_path) | ||
|
|
||
| settings = Settings() | ||
|
|
||
| def blow_up() -> None: | ||
| raise OSError("nope") | ||
|
|
||
| monkeypatch.setattr(Settings, "_create_settings_file", blow_up) | ||
| with pytest.raises(CannotCreateSettingsError): | ||
| settings.configure() |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from workedon import constants | ||
|
|
||
|
|
||
| def test_constants_have_expected_values() -> None: | ||
| assert constants.APP_NAME == "workedon" | ||
| assert constants.CURRENT_DB_VERSION > 0 | ||
| assert constants.WORK_CHUNK_SIZE > 0 | ||
| assert "workedon settings file" in constants.SETTINGS_HEADER |
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from workedon import default_settings | ||
|
|
||
|
|
||
| def test_default_settings_are_sane() -> None: | ||
| assert isinstance(default_settings.DATE_FORMAT, str) | ||
| assert isinstance(default_settings.TIME_FORMAT, str) | ||
| assert default_settings.DATETIME_FORMAT == "" | ||
| assert isinstance(default_settings.TIME_ZONE, str) | ||
| assert default_settings.TIME_ZONE | ||
| assert default_settings.DURATION_UNIT == "minutes" |
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import pytest | ||
|
|
||
| from workedon import exceptions | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "exc_cls, detail", | ||
| [ | ||
| (exceptions.DBInitializationError, "Unable to initialize the database."), | ||
| (exceptions.CannotCreateSettingsError, "Unable to create settings file."), | ||
| (exceptions.CannotLoadSettingsError, "Unable to load settings file."), | ||
| (exceptions.InvalidWorkError, "The provided work text is invalid."), | ||
| ( | ||
| exceptions.InvalidDateTimeError, | ||
| "The provided date/time is invalid. Please refer the docs for valid phrases.", | ||
| ), | ||
| (exceptions.DateTimeInFutureError, "The provided date/time is in the future."), | ||
| (exceptions.StartDateAbsentError, "Please provide a start date/time."), | ||
| ( | ||
| exceptions.StartDateGreaterError, | ||
| "The provided start date/time is greater than the end date/time.", | ||
| ), | ||
| (exceptions.CannotSaveWorkError, "Unable to save your work."), | ||
| (exceptions.CannotFetchWorkError, "Unable to fetch your work."), | ||
| ], | ||
| ) | ||
| def test_exception_details_and_string_formatting( | ||
| exc_cls: type[exceptions.WorkedOnError], detail: str | ||
| ) -> None: | ||
| assert str(exc_cls()) == detail | ||
| assert str(exc_cls(extra_detail="extra")) == f"{detail} :: extra" | ||
| assert str(exc_cls(extra_detail="")) == detail |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.