Commit d63dff8c by Peter Baratta

Change a few tests to use `with self.assertRaises` for readability

parent 76707cb8
...@@ -14,7 +14,7 @@ class EvaluatorTest(unittest.TestCase): ...@@ -14,7 +14,7 @@ class EvaluatorTest(unittest.TestCase):
Go through all functionalities as specifically as possible-- Go through all functionalities as specifically as possible--
work from number input to functions and complex expressions work from number input to functions and complex expressions
Also test custom variable substitutions (i.e. Also test custom variable substitutions (i.e.
`evaluator({'x':3.0},{}, '3*x')` `evaluator({'x':3.0}, {}, '3*x')`
gives 9.0) and more. gives 9.0) and more.
""" """
...@@ -41,8 +41,10 @@ class EvaluatorTest(unittest.TestCase): ...@@ -41,8 +41,10 @@ class EvaluatorTest(unittest.TestCase):
""" """
The string '.' should not evaluate to anything. The string '.' should not evaluate to anything.
""" """
self.assertRaises(ParseException, calc.evaluator, {}, {}, '.') with self.assertRaises(ParseException):
self.assertRaises(ParseException, calc.evaluator, {}, {}, '1+.') calc.evaluator({}, {}, '.')
with self.assertRaises(ParseException):
calc.evaluator({}, {}, '1+.')
def test_trailing_period(self): def test_trailing_period(self):
""" """
...@@ -120,18 +122,12 @@ class EvaluatorTest(unittest.TestCase): ...@@ -120,18 +122,12 @@ class EvaluatorTest(unittest.TestCase):
""" """
Ensure division by zero gives an error Ensure division by zero gives an error
""" """
self.assertRaises( with self.assertRaises(ZeroDivisionError):
ZeroDivisionError, calc.evaluator, calc.evaluator({}, {}, '1/0')
{}, {}, '1/0' with self.assertRaises(ZeroDivisionError):
) calc.evaluator({}, {}, '1/0.0')
self.assertRaises( with self.assertRaises(ZeroDivisionError):
ZeroDivisionError, calc.evaluator, calc.evaluator({'x': 0.0}, {}, '1/x')
{}, {}, '1/0.0'
)
self.assertRaises(
ZeroDivisionError, calc.evaluator,
{'x': 0.0}, {}, '1/x'
)
def test_parallel_resistors(self): def test_parallel_resistors(self):
""" """
...@@ -518,15 +514,9 @@ class EvaluatorTest(unittest.TestCase): ...@@ -518,15 +514,9 @@ class EvaluatorTest(unittest.TestCase):
""" """
variables = {'R1': 2.0, 'R3': 4.0} variables = {'R1': 2.0, 'R3': 4.0}
self.assertRaises( with self.assertRaises(calc.UndefinedVariable):
calc.UndefinedVariable, calc.evaluator, calc.evaluator({}, {}, "5+7*QWSEKO")
{}, {}, "5+7*QWSEKO" with self.assertRaises(calc.UndefinedVariable):
) calc.evaluator({'r1': 5}, {}, "r1+r2")
self.assertRaises( with self.assertRaises(calc.UndefinedVariable):
calc.UndefinedVariable, calc.evaluator, calc.evaluator(variables, {}, "r1*r3", case_sensitive=True)
{'r1': 5}, {}, "r1+r2"
)
self.assertRaises(
calc.UndefinedVariable, calc.evaluator,
variables, {}, "r1*r3", case_sensitive=True
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment