-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: file locking in file mutation contexts
- Loading branch information
Showing
8 changed files
with
475 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from filelock import BaseFileLock | ||
|
||
|
||
class DummyFileLock(BaseFileLock): | ||
|
||
def release(self, force=False): | ||
pass | ||
|
||
def acquire(self, timeout=None, poll_intervall=0.05): | ||
pass | ||
|
||
def _acquire(self): | ||
pass | ||
|
||
def _release(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import unittest | ||
from functools import wraps | ||
|
||
import path | ||
|
||
from mutapath import Path | ||
|
||
|
||
def file_test(equal: bool = True, instance: bool = True, exists: bool = True): | ||
def file_test_decorator(func): | ||
@wraps(func) | ||
def func_wrapper(cls: PathTest): | ||
try: | ||
actual = cls._gen_start_path() | ||
expected = func(cls, actual) | ||
if equal: | ||
cls.assertIsNotNone(expected, "This test does not return the expected value. Fix the test.") | ||
cls.assertEqual(expected, actual) | ||
if instance: | ||
cls.typed_instance_test(actual) | ||
if exists: | ||
cls.assertTrue(actual.exists(), "The tested file does not exist.") | ||
finally: | ||
cls._clean() | ||
|
||
return func_wrapper | ||
|
||
return file_test_decorator | ||
|
||
|
||
class PathTest(unittest.TestCase): | ||
def __init__(self, *args): | ||
if not self.test_path: | ||
self.test_path = "test_path" | ||
super().__init__(*args) | ||
|
||
def _gen_start_path(self): | ||
self.test_base = Path.getcwd() / self.test_path | ||
self.test_base.rmtree_p() | ||
self.test_base.mkdir() | ||
new_file = self.test_base / "test.file" | ||
new_file.touch() | ||
return new_file | ||
|
||
def _clean(self): | ||
self.test_base.rmtree_p() | ||
|
||
def typed_instance_test(self, instance): | ||
self.assertIsInstance(instance, Path) | ||
self.assertIsInstance(instance._contained, path.Path) |
Oops, something went wrong.