-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_plot_climate_data_good.py
More file actions
50 lines (36 loc) · 1.11 KB
/
test_plot_climate_data_good.py
File metadata and controls
50 lines (36 loc) · 1.11 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
"""
Tests for plot_climate_data_good.py
"""
from pathlib import Path
import pandas as pd
import pytest
from plot_climate_data_good import (
calculate_mean_maximum_temperature,
get_station_name,
read_metoffice_file,
)
def test_get_station_name():
# Arrange
test_data_file = Path("someplacedata.txt")
expected_name = "someplace"
# Act
station_name = get_station_name(test_data_file)
# Assert
assert station_name == expected_name
def test_read_met_office_file():
# Arrange
test_data_file = Path(__file__).parent / "exampledata.txt"
# Act
data = read_metoffice_file(test_data_file)
# Assert
assert isinstance(data, pd.DataFrame)
assert data.index.name == 'date'
assert data.columns.to_list() == ['tmax', 'tmin', 'frost_days', 'rain_mm', 'sun']
def test_calculate_mean_maximum_temperature():
# Arrange
test_data_file = Path(__file__).parent / "exampledata.txt"
# Act
data = read_metoffice_file(test_data_file)
mean_max_temp = calculate_mean_maximum_temperature(data)
# Assert
assert mean_max_temp == pytest.approx(12.35, abs=0.01)