Skip to content

Commit

Permalink
lint: reformatted code with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoTartarini committed Sep 9, 2024
1 parent 603a47c commit 4353993
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
18 changes: 12 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,39 @@
import json
import requests
import numpy as np

# The conftest.py file serves as a means of providing fixtures for an entire directory.
# Fixtures defined in a conftest.py can be used by any test in that package
# Fixtures defined in a conftest.py can be used by any test in that package
# without needing to import them (pytest will automatically discover them).


unit_test_data_prefix = "https://raw.githubusercontent.com/TwinGan/validation-data-comfort-models/release_v1.0/"
test_adaptive_en_url = unit_test_data_prefix + "ts_adaptive_en.json"


def retrieve_data(url):
try:
resp = requests.get(url)
reference_tables = json.loads(resp.text)
return reference_tables
resp = requests.get(url)
reference_tables = json.loads(resp.text)
return reference_tables
except requests.RequestException as e:
print(f"Error fetching data from {url}: {e}")
return None


# Custom equal method
## Json null equal to np.nan
# Json null equal to np.nan
@pytest.fixture
def is_equal():
def compare(a, b):
if (a is None and np.isnan(b)) or (b is None and np.isnan(a)):
return True
return a == b

return compare


# get test data for adaptove_en()
@pytest.fixture
def get_adaptive_en_test_data():
return retrieve_data(test_adaptive_en_url)
return retrieve_data(test_adaptive_en_url)
29 changes: 15 additions & 14 deletions tests/test_adaptive_en.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import numpy as np
from pythermalcomfort.models import adaptive_en


def test_adaptive_en(get_adaptive_en_test_data, is_equal):
for entry in get_adaptive_en_test_data["data"]:
inputs = entry["inputs"]
outputs = entry["outputs"]
result = adaptive_en(
inputs["tdb"],
inputs["tr"],
inputs["t_running_mean"],
inputs["v"]
inputs["tdb"], inputs["tr"], inputs["t_running_mean"], inputs["v"]
)

assert is_equal(result["tmp_cmf"], outputs["tmp_cmf"])
assert is_equal(result["acceptability_cat_i"], outputs["acceptability_cat_i"])
assert is_equal(result["acceptability_cat_ii"], outputs["acceptability_cat_ii"])
assert is_equal(
result["acceptability_cat_iii"], outputs["acceptability_cat_iii"]
)
assert is_equal(result["tmp_cmf"] , outputs["tmp_cmf"])
assert is_equal(result["acceptability_cat_i"] , outputs["acceptability_cat_i"])
assert is_equal(result["acceptability_cat_ii"] , outputs["acceptability_cat_ii"])
assert is_equal(result["acceptability_cat_iii"] , outputs["acceptability_cat_iii"])
assert is_equal(result["tmp_cmf_cat_i_up"] , outputs["tmp_cmf_cat_i_up"])
assert is_equal(result["tmp_cmf_cat_ii_up"] , outputs["tmp_cmf_cat_ii_up"])
assert is_equal(result["tmp_cmf_cat_iii_up"] , outputs["tmp_cmf_cat_iii_up"])
assert is_equal(result["tmp_cmf_cat_i_low"] , outputs["tmp_cmf_cat_i_low"])
assert is_equal(result["tmp_cmf_cat_ii_low"] , outputs["tmp_cmf_cat_ii_low"])
assert is_equal(result["tmp_cmf_cat_iii_low"] , outputs["tmp_cmf_cat_iii_low"])
assert is_equal(result["tmp_cmf_cat_i_up"], outputs["tmp_cmf_cat_i_up"])
assert is_equal(result["tmp_cmf_cat_ii_up"], outputs["tmp_cmf_cat_ii_up"])
assert is_equal(result["tmp_cmf_cat_iii_up"], outputs["tmp_cmf_cat_iii_up"])
assert is_equal(result["tmp_cmf_cat_i_low"], outputs["tmp_cmf_cat_i_low"])
assert is_equal(result["tmp_cmf_cat_ii_low"], outputs["tmp_cmf_cat_ii_low"])
assert is_equal(result["tmp_cmf_cat_iii_low"], outputs["tmp_cmf_cat_iii_low"])

0 comments on commit 4353993

Please sign in to comment.