Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing false flagging of assert statements from tests. #4236

Merged
merged 13 commits into from
Jul 19, 2024
Merged
2 changes: 2 additions & 0 deletions bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# To ignore false flagging of assert statements in tests by Codacy.
skips: ['B101']
3 changes: 2 additions & 1 deletion pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def name(self):

@name.setter
def name(self, value: str):
assert isinstance(value, str)
if not isinstance(value, str):
raise TypeError(f"{value} must be of type str")
self._name = value

@property
Expand Down
10 changes: 6 additions & 4 deletions pybamm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ def debug_mode(self):
return self._debug_mode

@debug_mode.setter
def debug_mode(self, value):
assert isinstance(value, bool)
def debug_mode(self, value: bool):
if not isinstance(value, bool):
raise TypeError(f"{value} must be of type bool")
self._debug_mode = value

@property
def simplify(self):
return self._simplify

@simplify.setter
def simplify(self, value):
assert isinstance(value, bool)
def simplify(self, value: bool):
if not isinstance(value, bool):
raise TypeError(f"{value} must be of type bool")
self._simplify = value

def set_smoothing_parameters(self, k):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ extend-select = [
"UP", # pyupgrade
"YTT", # flake8-2020
"TID252", # relative-imports
"S101", # to identify use of assert statement
]
ignore = [
"E741", # Ambiguous variable name
Expand All @@ -220,7 +221,7 @@ ignore = [
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["T20"]
"tests/*" = ["T20", "S101"]
"docs/*" = ["T20"]
"examples/*" = ["T20"]
"**.ipynb" = ["E402", "E703"]
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_expression_tree/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
class TestSymbol(TestCase):
def test_symbol_init(self):
sym = pybamm.Symbol("a symbol")
with self.assertRaises(TypeError):
sym.name = 1
self.assertEqual(sym.name, "a symbol")
self.assertEqual(str(sym), "a symbol")

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@

class TestSettings:
def test_simplify(self):
with pytest.raises(TypeError):
pybamm.settings.simplify = "Not Bool"

assert pybamm.settings.simplify

pybamm.settings.simplify = False
assert not pybamm.settings.simplify

pybamm.settings.simplify = True

def test_debug_mode(self):
with pytest.raises(TypeError):
pybamm.settings.debug_mode = "Not bool"

def test_smoothing_parameters(self):
assert pybamm.settings.min_max_mode == "exact"
assert pybamm.settings.heaviside_smoothing == "exact"
Expand Down
Loading