From 7ac079070d32d683ebafc19438cc90cd2f737237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Mon, 26 Aug 2024 13:34:57 -0600 Subject: [PATCH] Test with a correct escape character --- target_csv/serialization.py | 23 +++++++++++++++-------- tests/test_core.py | 4 +--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/target_csv/serialization.py b/target_csv/serialization.py index 660874d..3ee87a0 100644 --- a/target_csv/serialization.py +++ b/target_csv/serialization.py @@ -1,18 +1,25 @@ import csv # noqa: D100 +import sys from pathlib import Path -from typing import Any, List, Callable +from typing import Any, List, Callable, TypeVar +if sys.version_info < (3, 10): + from typing_extensions import Concatenate, ParamSpec +else: + from typing import Concatenate, ParamSpec -def create_folder_if_not_exists(func: Any) -> Callable[..., int]: +P = ParamSpec("P") +T = TypeVar("T") + + +def create_folder_if_not_exists( + func: Callable[Concatenate[Path, P], T], +) -> Callable[Concatenate[Path, P], T]: """Decorator to create folder if it does not exist.""" - def wrapper(*args: Any, **kwargs: Any) -> int: - try: - filepath = Path(kwargs["filepath"]) - except KeyError: - filepath = Path(args[0]) + def wrapper(filepath: Path, *args: P.args, **kwargs: P.kwargs) -> T: filepath.parent.mkdir(parents=True, exist_ok=True) - return func(*args, **kwargs) + return func(filepath, *args, **kwargs) return wrapper diff --git a/tests/test_core.py b/tests/test_core.py index bc7fce0..6892891 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -16,9 +16,7 @@ else: from importlib_resources import files -SAMPLE_CONFIG: Dict[str, Any] = { - "escape_character": '"', -} +SAMPLE_CONFIG: Dict[str, Any] = {} class MultipleStreamsTest(TargetFileTestTemplate):