From d8b5d82852f208eb516f0278fdeb3faaf4faa948 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 18 Oct 2023 14:36:07 -0400 Subject: [PATCH] increased coverage --- test/test_xdmf.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_xdmf.py b/test/test_xdmf.py index dadf2352a..154967d87 100644 --- a/test/test_xdmf.py +++ b/test/test_xdmf.py @@ -3,6 +3,7 @@ import mpi4py.MPI as MPI import os import numpy as np +import pytest def test_init(): @@ -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")])