[PR] Add maybe copy tests #980

Link to PR

This PR fixes a couple of typos, makes fastai.core.maybe_copy work with files in current working directory (without the dir prefix) and adds tests.

This PR is not complete - will want to write more tests for maybe_copy. As it is right now, the tests have an obvious flaw - they rely on time.sleep. Python seems to write to disk files with the same timestamp even if created via consecutive method calls.

Would appreciate feedback. The sleep has to be removed - not only does it slow down the test suite, but even waiting for as much as 0.01 second seems to not be enough on certain platforms (I repeated the test 100 times on my machine and it was always passing). Anyhow, the sleep should go.

I’m very new to pytests, so I’m not sure if it’s possible to somehow replace your sleep calls by, do that other test that’s on the list. It seems it would be the most efficient

1 Like

This is also a bit problematic because it introduces dependency on order in which tests are run. I am thinking of seeing if executing bash commands like echo txt > file would create the files immediately - thinking that it might but need to actually get to my computer to try it out :slight_smile:

Echo adds a new line so went with printf. That worked on my linux laptop and passed in the CI pipeline but not for osx VMs. Tried a couple of variations on this idea -> kept getting a message that bash exited with code '1' so not a lot of information as to what is really happening there.

Researched this a bit and seems os.utime does the trick :slight_smile: It is passing the CI pipeline and it seems anyhow to be the right way to address this, without relying on however files are getting written to disk nor on usage of wait. That is good I think.

Will call it a day for today but I think based on this I can refactor the tests and add a couple more :slight_smile:

Thanks, it looks nice this way. Can I merge your PR then? Or do you want to keep adding to it?

No you can’t :slight_smile: See my comments.

Made the changes. Please let me know if anything else would be needed.