/
test_PlotGrid.py
124 lines (96 loc) · 4.46 KB
/
test_PlotGrid.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
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
# Copyright (c) 2019-2020, RTE (https://www.rte-france.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
# you can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
from abc import ABC, abstractmethod
import unittest
import warnings
from grid2op.Exceptions import *
from grid2op.MakeEnv import make
from grid2op.Parameters import Parameters
from grid2op.dtypes import dt_float
from grid2op.PlotGrid import *
import warnings
warnings.simplefilter("error")
class BaseTestPlot(ABC):
def setUp(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.env = make("rte_case14_redisp", test=True)
self.obs = self.env.current_obs
self.plot = self._plotter(self.env.observation_space)
def tearDown(self):
self.env.close()
@abstractmethod
def _plotter(self, obs_space):
pass
def test_plot_layout(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_layout()
def test_plot_info_line(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_info(line_values=self.obs.rho, gen_values=None, load_values=None)
def test_plot_info_gen(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_info(line_values=None, gen_values=self.obs.prod_q, load_values=None)
def test_plot_info_load(self):
self.plot.plot_info(line_values=None, gen_values=None, load_values=self.obs.load_q)
def test_plot_obs_default(self):
self.plot.plot_obs(self.obs)
def test_plot_obs_volts(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="v", gen_info="v", load_info="v")
def test_plot_obs_invalid_line(self):
with self.assertRaises(PlotError):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="error", gen_info="v", load_info="v")
def test_plot_obs_no_line(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info=None, gen_info="p", load_info="p")
def test_plot_obs_invalid_gen(self):
with self.assertRaises(PlotError):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="v", gen_info="error", load_info="v")
def test_plot_obs_no_gen(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="rho", gen_info=None, load_info="p")
def test_plot_obs_invalid_load(self):
with self.assertRaises(PlotError):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="rho", gen_info="v", load_info="error")
def test_plot_obs_no_load(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="v", gen_info="v", load_info=None)
def test_plot_obs_line(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info="a", gen_info=None, load_info=None)
def test_plot_obs_gen(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info=None, gen_info="p", load_info=None)
def test_plot_obs_load(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.plot.plot_obs(self.obs, line_info=None, gen_info=None, load_info="p")
class TestPlotMatplot(BaseTestPlot, unittest.TestCase):
def _plotter(self, obs_space):
return PlotMatplot(obs_space)
class TestPlotPlotly(BaseTestPlot, unittest.TestCase):
def _plotter(self, obs_space):
return PlotPlotly(obs_space)
if __name__ == "__main__":
unittest.main()