Skip to content

Commit

Permalink
Test with a correct escape character
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 26, 2024
1 parent f9a3e8c commit 7ac0790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 15 additions & 8 deletions target_csv/serialization.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7ac0790

Please sign in to comment.