Skip to content
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

Add assertions for explicit path comparison #147

Merged
merged 4 commits into from
Oct 10, 2024
Merged

Add assertions for explicit path comparison #147

merged 4 commits into from
Oct 10, 2024

Conversation

twiggler
Copy link
Contributor

@twiggler twiggler commented Oct 8, 2024

Originally, this issue was about implementing explicit path comparisons such as path == posix_path(/usr/local/ls").
As it turns out, this behavior is already supported by flow.record path, because it delegates to the superclass method pathlib::__eq__.

Added some assertions (actually I started with these and found out it already works as intended) to prevent regressions.

Bonus: improve typing of tests.

Closes #146

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.92%. Comparing base (62aff0f) to head (84f087f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #147   +/-   ##
=======================================
  Coverage   83.92%   83.92%           
=======================================
  Files          34       34           
  Lines        3466     3466           
=======================================
  Hits         2909     2909           
  Misses        557      557           
Flag Coverage Δ
unittests 83.92% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Schamper Schamper changed the title Add assetions for explicit path comparison. Add assertions for explicit path comparison Oct 8, 2024
tests/test_fieldtypes.py Outdated Show resolved Hide resolved
Copy link
Member

@Schamper Schamper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong button

@twiggler twiggler requested a review from Schamper October 9, 2024 07:19
@@ -689,7 +690,9 @@ def test_path() -> None:
),
],
)
def test_path_multiple_parts(path_parts, expected_instance) -> None:
def test_path_multiple_parts(
path_parts: Tuple[str | pathlib.PurePath, ...], expected_instance: Type[pathlib.PurePath]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path_parts: Tuple[str | pathlib.PurePath, ...], expected_instance: Type[pathlib.PurePath]
path_parts: Tuple[str | pathlib.PurePath, ...], expected_instance: type[pathlib.PurePath]

This is legal these days (unless it's another thing not allowed by 3.8, in which case ignore this comment).

Copy link
Contributor Author

@twiggler twiggler Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this got introduced in python 3.9 but the python compatibility test passes with type instead of Type.

In any case, 3.8 is EOL now https://discuss.python.org/t/python-3-8-is-now-officially-eol/66983

@@ -1153,7 +1160,7 @@ def test_command_failed() -> None:
fieldtypes.path,
],
)
def test_empty_path(path_cls) -> None:
def test_empty_path(path_cls: Type[pathlib.PurePath]) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_empty_path(path_cls: Type[pathlib.PurePath]) -> None:
def test_empty_path(path_cls: type[pathlib.PurePath]) -> None:

Schamper
Schamper previously approved these changes Oct 9, 2024
@@ -688,7 +690,9 @@ def test_path():
),
],
)
def test_path_multiple_parts(path_parts, expected_instance):
def test_path_multiple_parts(
path_parts: Tuple[str | pathlib.PurePath, ...], expected_instance: type[pathlib.PurePath]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path_parts: Tuple[str | pathlib.PurePath, ...], expected_instance: type[pathlib.PurePath]
path_parts: tuple[str | pathlib.PurePath, ...], expected_instance: type[pathlib.PurePath]

This already worked with no changes because path::__eq__ is delegating to pathlib::__eq__. Nevertheless, let's prevent regressions.
@twiggler twiggler merged commit c17dc6b into main Oct 10, 2024
18 checks passed
@twiggler twiggler deleted the path-comparison branch October 10, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure explicit path comparisons are supported
3 participants