forked from UCL-COMP0233-24-25/time-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_with_param.py
32 lines (24 loc) · 907 Bytes
/
test_with_param.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
import pytest
import yaml
from times import time_range, compute_overlap_time
# load fixture.yaml
def load_yaml_data():
with open("fixture.yaml", "r") as file:
return yaml.safe_load(file)
# parametrization
yaml_data = load_yaml_data()
@pytest.mark.parametrize("test_case", yaml_data)
def test_compute_overlap_time(test_case):
# time ranges and expected results
case_data = list(test_case.values())[0]
time_range_1 = case_data["time_range_1"]
time_range_2 = case_data["time_range_2"]
expected = [tuple(pair) for pair in case_data["expected"]]
range1 = time_range(*time_range_1)
range2 = time_range(*time_range_2)
result = compute_overlap_time(range1, range2)
assert result == expected
def test_input_validation():
with pytest.raises(ValueError):
# End time before start time
time_range("2023-10-20 12:00:00", "2023-10-20 10:00:00")