-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_utils.py
52 lines (42 loc) · 1.22 KB
/
test_utils.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
from typing import Dict, Union
import pytest
from microarchive import MicroArchive, Identity, Description, Contact, Item, Control
@pytest.fixture
def archive():
return MicroArchive(
identity=Identity(
title="Test",
extent="1 box"
),
description=Description(
scope="Paragraph 1\n\nParagraph 2"
),
contact=Contact(
street="1 Acacia Av."
),
control=Control(
notes="Test Note"
),
items=[
Item.make(id="Dir1/Dir1-1/item1", identity=Identity(title="Item1")),
Item.make(id="Dir1/item2", identity=Identity(title="Item2")),
Item.make(id="Dir2/Dir2-1/item3", identity=Identity(title="Item3")),
Item.make(id="Dir2/item4", identity=Identity(title="Item4")),
]
)
def key_exists(data: Dict, *keys: Union[str, int]):
elem = data
for key in keys:
try:
elem = elem[key]
except KeyError:
return False
return True
def value_of(data: Dict, *keys: Union[str, int]):
elem = data
for key in keys:
try:
elem = elem[key]
except KeyError:
return None
return elem