Skip to content

Commit

Permalink
increased coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Oct 18, 2023
1 parent f15b9e9 commit d8b5d82
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/test_xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mpi4py.MPI as MPI
import os
import numpy as np
import pytest


def test_init():
Expand Down Expand Up @@ -51,3 +52,31 @@ def test_integration_with_HTransportProblem(tmp_path):

# checks that filename exists
assert os.path.exists(filename)


def test_field_attribute_is_always_list():
"""Test that the field attribute is always a list"""
my_export = F.XDMFExport("my_export.xdmf", field=F.Species("H"))
assert isinstance(my_export.field, list)

my_export = F.XDMFExport("my_export.xdmf", field=[F.Species("H")])
assert isinstance(my_export.field, list)


@pytest.mark.parametrize("field", ["H", 1, [F.Species("H"), 1]])
def test_field_attribute_raises_error_when_invalid_type(field):
"""Test that the field attribute raises an error if the type is not festim.Species or list"""
with pytest.raises(TypeError):
F.XDMFExport("my_export.xdmf", field=field)


def test_filename_raises_error_with_wrong_extension():
"""Test that the filename attribute raises an error if the extension is not .xdmf"""
with pytest.raises(ValueError):
F.XDMFExport("my_export.txt", field=[F.Species("H")])


def test_filename_raises_error_when_wrong_type():
"""Test that the filename attribute raises an error if the file is not str"""
with pytest.raises(TypeError):
F.XDMFExport(1, field=[F.Species("H")])

0 comments on commit d8b5d82

Please sign in to comment.