added tmpdir
All checks were successful
CI / build (push) Successful in 12s

This commit is contained in:
2024-06-24 20:35:38 +08:00
parent 07e511ae2c
commit 29dd81159c
2 changed files with 28 additions and 4 deletions

View File

@@ -1,4 +1,11 @@
from .private import format_filesize, async_retry, retry, async_test, ExceptionHandlerOutcome
from .private import (
format_filesize,
async_retry,
retry,
async_test,
ExceptionHandlerOutcome,
tmpdir
)
from .maybe import Maybe
__all__ = [
@@ -7,5 +14,6 @@ __all__ = [
'retry',
'async_test',
'ExceptionHandlerOutcome',
'Maybe'
'Maybe',
'tmpdir'
]

View File

@@ -1,4 +1,6 @@
import math
from tempfile import TemporaryDirectory
from pathlib import Path
from enum import Enum, auto
from typing import Callable
from time import sleep
@@ -17,7 +19,6 @@ def format_filesize(size: int) -> str:
return '%.2f ' % (size / math.pow(1024, counter)) + _size_uoms[counter]
class ExceptionHandlerOutcome(Enum):
THROW = auto()
CONTINUE = auto()
@@ -75,8 +76,23 @@ def async_retry(
return wrapper
def async_test(coro):
def wrapper(*args, **kwargs):
with Runner() as runner:
runner.run(coro(*args, **kwargs))
return wrapper
return wrapper
def tmpdir(argument_name='tmpdir'):
def wrapper(fun):
def result(*args, **kwargs):
with TemporaryDirectory() as temp_dir:
fun(*args, **kwargs, **{
argument_name: Path(temp_dir)
})
return result
return wrapper