-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathtest_cli.py
More file actions
134 lines (123 loc) · 4.02 KB
/
Copy pathtest_cli.py
File metadata and controls
134 lines (123 loc) · 4.02 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import shutil
import mock
import matplotlib.pyplot as plt
import pytest
from ramp.cli import parser as ramp_parser, main as ramp_main
from .utils import TEST_PATH, TEST_OUTPUT_PATH
class TestProcessUserArguments:
def setup_method(self):
if os.path.exists(TEST_OUTPUT_PATH):
shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)
if os.path.exists(TEST_OUTPUT_PATH) is False:
os.mkdir(TEST_OUTPUT_PATH)
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
["--start-date", "2022-01-01", "-y", "2022"]
),
)
def test_impossible_option_combinaison_start_date_year(self, m_args):
with pytest.raises(ValueError):
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(["--end-date", "2022-01-01", "-y", "2022"]),
)
def test_impossible_option_combinaison_end_date_year(self, m_args):
with pytest.raises(ValueError):
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
[
"-i",
os.path.join(TEST_PATH, "test_inputs", "example_excel_usecase.xlsx"),
"-y",
"2022",
"2023",
"-o",
os.path.join(TEST_OUTPUT_PATH, "example_excel.csv"),
]
),
)
def test_multiple_year_is_possible_xlsx_file(self, m_args, monkeypatch):
monkeypatch.setattr(
plt, "show", lambda: None
) # prevents the test to output figure
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
[
"-i",
os.path.join(TEST_PATH, "test_inputs", "example_ods_usecase.ods"),
"-y",
"2022",
"-o",
os.path.join(TEST_OUTPUT_PATH, "example_ods.csv"),
]
),
)
def test_read_year_power_input_ods_file(self, m_args, monkeypatch):
monkeypatch.setattr(
plt, "show", lambda: None
) # prevents the test to output figure
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
[
"-i",
os.path.join(TEST_PATH, "test_inputs", "example_csv_usecase.csv"),
"-y",
"2022",
"-o",
os.path.join(TEST_OUTPUT_PATH, "example_csv.csv"),
]
),
)
def test_read_year_power_input_csv_file(self, m_args, monkeypatch):
monkeypatch.setattr(
plt, "show", lambda: None
) # prevents the test to output figure
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
[
"-i",
os.path.join(TEST_OUTPUT_PATH),
"-y",
"2022",
"-n",
"1",
]
),
)
def test_month_variation_without_month_files(self, m_args):
with pytest.raises(ValueError):
ramp_main()
@mock.patch(
"argparse.ArgumentParser.parse_args",
return_value=ramp_parser.parse_args(
[
"-i",
os.path.join(TEST_OUTPUT_PATH),
"-y",
"2022",
"-n",
"1",
]
),
)
def test_month_variation_with_month_files(self, m_args):
for i in range(12):
shutil.copy(
os.path.join(TEST_PATH, "test_inputs", "example_excel_usecase.xlsx"),
os.path.join(TEST_OUTPUT_PATH, f"example_excel_usecase_{i}.xlsx"),
)
ramp_main()
def teardown_method(self):
if os.path.exists(TEST_OUTPUT_PATH):
shutil.rmtree(TEST_OUTPUT_PATH, ignore_errors=True)