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

tests(windows): fix remaining "unixisms" that break some tests #816

Merged
merged 9 commits into from
Apr 14, 2024

Conversation

kiike
Copy link
Contributor

@kiike kiike commented Apr 12, 2024

When I was developing an earlier PR, I wanted to test it on a vanilla installation of Windows, just to make sure no config could pollute the results.

Turns out, some tests fail on this kind of setup. Even with a benign but creepy Windows error popup during tests/commands/open.
image

Some reasons for the failing tests:

  • symlinks no functional unless "developer mode is active" (I guess CI never sees this because it's running a modified build)
  • typical unix commands such as mv, echo or mv not present in vanilla Windows.

Some details of this PR:

  • It actually contains a fix that is present on a commit of feat(rename): allow batch and auto-renaming from pattern #810, so I'll remove it from there.
  • I want to explain the user why symlinks don't work if we get an exception.
  • I'm sad to make ["git"] if git else []) + ["mv", folder, new_folder_path] go, being so clever. I hope using shutils is OK.
  • the add via symlink test is marked as xfail, just in case it succeeds.
  • script.py now has ls too.

Looking forward to your feedback! I think this PR getting in will make it a bit more polished when a new user tries the 0.14 release on Windows, wants to contribute, and tests pass on a fresh install!

@kiike kiike force-pushed the fix/unixisms branch 2 times, most recently from 7dc2c44 to 533f876 Compare April 12, 2024 16:08
@kiike kiike marked this pull request as draft April 12, 2024 16:31
@kiike kiike force-pushed the fix/unixisms branch 2 times, most recently from 4f9ea08 to 5949a1b Compare April 12, 2024 18:51
@kiike kiike marked this pull request as ready for review April 12, 2024 18:55
@kiike
Copy link
Contributor Author

kiike commented Apr 12, 2024

I misunderstood the Python docs and thought I could have WindowsError in the code and that it wouldn't just check, but that actually breaks on Linux as it is undefined. I changed it to the more generic OSError and then a guard to check for the actual error code.

@kiike kiike changed the title tests: fix remaining "unixisms" tests(windows): fix remaining "unixisms" that break some tests Apr 12, 2024
Copy link
Collaborator

@alexfikl alexfikl left a comment

Choose a reason for hiding this comment

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

This is great! 🎉

Left a few questions and nitpicks, but hopefully easy to fix.

I misunderstood the Python docs and thought I could have WindowsError in the code and that it wouldn't just check, but that actually breaks on Linux as it is undefined. I changed it to the more generic OSError and then a guard to check for the actual error code.

From the docs, WindowsError also seems to be deprecated since version 3.3, so we should just use OSError: https://docs.python.org/3/library/exceptions.html#WindowsError.

papis/commands/add.py Outdated Show resolved Hide resolved
papis/commands/add.py Outdated Show resolved Hide resolved
papis/commands/mv.py Outdated Show resolved Hide resolved
tests/commands/test_add.py Show resolved Hide resolved
tests/commands/test_edit.py Outdated Show resolved Hide resolved
Comment on lines -48 to +50
["--tool", 'cmd.exe /c start ""', "--all", "Krishnamurti"])
["--tool", "cmd.exe /c type", "--all", "Krishnamurti"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does "start" not work here? Or?

@kiike
Copy link
Contributor Author

kiike commented Apr 13, 2024 via email

@alexfikl
Copy link
Collaborator

It raises WinError, an exception that subclasses OSError. WinError can’t be in code that would run on Linux, since that’s undefined. I’ll probably move Windows specific stuff into its own utility function as you suggested so that we have specific WinError exceptions.

According to the docs, WindowsError is an alias of OSError starting with Python 3.3, not a subclass of it. But yeah, it's not defined at all on non-Windows systems, so it can't be used.

As for checking before actually running the operations, I guess that’s not impossible, but where should the check go? After installation, warning the user that functionality would be reduced due to dev mode not enabled, for instance?

I was just thinking for that specific test, to just add a little

if not is_win_dev_mode():
    pytest.skip("This test requires Developer Mode on Windows")

But it was mostly for curiosity. They way it is now is just fine!

@kiike
Copy link
Contributor Author

kiike commented Apr 13, 2024

Blocked until #810 gets in.

Copy link
Collaborator

@alexfikl alexfikl left a comment

Choose a reason for hiding this comment

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

Left a few more suggestions, but this should be good to go once we can use the git stuff from #810.

papis/commands/add.py Show resolved Hide resolved
papis/commands/addto.py Show resolved Hide resolved
papis/utils.py Outdated Show resolved Hide resolved
papis/utils.py Outdated Show resolved Hide resolved
papis/utils.py Outdated Show resolved Hide resolved
papis.utils.run((["git"] if git else []) + ["mv", folder, new_folder_path],
cwd=folder)
if git:
papis.git.mv_and_commit_resource(folder, new_folder_path)

Check failure

Code scanning / CodeQL

Wrong number of arguments in a call

Call to [function mv_and_commit_resource](1) with too few arguments; should be no fewer than 3.
@kiike
Copy link
Contributor Author

kiike commented Apr 14, 2024

I'm checking the exception on windows, to see if it is raising with all arguments

EDIT: It works perfectly, with the files that failed to link and all.

image

@alexfikl
Copy link
Collaborator

@kiike Looks good to me now! Ready to go?

@kiike
Copy link
Contributor Author

kiike commented Apr 14, 2024

@kiike Looks good to me now! Ready to go?

Yes! Let's do it! But if you want me to clean up the commit list so they are logically separated by what they want to do, I can do it to ease reverting/tracking when was something introduced. Just tell me or squash merge, I don't mind 😄

@alexfikl alexfikl merged commit 380e1f1 into papis:main Apr 14, 2024
19 checks passed
@kiike kiike deleted the fix/unixisms branch April 14, 2024 13:11
@alexfikl
Copy link
Collaborator

@kiike Looks good to me now! Ready to go?

Yes! Let's do it! But if you want me to clean up the commit list so they are logically separated by what they want to do, I can do it to ease reverting/tracking when was something introduced. Just tell me or squash merge, I don't mind 😄

I don't know, squashing should be fine. My "rule" is just that when there's some "fix this and that" commits from the review => squash it 😁

Thank you for working on this! In it went 🚀

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.

None yet

2 participants