|
| 1 | +# Copyright (c) 2019-2020, RTE (https://www.rte-france.com) |
| 2 | +# See AUTHORS.txt |
| 3 | +# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. |
| 4 | +# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, |
| 5 | +# you can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | +# SPDX-License-Identifier: MPL-2.0 |
| 7 | +# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems. |
| 8 | + |
| 9 | +""" |
| 10 | +This script provides a way to run the tests performed by grid2Op for the backend. |
| 11 | +
|
| 12 | +These tests are not 100% complete (some things might not be tested and are tested somewhere else) |
| 13 | +but they cover a big part of what the backend is expected to do. |
| 14 | +
|
| 15 | +YOU NEED TO INSTALL GRID2OP FROM THE GITHUB REPO FOR THIS TO WORK ! |
| 16 | +To do that, simply: |
| 17 | +
|
| 18 | +1) clone grid2op repo |
| 19 | +2) cd there |
| 20 | +3) run `pip install -e .` |
| 21 | +
|
| 22 | +(do this in a venv preferably) |
| 23 | +""" |
| 24 | + |
| 25 | +import unittest |
| 26 | +import warnings |
| 27 | + |
| 28 | +# first the backend class (for the example here) |
| 29 | +from Step5_modify_topology import CustomBackend_Minimal |
| 30 | + |
| 31 | +# then some required things |
| 32 | +from grid2op.tests.helper_path_test import PATH_DATA_TEST_PP, PATH_DATA_TEST |
| 33 | +from grid2op.tests.helper_path_test import HelperTests |
| 34 | +PATH_DATA_TEST_INIT = PATH_DATA_TEST |
| 35 | +PATH_DATA_TEST = PATH_DATA_TEST_PP |
| 36 | + |
| 37 | +# then all the tests that can be automatically performed |
| 38 | +from grid2op.tests.BaseBackendTest import BaseTestNames, BaseTestLoadingCase, BaseTestLoadingBackendFunc |
| 39 | +from grid2op.tests.BaseBackendTest import BaseTestTopoAction, BaseTestEnvPerformsCorrectCascadingFailures |
| 40 | +from grid2op.tests.BaseBackendTest import BaseTestChangeBusAffectRightBus, BaseTestShuntAction |
| 41 | +from grid2op.tests.BaseBackendTest import BaseTestResetEqualsLoadGrid, BaseTestVoltageOWhenDisco, BaseTestChangeBusSlack |
| 42 | +from grid2op.tests.BaseBackendTest import BaseIssuesTest, BaseStatusActions |
| 43 | +from grid2op.tests.test_Environment import (TestLoadingBackendPandaPower as BaseTestLoadingBackendPandaPower, |
| 44 | + TestResetOk as BaseTestResetOk) |
| 45 | +from grid2op.tests.test_Environment import (TestResetAfterCascadingFailure as TestResetAfterCascadingFailure, |
| 46 | + TestCascadingFailure as BaseTestCascadingFailure) |
| 47 | +from grid2op.tests.BaseRedispTest import BaseTestRedispatch, BaseTestRedispatchChangeNothingEnvironment |
| 48 | +from grid2op.tests.BaseRedispTest import BaseTestRedispTooLowHigh, BaseTestDispatchRampingIllegalETC |
| 49 | +from grid2op.tests.BaseRedispTest import BaseTestLoadingAcceptAlmostZeroSumRedisp |
| 50 | + |
| 51 | +# then still some glue code, mainly for the names of the time series |
| 52 | +from grid2op.Converter import BackendConverter |
| 53 | +from grid2op.Backend import PandaPowerBackend |
| 54 | + |
| 55 | +# our backend does not read the names from the grid, so this test is not relevant |
| 56 | +# class TestNames(HelperTests, BaseTestNames): |
| 57 | +# def make_backend(self, detailed_infos_for_cascading_failures=False): |
| 58 | +# with warnings.catch_warnings(): |
| 59 | +# warnings.filterwarnings("ignore") |
| 60 | +# bk = BackendConverter(source_backend_class=CustomBackend_Minimal, |
| 61 | +# target_backend_class=PandaPowerBackend, |
| 62 | +# use_target_backend_name=True, |
| 63 | +# detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) |
| 64 | +# return bk |
| 65 | + |
| 66 | +# def get_path(self): |
| 67 | +# return PATH_DATA_TEST_INIT |
| 68 | + |
| 69 | +class TestLoadingCase(HelperTests, BaseTestLoadingCase): |
| 70 | + def make_backend(self, detailed_infos_for_cascading_failures=False): |
| 71 | + with warnings.catch_warnings(): |
| 72 | + warnings.filterwarnings("ignore") |
| 73 | + bk = BackendConverter(source_backend_class=CustomBackend_Minimal, |
| 74 | + target_backend_class=PandaPowerBackend, |
| 75 | + use_target_backend_name=True, |
| 76 | + detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) |
| 77 | + return bk |
| 78 | + |
| 79 | + def get_path(self): |
| 80 | + return PATH_DATA_TEST |
| 81 | + |
| 82 | + def get_casefile(self): |
| 83 | + return "test_case14.json" |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == "__main__": |
| 87 | + unittest.main() |
0 commit comments