-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Verify if get_mtime_and_size
can take both Path objects and strings
#2698
Verify if get_mtime_and_size
can take both Path objects and strings
#2698
Conversation
@algomaster99 Please keep an eye on tests, they will tell you if anything is very wrong before I am able to come in and take a look 🙂 |
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.
The tests are failing because get_mtime_and_size
is not converting things properly right now. For example https://github.com/iterative/dvc/blob/0.66.2/dvc/utils/fs.py#L24 https://github.com/iterative/dvc/blob/0.66.2/dvc/utils/fs.py#L42 etc.
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.
Before verifying one needs to actually change get_mtime_and_size()
to handle PathInfo
arguments. The agreed way to do this is wrapping path args with fspath()
unconditionally, see how this is done in dvc.system.System
methods.
tests/unit/utils/test_fs.py
Outdated
def test_path_object_and_str_are_valid_types(self): | ||
dvcignore = DvcIgnoreFilter(self.root_dir) | ||
file_time, file_size = get_mtime_and_size(self.DATA, dvcignore) | ||
file_object_time, file_object_size = get_mtime_and_size( | ||
PathInfo(self.DATA), dvcignore | ||
) | ||
self.assertEqual(file_time, file_object_time) | ||
self.assertEqual(file_size, file_object_size) |
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.
Not sure this test is valuable:
- this is tested via functional tests anyway
- this doesn't test for non-dir argument
I would just drop it.
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.
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.
We are verifying that it works the same with str and path_infos and for that the test is suitable and valuable. Let's keep it.
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.
@algomaster99 But this doesn't test for non-dir argument
is a valid one(though it is probably meant to say "dir" instead of "non-dir"). Let's also run this test with self.DATA_DIR
, so we verify that this works for dirs as well. Make sure that you are not copypasting the code for the new test, but rather use parametrization. E.g. you could make this as a pytest-style test with something like:
@pytest.mark.parametrize("path", ["data_dir", "data"])
You can look around for parametrize
examples in our existing tests. 🙂
@Suor This is not the agreed way. Current patch handles it much better by using fspath_py35 where needed, so next year we can go and remove those easily when py35 reaches end-of-life. |
@efiop having one place at the start of the function to coerce paths is more durable solution. If you only pass that to file utils and expect this to work transparently in Python 3.6+ you might use
We discussed that previously and I had an impression we agreed on that. Maybe that was only about P.S. This is general discussion, which should not delay this particular PR. So we may resolve it in any of those ways. |
@efiop |
@efiop DeepSource test is failing. Do you know how can I fix it? The |
@Suor Good points! In this particular case, I'm not that worried about performance, as double |
@algomaster99 Take DeepSource's report as a recommendation, not as a requirement. We are still fine-tuning the settings for it. |
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.
Thanks!
@efiop I don't worry too much about performance here too. The main point was simplifying code comprehension. Having tests covering things is good, but writing durable code is a basic measure that also works and is cheap. After we all agree on particularities of cause :) And, BTW, it looks like they use "convert at the function start" approach in stdlib too, see os.walk() for example. |
Have you followed the guidelines in our
Contributing document?
Does your PR affect documented changes or does it add new functionality
that should be documented? If yes, have you created a PR for
dvc.org documenting it or at
least opened an issue for it? If so, please add a link to it.
With reference to #2137 and #2673 (comment)