python-fsutil icon indicating copy to clipboard operation
python-fsutil copied to clipboard

fsutil write_file atomic=True destroys created file on exit

Open williwacker opened this issue 1 year ago • 13 comments
trafficstars

Python version 3.10

Package version latest

Current behavior (bug description) write_file atomic=True destroys the created file on exit. Obviously fsutil is not designed for running on Windows. Cannot handle directory names etc.

Expected behavior created file should stay

Test Results: pytest_result.txt

williwacker avatar May 04 '24 10:05 williwacker

@williwacker actually all tests run successfully even on Windows. Can you help me to figure how to make the CI fail (when it should) when running on Windows?

fabiocaccamo avatar May 10 '24 11:05 fabiocaccamo

Hi Fabio, I am wondering how the test can run on your windows machine where windows paths are always created wit backslashes and the tests comparing the given paths (using forward slashes) with the created ones are different. I cannot say what is different on my system from yours. My suggestion would be calling Pathlib.PurePath(path).as_posix(). With this approach paths are always with forward slashes. Regards Werner

williwacker avatar May 11 '24 15:05 williwacker

How I was testing: copied the testcase file into my temp folder and started pytest from this folder.

williwacker avatar May 12 '24 00:05 williwacker

@williwacker I have not a Windows machine, I run tests locally using tox and remotely on Linux / MacOS / Windows using the GitHub CI.

The tests are based on unittest and not on pytest.

For testing, please follow the instructions in the README testing section.

fabiocaccamo avatar May 12 '24 16:05 fabiocaccamo

@fabiocaccamo, Simular result when running unittest. unittest.txt

williwacker avatar May 13 '24 12:05 williwacker

@williwacker thank you for the feedback, this is probably just a tests problem because paths are hardcoded, I will try to fix tests as soon as possible and ask you to check again.

Anyway, I don't understand why the GitHub CI doesn't fail when running on Windows.

fabiocaccamo avatar May 14 '24 08:05 fabiocaccamo

@williwacker I improved some tests for Windows compatibility, could you please pull from master, run tests and send me the errors report?

fabiocaccamo avatar May 14 '24 19:05 fabiocaccamo

Hi @fabiocaccamo, Much better but not perfect yet. I guess the permission test cases can be ignored on windows, but the atomic write file tests are important. Thanks unittest.result.txt

williwacker avatar May 16 '24 07:05 williwacker

@williwacker exactly what I expected, I also agree with skipping permission test cases on Windows. I will try to figure out the atomic write file tests issue (if you have any hint let me know). Thanks for the updated errors report.

fabiocaccamo avatar May 16 '24 07:05 fabiocaccamo

@williwacker I would ask you to pull from master and test it again.

All tests should succeed now (permissions tests skipped on Windows), except atomic write file tests that should still fail, but I would ask you to do a couple of tests locally:

fabiocaccamo avatar May 21 '24 07:05 fabiocaccamo

Hi @fabiocaccamo, have tested the new code with both delete=true and false and have pasted the output in here. Thanks test_result_delete_false.txt test_result_delete_true.txt

williwacker avatar Jun 02 '24 12:06 williwacker