Skip to content

Commit

Permalink
Apply code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
awais307 committed Sep 27, 2023
1 parent 21daf50 commit 9c723ab
Show file tree
Hide file tree
Showing 26 changed files with 276 additions and 256 deletions.
13 changes: 3 additions & 10 deletions message_ix_models/model/disutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@

from message_ix_models import ScenarioInfo, Spec
from message_ix_models.model.build import apply_spec
from message_ix_models.util import (
broadcast,
eval_anno,
make_io,
make_matched_dfs,
make_source_tech,
merge_data,
nodes_ex_world,
same_node,
)
from message_ix_models.util import (broadcast, eval_anno, make_io,
make_matched_dfs, make_source_tech,
merge_data, nodes_ex_world, same_node)

log = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/model/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from iam_units import registry
from sdmx.model.v21 import Annotation, Code

from message_ix_models.util import eval_anno, load_package_data, package_data_path
from message_ix_models.util import (eval_anno, load_package_data,
package_data_path)
from message_ix_models.util.sdmx import as_codes

log = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/model/water/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from message_ix_models import ScenarioInfo
from message_ix_models.util import add_par_data

from .demands import add_irrigation_demand, add_sectoral_demands, add_water_availability
from .demands import (add_irrigation_demand, add_sectoral_demands,
add_water_availability)
from .infrastructure import add_desalination, add_infrastructure_techs
from .irrigation import add_irr_structure
from .water_for_ppl import cool_tech, non_cooling_tec
Expand Down
9 changes: 2 additions & 7 deletions message_ix_models/model/water/data/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
from message_ix import make_df

from message_ix_models.model.water.utils import map_yv_ya_lt
from message_ix_models.util import (
broadcast,
make_matched_dfs,
private_data_path,
same_node,
same_time,
)
from message_ix_models.util import (broadcast, make_matched_dfs,
private_data_path, same_node, same_time)


def add_infrastructure_techs(context): # noqa: C901
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
mapping used in the nexus module.
"""
import glob

# Import packages
import os
from datetime import datetime as dt
Expand Down
11 changes: 4 additions & 7 deletions message_ix_models/model/water/data/water_for_ppl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import pandas as pd
from message_ix import make_df

from message_ix_models.model.water.data.water_supply import map_basin_region_wat
from message_ix_models.util import (
broadcast,
make_matched_dfs,
private_data_path,
same_node,
)
from message_ix_models.model.water.data.water_supply import \
map_basin_region_wat
from message_ix_models.util import (broadcast, make_matched_dfs,
private_data_path, same_node)


# water & electricity for cooling technologies
Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/model/water/data/water_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from message_ix_models.model.water.data.demands import read_water_availability
from message_ix_models.model.water.utils import map_yv_ya_lt
from message_ix_models.util import broadcast, private_data_path, same_node, same_time
from message_ix_models.util import (broadcast, private_data_path, same_node,
same_time)


def map_basin_region_wat(context):
Expand Down
5 changes: 2 additions & 3 deletions message_ix_models/model/water/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from message_ix_models.util import private_data_path

try:
from message_data.tools.post_processing.iamc_report_hackathon import (
report as old_reporting,
)
from message_data.tools.post_processing.iamc_report_hackathon import \
report as old_reporting
except ImportError: # message_data not installed
old_reporting = None

Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/report/computations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Atomic reporting operations for MESSAGEix-GLOBIOM."""
import itertools
import logging
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Set, Tuple, Union
from typing import (TYPE_CHECKING, Any, List, Mapping, Optional, Set, Tuple,
Union)

import ixmp
import pandas as pd
Expand Down
8 changes: 2 additions & 6 deletions message_ix_models/tests/model/test_disutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@

from message_ix_models import ScenarioInfo, testing
from message_ix_models.model import disutility
from message_ix_models.util import (
add_par_data,
copy_column,
make_source_tech,
merge_data,
)
from message_ix_models.util import (add_par_data, copy_column,
make_source_tech, merge_data)

# Common data and fixtures for test_minimal() and other tests

Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/tests/model/test_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from message_ix.models import MACRO

from message_ix_models import testing
from message_ix_models.model.emissions import add_tax_emission, get_emission_factors
from message_ix_models.model.emissions import (add_tax_emission,
get_emission_factors)


def add_test_data(scenario):
Expand Down
13 changes: 5 additions & 8 deletions message_ix_models/tests/model/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
from iam_units import registry
from sdmx.model.v21 import Annotation, Code

from message_ix_models.model.structure import (
codelists,
generate_set_elements,
get_codes,
get_region_codes,
process_commodity_codes,
process_units_anno,
)
from message_ix_models.model.structure import (codelists,
generate_set_elements,
get_codes, get_region_codes,
process_commodity_codes,
process_units_anno)
from message_ix_models.util import as_codes, eval_anno


Expand Down
67 changes: 47 additions & 20 deletions message_ix_models/tests/model/water/test_cooling.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,68 @@
from unittest.mock import MagicMock, patch

import pandas as pd
from unittest.mock import MagicMock, patch

from message_ix_models.model.water.data.irrigation import non_cooling_tec


def test_non_cooling_tec():
# Mock the context
context = {
"water build info": {"Y": [2020, 2030, 2040]},
"type_reg": "country",
"regions": "test_region",
"map_ISO_c": {"test_region": "test_ISO"},
"get_scenario": MagicMock(return_value=MagicMock(par=MagicMock(return_value=pd.DataFrame({
"technology": ["tech1", "tech2"],
"node_loc": ["loc1", "loc2"],
"node_dest": ["dest1", "dest2"],
"year_vtg": ["2020", "2020"],
"year_act": ["2020", "2020"],
}))))
"get_scenario": MagicMock(
return_value=MagicMock(
par=MagicMock(
return_value=pd.DataFrame(
{
"technology": ["tech1", "tech2"],
"node_loc": ["loc1", "loc2"],
"node_dest": ["dest1", "dest2"],
"year_vtg": ["2020", "2020"],
"year_act": ["2020", "2020"],
}
)
)
)
),
}

# Mock the DataFrame read from CSV
df = pd.DataFrame({
"technology_group": ["cooling", "non-cooling"],
"technology_name": ["cooling_tech1", "non_cooling_tech1"],
"water_supply_type": ["freshwater_supply", "freshwater_supply"],
"water_withdrawal_mid_m3_per_output": [1, 2],
})

df = pd.DataFrame(
{
"technology_group": ["cooling", "non-cooling"],
"technology_name": ["cooling_tech1", "non_cooling_tech1"],
"water_supply_type": ["freshwater_supply", "freshwater_supply"],
"water_withdrawal_mid_m3_per_output": [1, 2],
}
)

# Mock the function 'private_data_path' to return the mocked DataFrame
with patch('message_ix_models.util.private_data_path', return_value="path/to/file"), \
patch('pandas.read_csv', return_value=df):
with patch(
"message_ix_models.util.private_data_path", return_value="path/to/file"
), patch("pandas.read_csv", return_value=df):
# Call the function to be tested
result = non_cooling_tec(context)

# Assert the results
assert isinstance(result, dict)
assert "input" in result
assert all(col in result["input"].columns for col in ["technology", "value", "unit", "level", "commodity", "mode", "time", "time_origin", "node_origin", "node_loc", "year_vtg", "year_act"])
assert all(
col in result["input"].columns
for col in [
"technology",
"value",
"unit",
"level",
"commodity",
"mode",
"time",
"time_origin",
"node_origin",
"node_loc",
"year_vtg",
"year_act",
]
)
57 changes: 44 additions & 13 deletions message_ix_models/tests/model/water/test_irrigation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pandas as pd
from unittest.mock import patch

import pandas as pd

from message_ix_models.model.water.data.irrigation import add_irr_structure


def test_add_irr_structure():
# Mock the context
context = {
Expand All @@ -11,23 +13,52 @@ def test_add_irr_structure():
"regions": "test_region",
"map_ISO_c": {"test_region": "test_ISO"},
}

# Mock the DataFrame read from CSV
df_node = pd.DataFrame({
"BCU_name": ["1", "2"],
"REGION": ["region1", "region2"]
})

df_node = pd.DataFrame({"BCU_name": ["1", "2"], "REGION": ["region1", "region2"]})

# Mock the function 'private_data_path' to return the mocked DataFrame
with patch('message_ix_models.util.private_data_path', return_value="path/to/file"), \
patch('pandas.read_csv', return_value=df_node):
with patch(
"message_ix_models.util.private_data_path", return_value="path/to/file"
), patch("pandas.read_csv", return_value=df_node):
# Call the function to be tested
result = add_irr_structure(context)

# Assert the results
assert isinstance(result, dict)
assert "input" in result
assert "output" in result
assert all(col in result["input"].columns for col in ["technology", "value", "unit", "level", "commodity", "mode", "time", "time_origin", "node_origin", "node_loc", "year_vtg", "year_act"])
assert all(col in result["output"].columns for col in ["technology", "value", "unit", "level", "commodity", "mode", "time", "time_dest", "node_loc", "node_dest", "year_vtg", "year_act"])
assert all(
col in result["input"].columns
for col in [
"technology",
"value",
"unit",
"level",
"commodity",
"mode",
"time",
"time_origin",
"node_origin",
"node_loc",
"year_vtg",
"year_act",
]
)
assert all(
col in result["output"].columns
for col in [
"technology",
"value",
"unit",
"level",
"commodity",
"mode",
"time",
"time_dest",
"node_loc",
"node_dest",
"year_vtg",
"year_act",
]
)
Loading

0 comments on commit 9c723ab

Please sign in to comment.