From 222fc9fbac10a58a6563a6a33568e707e05bc43f Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 28 Mar 2024 11:52:26 -0400 Subject: [PATCH 1/3] added test to catch the bug --- .../test_derived_quantities.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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, + ) From e2a13bdb0aaa5b1ab2685bca9c9f1fdf22b6b784 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 28 Mar 2024 11:55:17 -0400 Subject: [PATCH 2/3] fixed bug --- festim/exports/derived_quantities/derived_quantities.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 From 17dfe0cd732a3f90efbc79464ed12e762e0492e2 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 28 Mar 2024 12:14:52 -0400 Subject: [PATCH 3/3] 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()