After the test completes as expected (ALREADY_LOCKED), ensure we close the
filehandle for that, else it seems to interfere with the sub-process
cleanup, which then leads to subsequent tests not being able to cleanup.
Tests as now working after 10s of runs of `pytest` in a loop.
* Set `tmpdir` properly for this test.
* Do **NOT** unset `JournalLock.journal_dir_lockfile_name` on release, as
this is needed to remove the file
* Ensure prior test(s) release their locks, *and* remove the file.
* Some `# pragma: no cover' added where it's more pain to get coverage
than to put up with lack of testing.
We are choosing to NOT test retry_lock() or the call to it from
update_lock() as it's tkinter stuff.
* Check `self.journal_dir_lockfile` exists before trying to call
.close() on it.
* Note where platform checks means only one if branch gets run, so of
course coverage will complain about the other one.
* Add test_release_lock_lie_locked() to test when not locked, but
pretend we were so release_lock() returns False.
* Add test_update_lock_same() to check if an attempt is made to 'update'
to the same directory.
* update_lock() wants to, potentially, invoke
JournalLock.JournalAlreadyLocked() instance for a tkinter pop-up.
We do *not* want to mock all of that, so monkeypatch a mock so that in
the 'test PASSED' case this just works.
This splits the code for opening the lockfile away from that for
actually obtaining the lock. It enables a test for trying to lock again
with the same file handle.
* On win32 this uses pywin32 package modules, so that's now in
requirements-dev.txt.
* I *think* that code is as clean as it's going to be. Windows is a
pain with having you *append* a Deny ACL (rather than remove an Allow
one), and then you have to find it in all the ACLs for the object in
order to remove it by index.
* Linux version of this using `os.chmod()` currently untested.
Only tested under win32 so far, but I'd hope os.chmod() is the way to go
on Linux and macOS.
The win32 implementation currently relies on the pywin32 package being
installed in order to use its ntsecuritycon and win32security modules.
It might be possible to do this with ctypes instead, but this sure looks
cleaner than most ctypes code I've seen.
* mock get_str() is now via a fixture so it can be re-used in more than
one test, avoiding DRY issue.
* Some actual tests, in the form of asserts, added to
test_journal_lock_init().