Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d63dff8c
Commit
d63dff8c
authored
Jul 16, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change a few tests to use `with self.assertRaises` for readability
parent
76707cb8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
27 deletions
+17
-27
common/lib/calc/tests/test_calc.py
+17
-27
No files found.
common/lib/calc/tests/test_calc.py
View file @
d63dff8c
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment