Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
55b67e39
Commit
55b67e39
authored
11 years ago
by
Peter Baratta
Browse files
Options
Downloads
Plain Diff
Merge pull request #680 from edx/peterb/move-numpy-seterr
Move the silencing of numpy's warnings into test_calc.py
parents
0db4c987
5f3dd37f
No related branches found
Branches containing commit
Tags
release-2021-05-04-14.07
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/lib/calc/calc.py
+0
-5
0 additions, 5 deletions
common/lib/calc/calc.py
common/lib/calc/tests/test_calc.py
+13
-8
13 additions, 8 deletions
common/lib/calc/tests/test_calc.py
with
13 additions
and
13 deletions
common/lib/calc/calc.py
+
0
−
5
View file @
55b67e39
...
...
@@ -11,11 +11,6 @@ import numpy
import
scipy.constants
import
calcfunctions
# Have numpy ignore errors on functions outside its domain.
# See http://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html
# TODO worry about thread safety/changing a global setting
numpy
.
seterr
(
all
=
'
ignore
'
)
# Also: 'ignore', 'warn' (default), 'raise'
from
pyparsing
import
(
Word
,
Literal
,
CaselessLiteral
,
ZeroOrMore
,
MatchFirst
,
Optional
,
Forward
,
Group
,
ParseResults
,
stringEnd
,
Suppress
,
Combine
,
alphas
,
nums
,
alphanums
...
...
This diff is collapsed.
Click to expand it.
common/lib/calc/tests/test_calc.py
+
13
−
8
View file @
55b67e39
...
...
@@ -7,6 +7,12 @@ import numpy
import
calc
from
pyparsing
import
ParseException
# numpy's default behavior when it evaluates a function outside its domain
# is to raise a warning (not an exception) which is then printed to STDOUT.
# To prevent this from polluting the output of the tests, configure numpy to
# ignore it instead.
# See http://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html
numpy
.
seterr
(
all
=
'
ignore
'
)
# Also: 'ignore', 'warn' (default), 'raise'
class
EvaluatorTest
(
unittest
.
TestCase
):
"""
...
...
@@ -186,17 +192,16 @@ class EvaluatorTest(unittest.TestCase):
arcsin_inputs
=
[
'
-0.707
'
,
'
0
'
,
'
0.5
'
,
'
0.588
'
,
'
1.298 + 0.635*j
'
]
arcsin_angles
=
[
-
0.785
,
0
,
0.524
,
0.629
,
1
+
1j
]
self
.
assert_function_values
(
'
arcsin
'
,
arcsin_inputs
,
arcsin_angles
)
# Rather than throwing an exception, numpy.arcsin gives nan
# self.assertTrue(numpy.isnan(calc.evaluator({}, {}, 'arcsin(-1.1)')))
# self.assertTrue(numpy.isnan(calc.evaluator({}, {}, 'arcsin(1.1)')))
# Disabled for now because they are giving a runtime warning... :-/
# Rather than a complex number, numpy.arcsin gives nan
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'
arcsin(-1.1)
'
)))
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'
arcsin(1.1)
'
)))
# Include those where the real part is between 0 and pi
arccos_inputs
=
[
'
1
'
,
'
0.866
'
,
'
0.809
'
,
'
0.834-0.989*j
'
]
arccos_angles
=
[
0
,
0.524
,
0.628
,
1
+
1j
]
self
.
assert_function_values
(
'
arccos
'
,
arccos_inputs
,
arccos_angles
)
#
self.assertTrue(numpy.isnan(calc.evaluator({}, {}, 'arccos(-1.1)')))
#
self.assertTrue(numpy.isnan(calc.evaluator({}, {}, 'arccos(1.1)')))
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'
arccos(-1.1)
'
)))
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'
arccos(1.1)
'
)))
# Has the same range as arcsin
arctan_inputs
=
[
'
-1
'
,
'
0
'
,
'
0.577
'
,
'
0.727
'
,
'
0.272 + 1.084*j
'
]
...
...
@@ -535,10 +540,10 @@ class EvaluatorTest(unittest.TestCase):
# With case sensitive turned on, it should pick the right function
functions
=
{
'
f
'
:
lambda
x
:
x
,
'
F
'
:
lambda
x
:
x
+
1
}
self
.
assertEqual
(
calc
.
evaluator
({},
functions
,
'
f(6)
'
,
case_sensitive
=
True
)
,
6
6
,
calc
.
evaluator
({},
functions
,
'
f(6)
'
,
case_sensitive
=
True
)
)
self
.
assertEqual
(
calc
.
evaluator
({},
functions
,
'
F(6)
'
,
case_sensitive
=
True
)
,
7
7
,
calc
.
evaluator
({},
functions
,
'
F(6)
'
,
case_sensitive
=
True
)
)
def
test_undefined_vars
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment