Skip to content

Commit

Permalink
Merge branch 'develop' into all-contributors/add-Aswinr24
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py authored Oct 14, 2024
2 parents 4725b60 + 3ee7dd0 commit 3fd7d5a
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions tests/unit/test_parameters/test_process_parameter_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,48 @@
# Tests for the parameter processing functions
#


import os
import numpy as np
import pybamm

import pytest
from pathlib import Path


class TestProcessParameterData:
def test_process_1D_data(self):
name = "lico2_ocv_example"
path = os.path.abspath(os.path.dirname(__file__))
processed = pybamm.parameters.process_1D_data(name, path)
assert processed[0] == name
assert isinstance(processed[1], tuple)
assert isinstance(processed[1][0][0], np.ndarray)
assert isinstance(processed[1][1], np.ndarray)
@pytest.fixture
def parameters_path():
return Path(__file__).parent.resolve()

def test_process_2D_data(self):
name = "lico2_diffusivity_Dualfoil1998_2D"
path = os.path.abspath(os.path.dirname(__file__))
processed = pybamm.parameters.process_2D_data(name, path)
assert processed[0] == name
assert isinstance(processed[1], tuple)
assert isinstance(processed[1][0][0], np.ndarray)
assert isinstance(processed[1][0][1], np.ndarray)
assert isinstance(processed[1][1], np.ndarray)

def test_process_2D_data_csv(self):
name = "data_for_testing_2D"
path = os.path.abspath(os.path.dirname(__file__))
processed = pybamm.parameters.process_2D_data_csv(name, path)
@pytest.fixture(
params=[
("lico2_ocv_example", pybamm.parameters.process_1D_data),
("lico2_diffusivity_Dualfoil1998_2D", pybamm.parameters.process_2D_data),
("data_for_testing_2D", pybamm.parameters.process_2D_data_csv),
("data_for_testing_3D", pybamm.parameters.process_3D_data_csv),
]
)
def parameter_data(request, parameters_path):
name, processing_function = request.param
processed = processing_function(name, parameters_path)
return name, processed


class TestProcessParameterData:
def test_processed_name(self, parameter_data):
name, processed = parameter_data
assert processed[0] == name

def test_processed_structure(self, parameter_data):
name, processed = parameter_data
assert isinstance(processed[1], tuple)
assert isinstance(processed[1][0][0], np.ndarray)
assert isinstance(processed[1][0][1], np.ndarray)
assert isinstance(processed[1][1], np.ndarray)

def test_process_3D_data_csv(self):
name = "data_for_testing_3D"
path = os.path.abspath(os.path.dirname(__file__))
processed = pybamm.parameters.process_3D_data_csv(name, path)
if len(processed[1][0]) > 1:
assert isinstance(processed[1][0][1], np.ndarray)

assert processed[0] == name
assert isinstance(processed[1], tuple)
assert isinstance(processed[1][0][0], np.ndarray)
assert isinstance(processed[1][0][1], np.ndarray)
assert isinstance(processed[1][0][2], np.ndarray)
assert isinstance(processed[1][1], np.ndarray)
elif len(processed[1]) == 3:
assert isinstance(processed[1][0][1], np.ndarray)
assert isinstance(processed[1][0][2], np.ndarray)

def test_error(self):
with pytest.raises(FileNotFoundError, match="Could not find file"):
Expand Down

0 comments on commit 3fd7d5a

Please sign in to comment.