def test_zones_from_geometries_exist(self): world_geometries = json.load(open("web/geo/world.geojson")) world_geometries_zone_keys = set() for ft in world_geometries["features"]: world_geometries_zone_keys.add(ft["properties"]["zoneName"]) all_zone_keys = set(ZONES_CONFIG.keys()) non_existing_zone_keys = sorted(world_geometries_zone_keys - all_zone_keys) assert ( len(non_existing_zone_keys) == 0 ), f"{non_existing_zone_keys} are defined in world.geojson but not in zones.json"
def _load_config_model() -> ConfigModel: for zone_key, zone in ZONES_CONFIG.items(): zone["key"] = zone_key return ConfigModel(exchanges=EXCHANGES_CONFIG, zones=ZONES_CONFIG)
import unittest from electricitymap.contrib.config import EXCHANGES_CONFIG, ZONES_CONFIG ZONE_KEYS = ZONES_CONFIG.keys() class ExchangeJsonTestcase(unittest.TestCase): def test_all_zones_in_zones_json(self): for zone_key, values in EXCHANGES_CONFIG.items(): self.assertIn("->", zone_key) for zone in zone_key.split("->"): if zone == "US": # Old US zone that we ignore continue self.assertIn(zone, ZONE_KEYS) if __name__ == "__main__": unittest.main(buffer=True)
PRICE_PARSERS = {} CONSUMPTION_FORECAST_PARSERS = {} GENERATION_FORECAST_PARSERS = {} EXCHANGE_FORECAST_PARSERS = {} PARSER_KEY_TO_DICT = { 'consumption': CONSUMPTION_PARSERS, 'production': PRODUCTION_PARSERS, 'productionPerUnit': PRODUCTION_PER_UNIT_PARSERS, 'productionPerModeForecast': PRODUCTION_PER_MODE_FORECAST_PARSERS, 'exchange': EXCHANGE_PARSERS, 'price': PRICE_PARSERS, 'consumptionForecast': CONSUMPTION_FORECAST_PARSERS, 'generationForecast': GENERATION_FORECAST_PARSERS, 'exchangeForecast': EXCHANGE_FORECAST_PARSERS, } # Read all zones for zone_id, zone_config in ZONES_CONFIG.items(): for parser_key, v in zone_config.get('parsers', {}).items(): mod_name, fun_name = v.split('.') mod = importlib.import_module('parsers.%s' % mod_name) PARSER_KEY_TO_DICT[parser_key][zone_id] = getattr(mod, fun_name) # Read all exchanges for exchange_id, exchange_config in EXCHANGES_CONFIG.items(): for parser_key, v in exchange_config.get('parsers', {}).items(): mod_name, fun_name = v.split('.') mod = importlib.import_module('parsers.%s' % mod_name) PARSER_KEY_TO_DICT[parser_key][exchange_id] = getattr(mod, fun_name)
def test_bounding_boxes(self): for zone, values in ZONES_CONFIG.items(): bbox = values.get("bounding_box") if bbox: self.assertLess(bbox[0][0], bbox[1][0]) self.assertLess(bbox[0][1], bbox[1][1])
def test_sub_zones(self): for zone, values in ZONES_CONFIG.items(): sub_zones = values.get("subZoneNames", []) for sub_zone in sub_zones: self.assertIn(sub_zone, ZONE_KEYS)