-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtest_in_memory_target.py
56 lines (45 loc) · 1.72 KB
/
test_in_memory_target.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime
from time import sleep
import pytest
from gokart.conflict_prevention_lock.task_lock import TaskLockParams
from gokart.in_memory import InMemoryCacheRepository, InMemoryTarget, make_in_memory_target
class TestInMemoryTarget:
@pytest.fixture
def task_lock_params(self) -> TaskLockParams:
return TaskLockParams(
redis_host=None,
redis_port=None,
redis_timeout=None,
redis_key='dummy',
should_task_lock=False,
raise_task_lock_exception_on_collision=False,
lock_extend_seconds=0,
)
@pytest.fixture
def target(self, task_lock_params: TaskLockParams) -> InMemoryTarget:
return make_in_memory_target(data_key='dummy_key', task_lock_params=task_lock_params)
@pytest.fixture(autouse=True)
def clear_repo(self) -> None:
InMemoryCacheRepository().clear()
def test_dump_and_load_data(self, target: InMemoryTarget):
dumped = 'dummy_data'
target.dump(dumped)
loaded = target.load()
assert loaded == dumped
def test_exist(self, target: InMemoryTarget):
assert not target.exists()
target.dump('dummy_data')
assert target.exists()
def test_last_modified_time(self, target: InMemoryTarget):
input = 'dummy_data'
target.dump(input)
time = target.last_modification_time()
assert isinstance(time, datetime)
sleep(0.1)
another_input = 'another_data'
target.dump(another_input)
another_time = target.last_modification_time()
assert time < another_time
target.remove()
with pytest.raises(ValueError):
assert target.last_modification_time()