Skip to content

Commit

Permalink
Merge pull request #935 from jhdark/depricate_list_attributes
Browse files Browse the repository at this point in the history
Deprecate list attributes
  • Loading branch information
RemDelaporteMathurin authored Jan 14, 2025
2 parents 8d6857b + 79f5d3e commit 8d8f7d9
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 263 deletions.
22 changes: 0 additions & 22 deletions festim/concentration/traps/traps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import festim
import fenics as f
import warnings


class Traps(list):
Expand All @@ -21,27 +20,6 @@ def __init__(self, *args):
self.extrinsic_formulations = []
self.sub_expressions = []

@property
def traps(self):
warnings.warn(
"The traps attribute will be deprecated in a future release, please use festim.Traps as a list instead",
DeprecationWarning,
)
return self

@traps.setter
def traps(self, value):
warnings.warn(
"The traps attribute will be deprecated in a future release, please use festim.Traps as a list instead",
DeprecationWarning,
)
if isinstance(value, list):
if not all(isinstance(t, festim.Trap) for t in value):
raise TypeError("traps must be a list of festim.Trap")
super().__init__(value)
else:
raise TypeError("traps must be a list")

def __setitem__(self, index, item):
super().__setitem__(index, self._validate_trap(item))

Expand Down
24 changes: 0 additions & 24 deletions festim/exports/derived_quantities/derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import numpy as np
from typing import Union
import warnings


class DerivedQuantities(list):
Expand Down Expand Up @@ -63,29 +62,6 @@ def __init__(
self.data = []
self.t = []

@property
def derived_quantities(self):
warnings.warn(
"The derived_quantities attribute will be deprecated in a future release, please use festim.DerivedQuantities as a list instead",
DeprecationWarning,
)
return self

@derived_quantities.setter
def derived_quantities(self, value):
warnings.warn(
"The derived_quantities attribute will be deprecated in a future release, please use festim.DerivedQuantities as a list instead",
DeprecationWarning,
)
if isinstance(value, list):
if not all(isinstance(t, DerivedQuantity) for t in value):
raise TypeError(
"derived_quantities must be a list of festim.DerivedQuantity"
)
super().__init__(value)
else:
raise TypeError("derived_quantities must be a list")

def __setitem__(self, index, item):
super().__setitem__(index, self._validate_derived_quantity(item))

Expand Down
28 changes: 0 additions & 28 deletions festim/exports/exports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import festim
import fenics as f
import warnings


class Exports(list):
Expand All @@ -22,33 +21,6 @@ def __init__(self, *args):
self.final_time = None
self.nb_iterations = 0

@property
def exports(self):
warnings.warn(
"The exports attribute will be deprecated in a future release, please use festim.Exports as a list instead",
DeprecationWarning,
)
return self

@exports.setter
def exports(self, value):
warnings.warn(
"The exports attribute will be deprecated in a future release, please use festim.Exports as a list instead",
DeprecationWarning,
)
if isinstance(value, list):
if not all(
(
isinstance(t, festim.Export)
or isinstance(t, festim.DerivedQuantities)
)
for t in value
):
raise TypeError("exports must be a list of festim.Export")
super().__init__(value)
else:
raise TypeError("exports must be a list")

def __setitem__(self, index, item):
super().__setitem__(index, self._validate_export(item))

Expand Down
22 changes: 0 additions & 22 deletions festim/materials/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import festim
import fenics as f
from typing import Union
import warnings


class Materials(list):
Expand All @@ -29,27 +28,6 @@ def __init__(self, *args):
self.density = None
self.Q = None

@property
def materials(self):
warnings.warn(
"The materials attribute will be deprecated in a future release, please use festim.Materials as a list instead",
DeprecationWarning,
)
return self

@materials.setter
def materials(self, value):
warnings.warn(
"The materials attribute will be deprecated in a future release, please use festim.Materials as a list instead",
DeprecationWarning,
)
if isinstance(value, list):
if not all(isinstance(t, festim.Material) for t in value):
raise TypeError("materials must be a list of festim.Material")
super().__init__(value)
else:
raise TypeError("materials must be a list")

def __setitem__(self, index, item):
super().__setitem__(index, self._validate_material(item))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,49 +543,6 @@ def test_assign_derived_quantitites_wrong_type():
my_derived_quantities.insert(0, dq_combination)


class TestDerivedQuantititesPropertyDeprWarn:
"""
A temporary test to check DeprecationWarnings in festim.DerivedQuantitites.exports
"""

my_derived_quantity = SurfaceFlux(0, 2)
my_derived_quantities = DerivedQuantities([])

def test_property_depr_warns(self):
with pytest.deprecated_call():
self.my_derived_quantities.derived_quantities

def test_property_setter_depr_warns(self):
with pytest.deprecated_call():
self.my_derived_quantities.derived_quantities = [self.my_derived_quantity]


class TestDerivedQuantititesPropertyRaiseError:
"""
A temporary test to check TypeErrors in festim.DerivedQuantitites.exports
"""

my_derived_quantity = SurfaceFlux(0, 2)
my_derived_quantities = DerivedQuantities([])

def test_set_der_quants_wrong_type(self):
with pytest.raises(
TypeError,
match="derived_quantities must be a list",
):
self.my_derived_quantities.derived_quantities = self.my_derived_quantity

def test_set_der_quants_list_wrong_type(self):
with pytest.raises(
TypeError,
match="derived_quantities must be a list of festim.DerivedQuantity",
):
self.my_derived_quantities.derived_quantities = [
self.my_derived_quantity,
1,
]


def test_instanciate_with_no_derived_quantities():
"""
Test to catch bug described in issue #724
Expand Down
40 changes: 0 additions & 40 deletions test/unit/test_exports/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,6 @@ def test_assign_exports_wrong_type():
my_exports.insert(0, export_combination)


class TestExportsPropertyDeprWarn:
"""
A temporary test to check DeprecationWarnings in festim.Exports.exports
"""

my_export = festim.Export(field=0)
my_exports = festim.Exports([])

def test_property_depr_warns(self):
with pytest.deprecated_call():
self.my_exports.exports

def test_property_setter_depr_warns(self):
with pytest.deprecated_call():
self.my_exports.exports = [self.my_export]


class TestExportsPropertyRaiseError:
"""
A temporary test to check TypeErrors in festim.Exports.exports
"""

my_export = festim.Export(field=0)
my_exports = festim.Exports([])

def test_set_exports_wrong_type(self):
with pytest.raises(
TypeError,
match="exports must be a list",
):
self.my_exports.exports = self.my_export

def test_set_exports_list_wrong_type(self):
with pytest.raises(
TypeError,
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
Expand Down
40 changes: 0 additions & 40 deletions test/unit/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,46 +402,6 @@ def test_assign_materials_wrong_type():
my_materials.insert(0, mat_combination)


class TestMaterialsPropertyDeprWarn:
"""
A temporary test to check DeprecationWarnings in F.Materials.materials
"""

my_mat = F.Material(id=1, E_D=1, D_0=1)
my_mats = F.Materials([])

def test_property_depr_warns(self):
with pytest.deprecated_call():
self.my_mats.materials

def test_property_setter_depr_warns(self):
with pytest.deprecated_call():
self.my_mats.materials = [self.my_mat]


class TestMaterialsPropertyRaiseError:
"""
A temporary test to check TypeErrors in F.Materials.materials
"""

my_mat = F.Material(id=1, E_D=1, D_0=1)
my_mats = F.Materials([])

def test_set_materials_wrong_type(self):
with pytest.raises(
TypeError,
match="materials must be a list",
):
self.my_mats.materials = self.my_mat

def test_set_materials_list_wrong_type(self):
with pytest.raises(
TypeError,
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
Expand Down
44 changes: 0 additions & 44 deletions test/unit/test_traps/test_traps.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,50 +213,6 @@ def test_assign_traps_wrong_type():
my_traps.insert(0, trap_combination)


class TestTrapsPropertyDeprWarn:
"""
A temporary test to check DeprecationWarnings in festim.Traps.traps
"""

my_mat = festim.Material(1, 1, 1)
my_trap = festim.Trap(1, 1, 1, 1, [my_mat], 1)

my_traps = festim.Traps([])

def test_property_depr_warns(self):
with pytest.deprecated_call():
self.my_traps.traps

def test_property_setter_depr_warns(self):
with pytest.deprecated_call():
self.my_traps.traps = [self.my_trap]


class TestTrapsPropertyRaiseError:
"""
A temporary test to check TypeErrors in festim.Traps.traps
"""

my_mat = festim.Material(1, 1, 1)
my_trap = festim.Trap(1, 1, 1, 1, [my_mat], 1)

my_traps = festim.Traps([])

def test_set_traps_wrong_type(self):
with pytest.raises(
TypeError,
match="traps must be a list",
):
self.my_traps.traps = self.my_trap

def test_set_traps_list_wrong_type(self):
with pytest.raises(
TypeError,
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
Expand Down

0 comments on commit 8d8f7d9

Please sign in to comment.