|
3 | 3 |
|
4 | 4 | import pandas as pd
|
5 | 5 | import pytest
|
| 6 | +from genno import Computer |
6 | 7 |
|
| 8 | +from message_ix_models.tools.exo_data import prepare_computer |
7 | 9 | from message_ix_models.tools.iea.web import (
|
8 | 10 | DIMS,
|
9 | 11 | FILES,
|
|
14 | 16 | from message_ix_models.util import package_data_path
|
15 | 17 |
|
16 | 18 |
|
| 19 | +class TestIEA_EWEB: |
| 20 | + @pytest.mark.parametrize("source", ("IEA_EWEB",)) |
| 21 | + @pytest.mark.parametrize( |
| 22 | + "source_kw", |
| 23 | + ( |
| 24 | + dict( |
| 25 | + provider="OECD", edition="2021", product=["CHARCOAL"], flow=["RESIDENT"] |
| 26 | + ), |
| 27 | + # All flows related to transport |
| 28 | + dict( |
| 29 | + provider="OECD", |
| 30 | + edition="2022", |
| 31 | + flow=[ |
| 32 | + "DOMESAIR", |
| 33 | + "DOMESNAV", |
| 34 | + "PIPELINE", |
| 35 | + "RAIL", |
| 36 | + "ROAD", |
| 37 | + "TOTTRANS", |
| 38 | + "TRNONSPE", |
| 39 | + "WORLDAV", |
| 40 | + "WORLDMAR", |
| 41 | + ], |
| 42 | + ), |
| 43 | + ), |
| 44 | + ) |
| 45 | + def test_prepare_computer(self, test_context, source, source_kw): |
| 46 | + # FIXME The following should be redundant, but appears mutable on GHA linux and |
| 47 | + # Windows runners. |
| 48 | + test_context.model.regions = "R14" |
| 49 | + |
| 50 | + c = Computer() |
| 51 | + |
| 52 | + keys = prepare_computer(test_context, c, source, source_kw) |
| 53 | + |
| 54 | + # Preparation of data runs successfully |
| 55 | + result = c.get(keys[0]) |
| 56 | + # print(result.to_string()) |
| 57 | + |
| 58 | + # Data has the expected dimensions |
| 59 | + assert {"n", "y", "product", "flow"} == set(result.dims) |
| 60 | + |
| 61 | + # Data is complete |
| 62 | + assert 14 == len(result.coords["n"]) |
| 63 | + assert {1980, 2020} < set(result.coords["y"].data) |
| 64 | + |
| 65 | + |
17 | 66 | @pytest.mark.parametrize("provider, edition", FILES.keys())
|
18 | 67 | def test_load_data(test_context, tmp_path, provider, edition):
|
19 | 68 | # # Store in the temporary directory for this test
|
|
0 commit comments