From 2baa9d628fd1ed2eb4bc5fdd4685aa37e669d525 Mon Sep 17 00:00:00 2001 From: matfax Date: Sat, 22 Aug 2020 14:31:45 +0000 Subject: [PATCH] style(format): reformat with black --- docs/attributes.py | 2 +- mutapath/decorator.py | 87 ++++++++++++++++++++++++++------ mutapath/immutapath.py | 100 ++++++++++++++++++++++++++----------- mutapath/lock_dummy.py | 1 - mutapath/mutapath.py | 12 +++-- tests/helper.py | 31 +++++++++--- tests/test_immutapath.py | 60 ++++++++++++++++------ tests/test_mutapath.py | 20 +++++--- tests/test_serializable.py | 10 ++-- tests/test_with_path.py | 18 ++++--- 10 files changed, 251 insertions(+), 90 deletions(-) diff --git a/docs/attributes.py b/docs/attributes.py index 304678d..8c8706a 100644 --- a/docs/attributes.py +++ b/docs/attributes.py @@ -49,7 +49,7 @@ def __init__(self, *args) -> None: if isinstance(self.object, mutapath.Path): for member in dir(mutapath.Path): if member not in self.options.get("members") and not member.startswith( - "_" + "_" ): LOG.info(f"[attributes] adding wrapped member {member}") self.options["members"].append(member) diff --git a/mutapath/decorator.py b/mutapath/decorator.py index 5f7ec5e..9a2004a 100644 --- a/mutapath/decorator.py +++ b/mutapath/decorator.py @@ -15,16 +15,67 @@ import mutapath __EXCLUDE_FROM_WRAPPING = [ - "__dir__", "__eq__", "__format__", "__repr__", "__str__", "__sizeof__", "__init__", "__getattribute__", - "__delattr__", "__setattr__", "__getattr__", "joinpath", "clone", "__exit__", "__fspath__", - "'_Path__wrap_attribute'", "__wrap_decorator", "_op_context", "__hash__", "__enter__", "_norm", "open", "lock", - "getcwd", "dirname", "owner", "uncshare", "posix_format", "posix_string", "__add__", "__radd__", "_set_contained", - "with_poxis_enabled", "_hash_cache", "_serialize", "_deserialize", "string_repr_enabled", "_shorten_duplicates", - "text", "bytes" + "__dir__", + "__eq__", + "__format__", + "__repr__", + "__str__", + "__sizeof__", + "__init__", + "__getattribute__", + "__delattr__", + "__setattr__", + "__getattr__", + "joinpath", + "clone", + "__exit__", + "__fspath__", + "'_Path__wrap_attribute'", + "__wrap_decorator", + "_op_context", + "__hash__", + "__enter__", + "_norm", + "open", + "lock", + "getcwd", + "dirname", + "owner", + "uncshare", + "posix_format", + "posix_string", + "__add__", + "__radd__", + "_set_contained", + "with_poxis_enabled", + "_hash_cache", + "_serialize", + "_deserialize", + "string_repr_enabled", + "_shorten_duplicates", + "text", + "bytes", ] -__MUTABLE_FUNCTIONS = {"rename", "renames", "copy", "copy2", "copyfile", "copymode", "copystat", "copytree", "move", - "basename", "abspath", "join", "joinpath", "normpath", "relpath", "realpath", "relpathto"} +__MUTABLE_FUNCTIONS = { + "rename", + "renames", + "copy", + "copy2", + "copyfile", + "copymode", + "copystat", + "copytree", + "move", + "basename", + "abspath", + "join", + "joinpath", + "normpath", + "relpath", + "realpath", + "relpathto", +} def __is_mbm(member): @@ -77,7 +128,9 @@ def __wrap_decorator(self, *args, **kwargs): converter = __path_converter(self.clone) if isinstance(result, List) and not isinstance(result, (str, bytes, bytearray)): return list(map(converter, result)) - if isinstance(result, Iterable) and not isinstance(result, (str, bytes, bytearray)): + if isinstance(result, Iterable) and not isinstance( + result, (str, bytes, bytearray) + ): return (converter(g) for g in result) return __path_converter(self.clone)(result) @@ -94,17 +147,21 @@ def path_wrapper(cls): setattr(cls, name, __path_func(method)) member_names.append(name) for name, _ in inspect.getmembers(path.Path, __is_mbm): - if not name.startswith("_") \ - and name not in __EXCLUDE_FROM_WRAPPING \ - and name not in member_names: + if ( + not name.startswith("_") + and name not in __EXCLUDE_FROM_WRAPPING + and name not in member_names + ): method = getattr(path.Path, name) if not hasattr(cls, name): setattr(cls, name, wrap_attribute(method)) member_names.append(name) for name, _ in inspect.getmembers(pathlib.Path, __is_mbm): - if not name.startswith("_") \ - and name not in __EXCLUDE_FROM_WRAPPING \ - and name not in member_names: + if ( + not name.startswith("_") + and name not in __EXCLUDE_FROM_WRAPPING + and name not in member_names + ): method = getattr(pathlib.Path, name) if not hasattr(cls, name): setattr(cls, name, wrap_attribute(method, pathlib.Path)) diff --git a/mutapath/immutapath.py b/mutapath/immutapath.py index d92f077..6117cab 100644 --- a/mutapath/immutapath.py +++ b/mutapath/immutapath.py @@ -33,14 +33,19 @@ @path_wrapper class Path(SerializableType): """Immutable Path""" + _contained: Union[path.Path, pathlib.PurePath, str] = path.Path("") __always_posix_format: bool __string_repr: bool __mutable: object - def __init__(self, contained: Union[Path, path.Path, pathlib.PurePath, str] = "", *, - posix: Optional[bool] = None, - string_repr: Optional[bool] = None): + def __init__( + self, + contained: Union[Path, path.Path, pathlib.PurePath, str] = "", + *, + posix: Optional[bool] = None, + string_repr: Optional[bool] = None, + ): if posix is None: posix = PathDefaults().posix self.__always_posix_format = posix @@ -52,7 +57,11 @@ def __init__(self, contained: Union[Path, path.Path, pathlib.PurePath, str] = "" self._set_contained(contained, posix) super().__init__() - def _set_contained(self, contained: Union[Path, path.Path, pathlib.PurePath, str], posix: Optional[bool] = None): + def _set_contained( + self, + contained: Union[Path, path.Path, pathlib.PurePath, str], + posix: Optional[bool] = None, + ): if contained: if isinstance(contained, Path): contained = contained._contained @@ -85,15 +94,21 @@ def __setattr__(self, key, value): if self.lock.is_locked: self.lock.release() Path(self.lock.lock_file).remove_p() - del self.__dict__['lock'] + del self.__dict__["lock"] if isinstance(value, Path): value = value._contained self._set_contained(value) - elif key in ["_Path__mutable", "_Path__always_posix_format", "_Path__string_repr"]: + elif key in [ + "_Path__mutable", + "_Path__always_posix_format", + "_Path__string_repr", + ]: super(Path, self).__setattr__(key, value) else: - raise AttributeError(f"attribute {key} can not be set because mutapath.Path is an immutable class.") + raise AttributeError( + f"attribute {key} can not be set because mutapath.Path is an immutable class." + ) def __repr__(self): if self.__string_repr: @@ -126,9 +141,11 @@ def __eq__(self, other): return str(self) == str(other) def __hash__(self): - warnings.warn(f"It is not advised to hash mutable path objects or to use them in sets or dicts. " - f"Please use hash(str(path)) instead to make the actual hashing input transparent.", - category=SyntaxWarning) + warnings.warn( + f"It is not advised to hash mutable path objects or to use them in sets or dicts. " + f"Please use hash(str(path)) instead to make the actual hashing input transparent.", + category=SyntaxWarning, + ) return self._hash_cache @cached_property @@ -191,6 +208,7 @@ def __fspath__(self): def __invert__(self): """Create a cloned :class:`~mutapath.MutaPath` from this immutable Path.""" from mutapath import MutaPath + return MutaPath(self._contained, posix=self.posix_enabled) def _serialize(self) -> str: @@ -214,13 +232,15 @@ def clone(self, contained) -> Path: :param contained: the new contained path element :return: the cloned path """ - return Path(contained, posix=self.__always_posix_format, string_repr=self.__string_repr) + return Path( + contained, posix=self.__always_posix_format, string_repr=self.__string_repr + ) @path.multimethod def _shorten_duplicates(self, input_path: str = "") -> str: if isinstance(input_path, Path): input_path = input_path._contained - return input_path.replace('\\\\', '\\') + return input_path.replace("\\\\", "\\") @path.multimethod def posix_string(self, input_path: str = "") -> str: @@ -233,7 +253,7 @@ def posix_string(self, input_path: str = "") -> str: """ if isinstance(input_path, Path): input_path = input_path._contained - return input_path.replace('\\\\', '\\').replace('\\', '/') + return input_path.replace("\\\\", "\\").replace("\\", "/") def with_poxis_enabled(self, enable: bool = True) -> Path: """ @@ -425,15 +445,15 @@ def startfile(self): """ if self.isfile(): secure_path = self.abspath() - if ' ' in secure_path: + if " " in secure_path: return if os.name == "nt": os.startfile(secure_path) else: if sys.platform == "darwin": - args = ['open', secure_path] + args = ["open", secure_path] else: - args = ['xdg-open', secure_path] + args = ["xdg-open", secure_path] subprocess.call(args, shell=False) @cached_property @@ -494,9 +514,16 @@ def mutate(self): self._contained = self.__mutable._contained @contextmanager - def _op_context(self, name: str, timeout: float, lock: bool, - operation: - Callable[[Union[os.PathLike, path.Path], Union[os.PathLike, path.Path]], Union[str, path.Path]]): + def _op_context( + self, + name: str, + timeout: float, + lock: bool, + operation: Callable[ + [Union[os.PathLike, path.Path], Union[os.PathLike, path.Path]], + Union[str, path.Path], + ], + ): """ Acquire a file mutation context that is bound to a file. @@ -507,7 +534,9 @@ def _op_context(self, name: str, timeout: float, lock: bool, """ if not self._contained.exists(): - raise PathException(f"{name.capitalize()} {self._contained} failed because the file does not exist.") + raise PathException( + f"{name.capitalize()} {self._contained} failed because the file does not exist." + ) try: if lock: @@ -515,7 +544,8 @@ def _op_context(self, name: str, timeout: float, lock: bool, self.lock.acquire(timeout) except filelock.Timeout as t: raise PathException( - f"{name.capitalize()} {self._contained} failed because the file could not be locked.") from t + f"{name.capitalize()} {self._contained} failed because the file could not be locked." + ) from t self.__mutable = mutapath.MutaPath(self) yield self.__mutable @@ -529,12 +559,14 @@ def _op_context(self, name: str, timeout: float, lock: bool, except FileExistsError as e: raise PathException( f"{name.capitalize()} to {current_file.normpath()} failed because the file already exists. " - f"Falling back to original value {self._contained}.") from e + f"Falling back to original value {self._contained}." + ) from e if not current_file.exists(): raise PathException( f"{name.capitalize()} to {current_file.normpath()} failed because it can not be found. " - f"Falling back to original value {self._contained}.") + f"Falling back to original value {self._contained}." + ) self._contained = current_file @@ -542,7 +574,9 @@ def _op_context(self, name: str, timeout: float, lock: bool, if self.lock.is_locked: self.lock.release() - def renaming(self, lock=True, timeout=1, method: Callable[[str, str], None] = os.rename): + def renaming( + self, lock=True, timeout=1, method: Callable[[str, str], None] = os.rename + ): """ Create a renaming context for this immutable path. The external value is only changed if the renaming succeeds. @@ -565,7 +599,8 @@ def checked_rename(cls: path.Path, target: path.Path): target_lock.acquire(timeout) except filelock.Timeout as t: raise PathException( - f"Renaming {self._contained} failed because the target {target} could not be locked.") from t + f"Renaming {self._contained} failed because the target {target} could not be locked." + ) from t try: if target.exists(): raise FileExistsError(f"{target.name} already exists.") @@ -576,9 +611,16 @@ def checked_rename(cls: path.Path, target: path.Path): target_lock_file.remove_p() return target - return self._op_context("Renaming", lock=lock, timeout=timeout, operation=checked_rename) + return self._op_context( + "Renaming", lock=lock, timeout=timeout, operation=checked_rename + ) - def moving(self, lock=True, timeout=1, method: Callable[[os.PathLike, os.PathLike], str] = shutil.move): + def moving( + self, + lock=True, + timeout=1, + method: Callable[[os.PathLike, os.PathLike], str] = shutil.move, + ): """ Create a moving context for this immutable path. The external value is only changed if the moving succeeds. @@ -594,7 +636,9 @@ def moving(self, lock=True, timeout=1, method: Callable[[os.PathLike, os.PathLik """ return self._op_context("Moving", operation=method, lock=lock, timeout=timeout) - def copying(self, lock=True, timeout=1, method: Callable[[Path, Path], Path] = shutil.copy): + def copying( + self, lock=True, timeout=1, method: Callable[[Path, Path], Path] = shutil.copy + ): """ Create a copying context for this immutable path. The external value is only changed if the copying succeeds. diff --git a/mutapath/lock_dummy.py b/mutapath/lock_dummy.py index d17da89..a99218b 100644 --- a/mutapath/lock_dummy.py +++ b/mutapath/lock_dummy.py @@ -2,7 +2,6 @@ class DummyFileLock(BaseFileLock): - def release(self, force=False): """Doing nothing""" diff --git a/mutapath/mutapath.py b/mutapath/mutapath.py index 26f67a1..3ecfe9a 100644 --- a/mutapath/mutapath.py +++ b/mutapath/mutapath.py @@ -13,9 +13,15 @@ class MutaPath(mutapath.Path): """Mutable Path""" - def __init__(self, contained: Union[MutaPath, mutapath.Path, path.Path, pathlib.PurePath, str] = "", *, - posix: Optional[bool] = None, - string_repr: Optional[bool] = None): + def __init__( + self, + contained: Union[ + MutaPath, mutapath.Path, path.Path, pathlib.PurePath, str + ] = "", + *, + posix: Optional[bool] = None, + string_repr: Optional[bool] = None, + ): if isinstance(contained, MutaPath): contained = contained._contained super(MutaPath, self).__init__(contained, posix=posix, string_repr=string_repr) diff --git a/tests/helper.py b/tests/helper.py index 9ce70ee..9fc9609 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -30,16 +30,21 @@ def typed_instance_test(self, *instance): self.assertIsInstance(i, Path) self.assertIsInstance(i._contained, path.Path) - def arg_with_matrix(self, with_func: Callable[[Path, bool], Path], - test_func: Optional[Callable[[Path], bool]] = None, - with_func_default: bool = True, **kwargs): + def arg_with_matrix( + self, + with_func: Callable[[Path, bool], Path], + test_func: Optional[Callable[[Path], bool]] = None, + with_func_default: bool = True, + **kwargs, + ): """ Use a matrix of keyed init arguments with their immutable with methods. The first passed keyed argument should relate to the with method. """ if len(kwargs) < 1: raise ValueError( - "The matrix requires at least the init value and its default that correlates with the with method.") + "The matrix requires at least the init value and its default that correlates with the with method." + ) first_key = next(iter(kwargs)) first_default = kwargs[first_key] @@ -76,7 +81,9 @@ def arg_with_matrix(self, with_func: Callable[[Path, bool], Path], self.assertFalse(test_func(with_disabled.clone("/"))) -def file_test(equal=True, instance=True, exists=True, posix_test=True, string_test=True): +def file_test( + equal=True, instance=True, exists=True, posix_test=True, string_test=True +): def file_test_decorator(func): @wraps(func) def func_wrapper(cls: PathTest): @@ -84,7 +91,10 @@ def test_case(use_posix: bool = False, use_string: bool = False) -> Path: actual = cls._gen_start_path(use_posix, use_string) expected = func(cls, actual) if equal: - cls.assertIsNotNone(expected, "This test does not return the expected value. Fix the test.") + 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) @@ -96,10 +106,15 @@ def test_case(use_posix: bool = False, use_string: bool = False) -> Path: test_case() if posix_test: test_path = test_case(use_posix=True) - cls.assertTrue(test_path.posix_enabled, "the test file is not in posix format") + cls.assertTrue( + test_path.posix_enabled, "the test file is not in posix format" + ) if string_test: test_path = test_case(use_string=True) - cls.assertTrue(test_path.string_repr_enabled, "the test file is not using string representation") + cls.assertTrue( + test_path.string_repr_enabled, + "the test file is not using string representation", + ) finally: cls._clean() diff --git a/tests/test_immutapath.py b/tests/test_immutapath.py index 96a8ded..54d83d8 100644 --- a/tests/test_immutapath.py +++ b/tests/test_immutapath.py @@ -15,7 +15,7 @@ def test_with_name_posix(self): self.typed_instance_test(actual) def test_with_name_win(self): - if os.name == 'nt': + if os.name == "nt": expected = Path("C:/B/other") actual = Path("C:/B/test1.txt").with_name("other") self.assertEqual(expected, actual) @@ -34,16 +34,18 @@ def test_with_base_length_posix(self): self.typed_instance_test(actual) def test_with_base_win(self): - if os.name == 'nt': + if os.name == "nt": expected = Path("C:/Users/joe/folder/sub") actual = Path("C:/Users/doe/folder/sub").with_base("C:/Users/joe") self.assertEqual(expected, actual) self.typed_instance_test(actual) def test_with_base_length_win(self): - if os.name == 'nt': + if os.name == "nt": expected = Path("C:/Users/joe/doe/folder/sub").abspath() - actual = Path("C:/Users/doe/folder/sub").abspath().with_base("C:/Users/joe", 1) + actual = ( + Path("C:/Users/doe/folder/sub").abspath().with_base("C:/Users/joe", 1) + ) self.assertEqual(expected, actual) self.typed_instance_test(actual) @@ -69,30 +71,54 @@ def _string_repr_enabled(path: Path): return path.string_repr_enabled def test_with_string_repr_enabled(self): - self.arg_with_matrix(Path.with_string_repr_enabled, self._string_repr_enabled, string_repr=False) - self.arg_with_matrix(Path.with_string_repr_enabled, self._string_repr_enabled, string_repr=False, posix=False) - self.arg_with_matrix(Path.with_string_repr_enabled, self._string_repr_enabled, string_repr=False, posix=True) + self.arg_with_matrix( + Path.with_string_repr_enabled, self._string_repr_enabled, string_repr=False + ) + self.arg_with_matrix( + Path.with_string_repr_enabled, + self._string_repr_enabled, + string_repr=False, + posix=False, + ) + self.arg_with_matrix( + Path.with_string_repr_enabled, + self._string_repr_enabled, + string_repr=False, + posix=True, + ) def test_defaults_with_string_repr(self): getter = lambda p: p.string_repr_enabled PathDefaults().string_repr = True self.arg_with_matrix(Path.with_string_repr_enabled, getter, string_repr=True) - self.arg_with_matrix(Path.with_string_repr_enabled, getter, string_repr=True, posix=False) - self.arg_with_matrix(Path.with_string_repr_enabled, getter, string_repr=True, posix=True) + self.arg_with_matrix( + Path.with_string_repr_enabled, getter, string_repr=True, posix=False + ) + self.arg_with_matrix( + Path.with_string_repr_enabled, getter, string_repr=True, posix=True + ) PathDefaults().reset() def test_with_posix_enabled(self): getter = lambda p: p.posix_enabled self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=False) - self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=False, string_repr=False) - self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=False, string_repr=True) + self.arg_with_matrix( + Path.with_poxis_enabled, getter, posix=False, string_repr=False + ) + self.arg_with_matrix( + Path.with_poxis_enabled, getter, posix=False, string_repr=True + ) def test_defaults_with_posix(self): getter = lambda p: p.posix_enabled PathDefaults().posix = True self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=True) - self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=True, string_repr=False) - self.arg_with_matrix(Path.with_poxis_enabled, getter, posix=True, string_repr=True) + self.arg_with_matrix( + Path.with_poxis_enabled, getter, posix=True, string_repr=False + ) + self.arg_with_matrix( + Path.with_poxis_enabled, getter, posix=True, string_repr=True + ) PathDefaults().reset() def test_static_joinpath(self): @@ -135,7 +161,7 @@ def posix_path(contain): constructors = [posix_path, Path, MutaPath] comparable_constructors = constructors + [path.Path, pathlib.Path, str] containers = ["/A/B/other.txt"] - if os.name == 'nt': + if os.name == "nt": containers += ["/A\\B/other.txt", "\\A\\B\\other.txt"] paths = list() @@ -151,7 +177,9 @@ def posix_path(contain): for l_const, l in paths: for r_const, r in comparables: - self.assertEqual(l, r, f"{l_const} is not equalling comparable {r_const}") + self.assertEqual( + l, r, f"{l_const} is not equalling comparable {r_const}" + ) def test_add(self): expected = "/A/B/other.txt" @@ -205,7 +233,7 @@ def test_parents(self): self.typed_instance_test(actual[0]) def test_anchor(self): - if os.name == 'nt': + if os.name == "nt": excpected = "C:\\" actual = Path("C:/A/B/C").anchor else: diff --git a/tests/test_mutapath.py b/tests/test_mutapath.py index 5775984..56ffc25 100644 --- a/tests/test_mutapath.py +++ b/tests/test_mutapath.py @@ -1,7 +1,9 @@ from mutapath import MutaPath, Path from tests.helper import PathTest, file_test -file_test_no_asserts = file_test(equal=False, instance=False, exists=False, posix_test=False, string_test=False) +file_test_no_asserts = file_test( + equal=False, instance=False, exists=False, posix_test=False, string_test=False +) class TestMutaPath(PathTest): @@ -10,7 +12,11 @@ def __init__(self, *args): super().__init__(*args) def _gen_start_path(self, posix: bool = False, use_string: bool = False): - return MutaPath(super(TestMutaPath, self)._gen_start_path(posix), posix=posix, string_repr=use_string) + return MutaPath( + super(TestMutaPath, self)._gen_start_path(posix), + posix=posix, + string_repr=use_string, + ) @file_test_no_asserts def test_suffix(self, test_file: Path): @@ -113,7 +119,7 @@ def test_copyfile(self, test_file: Path): @file_test(equal=False) def test_copytree(self, test_file: Path): - from_here = ~ (self.test_base / "from/here") + from_here = ~(self.test_base / "from/here") from_here.makedirs() test_file.copy(from_here) expected = self.test_base / "to" @@ -124,20 +130,22 @@ def test_copytree(self, test_file: Path): @file_test(equal=False, exists=False) def test_move(self, test_file: Path): from_here = self.test_base / "from/here" - current = ~ from_here + current = ~from_here current.makedirs() test_file.copy(current) expected = self.test_base / "to" current.move(expected) self.assertEqual(expected, current) self.assertIsInstance(current, MutaPath) - self.assertTrue(not from_here.exists(), "The moved file still exists in the source folder.") + self.assertTrue( + not from_here.exists(), "The moved file still exists in the source folder." + ) target_not_empty = len(current.files("test.file*")) > 0 self.assertTrue(target_not_empty, "The target file does not exist.") @file_test(equal=False) def test_merge_tree(self, test_file: Path): - from_here = ~ (self.test_base / "from/here") + from_here = ~(self.test_base / "from/here") from_here.makedirs() test_file.copy(from_here) expected = self.test_base / "to" diff --git a/tests/test_serializable.py b/tests/test_serializable.py index 9d2ee33..fe63fae 100644 --- a/tests/test_serializable.py +++ b/tests/test_serializable.py @@ -13,26 +13,26 @@ class DataClass(DataClassDictMixin): class TestSerialization(PathTest): def test_empty_serialization(self): - expected = {'path': ''} + expected = {"path": ""} actual = DataClass().to_dict() self.assertEqual(expected, actual) def test_serialization(self): - expected = {'path': "/A/B/test1.txt"} + expected = {"path": "/A/B/test1.txt"} actual = DataClass(Path("/A/B/test1.txt", posix=True)).to_dict() self.assertEqual(expected, actual) def test_empty_deserialization(self): expected = DataClass() - actual = DataClass().from_dict({'path': ''}) + actual = DataClass().from_dict({"path": ""}) self.assertEqual(expected, actual) def test_deserialization(self): expected = DataClass(Path("/A/B/test1.txt", posix=True)) - actual = DataClass().from_dict({'path': "/A/B/test1.txt"}) + actual = DataClass().from_dict({"path": "/A/B/test1.txt"}) self.assertEqual(expected, actual) def test_deserialization_static(self): expected = DataClass(Path("/A/B/test1.txt", posix=True)) - actual = DataClass.from_dict({'path': "/A/B/test1.txt"}) + actual = DataClass.from_dict({"path": "/A/B/test1.txt"}) self.assertEqual(expected, actual) diff --git a/tests/test_with_path.py b/tests/test_with_path.py index 3bde8fc..e43a211 100644 --- a/tests/test_with_path.py +++ b/tests/test_with_path.py @@ -135,7 +135,7 @@ def test_renaming_source_missing(self, test_file: Path): """Try renaming when the source file is missing""" with test_file.mutate() as mut: mut.name = "wrong.txt" - expected = ~ test_file + expected = ~test_file with self.assertRaises(PathException): with test_file.renaming() as mut: mut.name = expected.name @@ -144,7 +144,7 @@ def test_renaming_source_missing(self, test_file: Path): @file_test() def test_renaming_source_lock_fail(self, test_file: Path): """Try renaming when there is already a lock on the source file""" - expected = ~ test_file + expected = ~test_file anything = test_file.with_name("anything.txt") with expected.lock: with self.assertRaises(PathException): @@ -155,7 +155,7 @@ def test_renaming_source_lock_fail(self, test_file: Path): @file_test() def test_renaming_without_lock(self, test_file: Path): """Try renaming when lock=False even though there is already a lock on the source and the target file""" - expected = ~ test_file + expected = ~test_file target = test_file.with_name("target.txt").touch() with expected.lock: with target.lock: @@ -167,7 +167,7 @@ def test_renaming_without_lock(self, test_file: Path): @file_test() def test_renaming_target_lock_fail(self, test_file: Path): """Try renaming to a path for which there is already a lock but not a file itself""" - expected = ~ test_file + expected = ~test_file target = test_file.with_name("target.txt").touch() with target.lock: target.remove() @@ -179,14 +179,18 @@ def test_renaming_target_lock_fail(self, test_file: Path): @file_test() def test_lock_changes_with_mutation(self, test_file: Path): """Assure that the lock changes after the path has been mutated""" - expected = ~ test_file.with_name("target.txt") + expected = ~test_file.with_name("target.txt") first_lock = test_file.lock with test_file.renaming(timeout=0.1) as mut: mut.name = "target.txt" second_lock = test_file.lock self.assertNotEqual(first_lock.lock_file, second_lock.lock_file) - self.assertFalse(first_lock.is_locked, "the origin lock file should not be locked anymore") - self.assertFalse(second_lock.is_locked, "the target lock file should not be locked anymore") + self.assertFalse( + first_lock.is_locked, "the origin lock file should not be locked anymore" + ) + self.assertFalse( + second_lock.is_locked, "the target lock file should not be locked anymore" + ) return expected @file_test()