Skip to content

Commit

Permalink
Fixes #328
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerket committed Jan 30, 2023
1 parent d68f2d5 commit 2cc4ea4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
4 changes: 2 additions & 2 deletions buildstockbatch/base.py
Expand Up @@ -693,9 +693,9 @@ def validate_resstock_or_comstock_version(project_file):
versions[tool] = eval(version.strip())
BuildStockBatch_Version = versions['BuildStockBatch_Version']
if bsb_version < BuildStockBatch_Version:
if 'ResStock_Version' in dict.keys():
if 'ResStock_Version' in versions.keys():
stock_version = versions['ResStock_Version']
elif 'ComStock_Version' in dict.keys():
elif 'ComStock_Version' in versions.keys():
stock_version = versions['ComStock_Version']
else:
stock_version = 'Unknown'
Expand Down
12 changes: 12 additions & 0 deletions buildstockbatch/test/shared_testing_stuff.py
@@ -0,0 +1,12 @@
import os
import pathlib
import pytest


resstock_directory = pathlib.Path(
os.environ.get("RESSTOCK_DIR", pathlib.Path(__file__).resolve().parent.parent.parent.parent / "resstock")
)
resstock_required = pytest.mark.skipif(
not resstock_directory.exists(),
reason="ResStock checkout is not found"
)
29 changes: 1 addition & 28 deletions buildstockbatch/test/test_integration.py
@@ -1,22 +1,10 @@
import os
import pandas as pd
import pathlib
import pytest
import shutil
import tempfile
import json

from buildstockbatch.localdocker import LocalDockerBatch
from buildstockbatch.utils import get_project_configuration
from buildstockbatch.exc import ValidationError

resstock_directory = pathlib.Path(
os.environ.get("RESSTOCK_DIR", pathlib.Path(__file__).resolve().parent.parent.parent.parent / "resstock")
)
resstock_required = pytest.mark.skipif(
not resstock_directory.exists(),
reason="ResStock checkout is not found"
)
from buildstockbatch.test.shared_testing_stuff import resstock_directory, resstock_required


@pytest.mark.parametrize("project_filename", [
Expand Down Expand Up @@ -85,18 +73,3 @@ def test_resstock_local_batch(project_filename):
assert (ts_pq_path / "_metadata").exists()

shutil.rmtree(out_path)


@resstock_required
def test_number_of_options_apply_upgrade():
proj_filename = resstock_directory / "project_national" / "national_upgrades.yml"
cfg = get_project_configuration(str(proj_filename))
cfg["upgrades"][-1]["options"] = cfg["upgrades"][-1]["options"] * 10
cfg["upgrades"][0]["options"][0]["costs"] = cfg["upgrades"][0]["options"][0]["costs"] * 5
with tempfile.TemporaryDirectory() as tmpdir:
tmppath = pathlib.Path(tmpdir)
new_proj_filename = tmppath / "project.yml"
with open(new_proj_filename, "w") as f:
json.dump(cfg, f)
with pytest.raises(ValidationError):
LocalDockerBatch.validate_number_of_options(str(new_proj_filename))
29 changes: 29 additions & 0 deletions buildstockbatch/test/test_validation.py
Expand Up @@ -14,9 +14,14 @@
import os
import pytest
import types
import tempfile
import json
import pathlib
from buildstockbatch.eagle import EagleBatch
from buildstockbatch.localdocker import LocalDockerBatch
from buildstockbatch.base import BuildStockBatchBase, ValidationError
from buildstockbatch.test.shared_testing_stuff import resstock_directory, resstock_required
from buildstockbatch.utils import get_project_configuration
from unittest.mock import patch
from testfixtures import LogCapture
import logging
Expand Down Expand Up @@ -263,3 +268,27 @@ def test_logic_validation_fail(project_file):
])
def test_logic_validation_pass(project_file):
BuildStockBatchBase.validate_logic(project_file)


@resstock_required
def test_number_of_options_apply_upgrade():
proj_filename = resstock_directory / "project_national" / "national_upgrades.yml"
cfg = get_project_configuration(str(proj_filename))
cfg["upgrades"][-1]["options"] = cfg["upgrades"][-1]["options"] * 10
cfg["upgrades"][0]["options"][0]["costs"] = cfg["upgrades"][0]["options"][0]["costs"] * 5
with tempfile.TemporaryDirectory() as tmpdir:
tmppath = pathlib.Path(tmpdir)
new_proj_filename = tmppath / "project.yml"
with open(new_proj_filename, "w") as f:
json.dump(cfg, f)
with pytest.raises(ValidationError):
LocalDockerBatch.validate_number_of_options(str(new_proj_filename))


@resstock_required
def test_validate_resstock_or_comstock_version(mocker):
# Set the version to a 'really old' one so we trigger the version check error
mocker.patch("buildstockbatch.base.bsb_version", "0.1")
proj_filename = resstock_directory / "project_national" / "national_upgrades.yml"
with pytest.raises(ValidationError):
BuildStockBatchBase.validate_resstock_or_comstock_version(str(proj_filename))

0 comments on commit 2cc4ea4

Please sign in to comment.