From 17dfe0cd732a3f90efbc79464ed12e762e0492e2 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 28 Mar 2024 12:14:52 -0400 Subject: [PATCH] did the same for Materials Exports and Traps --- festim/concentration/traps/traps.py | 9 ++++++--- festim/exports/exports.py | 9 ++++++--- festim/materials/materials.py | 9 ++++++--- test/unit/test_exports/test_exports.py | 8 ++++++++ test/unit/test_materials.py | 8 ++++++++ test/unit/test_traps/test_traps.py | 8 ++++++++ 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/festim/concentration/traps/traps.py b/festim/concentration/traps/traps.py index 4feae1c70..f91a5880d 100644 --- a/festim/concentration/traps/traps.py +++ b/festim/concentration/traps/traps.py @@ -10,9 +10,12 @@ class Traps(list): def __init__(self, *args): # checks that input is list - if not isinstance(*args, list): - raise TypeError("festim.Traps must be a list") - super().__init__(self._validate_trap(item) for item in args[0]) + if len(args) == 0: + super().__init__() + else: + if not isinstance(*args, list): + raise TypeError("festim.Traps must be a list") + super().__init__(self._validate_trap(item) for item in args[0]) self.F = None self.extrinsic_formulations = [] diff --git a/festim/exports/exports.py b/festim/exports/exports.py index 84a23ef4d..a84e80d9e 100644 --- a/festim/exports/exports.py +++ b/festim/exports/exports.py @@ -10,9 +10,12 @@ class Exports(list): def __init__(self, *args): # checks that input is list - if not isinstance(*args, list): - raise TypeError("festim.Exports must be a list") - super().__init__(self._validate_export(item) for item in args[0]) + if len(args) == 0: + super().__init__() + else: + if not isinstance(*args, list): + raise TypeError("festim.Exports must be a list") + super().__init__(self._validate_export(item) for item in args[0]) self.t = None self.V_DG1 = None diff --git a/festim/materials/materials.py b/festim/materials/materials.py index be5b6c16b..642f6dde4 100644 --- a/festim/materials/materials.py +++ b/festim/materials/materials.py @@ -15,9 +15,12 @@ class Materials(list): def __init__(self, *args): # checks that input is list - if not isinstance(*args, list): - raise TypeError("festim.Materials must be a list") - super().__init__(self._validate_material(item) for item in args[0]) + if len(args) == 0: + super().__init__() + else: + if not isinstance(*args, list): + raise TypeError("festim.Materials must be a list") + super().__init__(self._validate_material(item) for item in args[0]) self.D = None self.S = None diff --git a/test/unit/test_exports/test_exports.py b/test/unit/test_exports/test_exports.py index 7df859d74..3921b1f84 100644 --- a/test/unit/test_exports/test_exports.py +++ b/test/unit/test_exports/test_exports.py @@ -131,3 +131,11 @@ def test_set_exports_list_wrong_type(self): match="exports must be a list of festim.Export", ): self.my_exports.exports = [self.my_export, 1] + + +def test_instanciate_with_no_elements(): + """ + Test to catch bug described in issue #724 + """ + # define exports + festim.Exports() diff --git a/test/unit/test_materials.py b/test/unit/test_materials.py index 9abe14c1a..00624553a 100644 --- a/test/unit/test_materials.py +++ b/test/unit/test_materials.py @@ -438,3 +438,11 @@ def test_set_materials_list_wrong_type(self): match="materials must be a list of festim.Material", ): self.my_mats.materials = [self.my_mat, 1] + + +def test_instanciate_with_no_elements(): + """ + Test to catch bug described in issue #724 + """ + # define exports + F.Materials() diff --git a/test/unit/test_traps/test_traps.py b/test/unit/test_traps/test_traps.py index 267fd8f78..b9cbed45b 100644 --- a/test/unit/test_traps/test_traps.py +++ b/test/unit/test_traps/test_traps.py @@ -240,3 +240,11 @@ def test_set_traps_list_wrong_type(self): match="traps must be a list of festim.Trap", ): self.my_traps.traps = [self.my_trap, 1] + + +def test_instanciate_with_no_elements(): + """ + Test to catch bug described in issue #724 + """ + # define exports + festim.Traps()