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/derived_quantities/derived_quantities.py b/festim/exports/derived_quantities/derived_quantities.py index 5a4cfe594..0cb0e108d 100644 --- a/festim/exports/derived_quantities/derived_quantities.py +++ b/festim/exports/derived_quantities/derived_quantities.py @@ -33,9 +33,12 @@ def __init__( nb_iterations_between_exports: int = None, ) -> None: # checks that input is list - if not isinstance(*args, list): - raise TypeError("festim.DerivedQuantities must be a list") - super().__init__(self._validate_derived_quantity(item) for item in args[0]) + if len(args) == 0: + super().__init__() + else: + if not isinstance(*args, list): + raise TypeError("festim.DerivedQuantities must be a list") + super().__init__(self._validate_derived_quantity(item) for item in args[0]) self.filename = filename self.nb_iterations_between_compute = nb_iterations_between_compute 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_derived_quantities/test_derived_quantities.py b/test/unit/test_exports/test_derived_quantities/test_derived_quantities.py index f61cbb585..765c32cf5 100644 --- a/test/unit/test_exports/test_derived_quantities/test_derived_quantities.py +++ b/test/unit/test_exports/test_derived_quantities/test_derived_quantities.py @@ -453,3 +453,15 @@ def test_set_der_quants_list_wrong_type(self): self.my_derived_quantity, 1, ] + + +def test_instanciate_with_no_derived_quantities(): + """ + Test to catch bug described in issue #724 + """ + # define exports + folder_results = "Results/" + DerivedQuantities( + filename=folder_results + "derived_quantities.csv", + nb_iterations_between_exports=1, + ) 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()