need methods for testing file locking
In issue #150 file locking was permanently on during an upload and we didn't notice. Simply having the transfer work is an insufficient test here. We need to be able to detect when options are not propagated to catch such problems, but the only methods I can think of are painfully manual.
Suggestion: use a custom file-like class as the upload source.
Is this intended to work on macos(darwin) ? I guess I assumed the target platform was unix/POSIX but the current flock implementation fails on macos:
tests/test_tftpy.py::TestTftpyMisc::testStdin FAILED [ 97%]
tests/test_tftpy.py::TestTftpyMisc::testStdout PASSED [100%]
=================================== FAILURES ===================================
___________________________ TestTftpyMisc.testStdin ____________________________
self = <test_tftpy.TestTftpyMisc testMethod=testStdin>
def testStdin(self):
cdir = os.path.dirname(os.path.abspath(__file__))
script = os.path.join(cdir, "stdin.py")
command = f"cat tests/640KBFILE | {script}"
rv = subprocess.call(command, shell=True)
> self.assertTrue( rv == 0 )
E AssertionError: False is not true
tests/test_tftpy.py:651: AssertionError
----------------------------- Captured stderr call -----------------------------
Traceback (most recent call last):
File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 34, in <module>
main()
File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 32, in main
clientServerUploadOptions({}, filename="stdin_upload", input="-")
File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 23, in clientServerUploadOptions
client.upload(filename, input)
File "/Users/runner/work/tftpy/tftpy/tftpy/TftpClient.py", line 136, in upload
c.start()
File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 140, in __exit__
self.end()
File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 390, in end
super().end()
File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 168, in end
lockfile(self.fileobj, unlock=True)
File "/Users/runner/work/tftpy/tftpy/tftpy/TftpShared.py", line 45, in lockfile
fcntl.flock(fobj, mode)
OSError: [Errno 45] Operation not supported
That surprises me. I thought that BSD would support flock. I'll have to borrow an OSX box to troubleshoot this on.
All my hardware runs Linux so I can only test things on macos/windows in Github CI. Also my main example consumer project is full of POSIX daemons that won't run on windows, but has a console "server" and example tox workflow that uses curl for the test client; there might be some interesting examples there: https://github.com/sarnold/pyserv