-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_assignment.py
More file actions
78 lines (49 loc) · 1.55 KB
/
test_assignment.py
File metadata and controls
78 lines (49 loc) · 1.55 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import pytest
from assignment import Widget
def test_widget(widget_parameters):
task = Widget()
output = task.run(widget_parameters)
assert len(output) == 1
text = output[0].decode()
assert text == "Peter Parker"
def test_widget_runs_locally(local_environment):
filename = local_environment.get('PARAMETER_FILE')
task = Widget()
output = task.run_locally(filename)
text = output[0].decode()
assert text == "Penny Parker"
def test_widget_runs_in_batch(batch_environment):
filename = batch_environment.get('PARAMETER_DATABASE')
task = Widget()
output = task.run_in_batch(filename)
text = output[0].decode()
assert text == "Peter Porker"
def test_widget_runs_in_lambda(lambda_event):
task = Widget()
output = task.run_from_lambda(lambda_event)
text = output[0].decode()
assert text == "Miles Morales"
@pytest.fixture
def widget_parameters():
return {
"first_name": "Peter",
"last_name": "Parker"
}
@pytest.fixture
def local_environment():
current_environment = os.environ.copy()
os.environ["PARAMETER_FILE"] = 'parameters.json'
yield os.environ
os.environ.clear()
os.environ.update(current_environment)
@pytest.fixture
def batch_environment():
current_environment = os.environ.copy()
os.environ["PARAMETER_DATABASE"] = 'configuration_db.json'
yield os.environ
os.environ.clear()
os.environ.update(current_environment)
@pytest.fixture
def lambda_event():
return {"first_name": "Miles", "last_name": "Morales"}