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
55b67e39
Commit
55b67e39
authored
Aug 15, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
common/lib/calc/calc.py
+0
-5
common/lib/calc/tests/test_calc.py
+13
-8
No files found.
common/lib/calc/calc.py
View file @
55b67e39
...
@@ -11,11 +11,6 @@ import numpy
...
@@ -11,11 +11,6 @@ import numpy
import
scipy.constants
import
scipy.constants
import
calcfunctions
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
(
from
pyparsing
import
(
Word
,
Literal
,
CaselessLiteral
,
ZeroOrMore
,
MatchFirst
,
Optional
,
Forward
,
Word
,
Literal
,
CaselessLiteral
,
ZeroOrMore
,
MatchFirst
,
Optional
,
Forward
,
Group
,
ParseResults
,
stringEnd
,
Suppress
,
Combine
,
alphas
,
nums
,
alphanums
Group
,
ParseResults
,
stringEnd
,
Suppress
,
Combine
,
alphas
,
nums
,
alphanums
...
...
common/lib/calc/tests/test_calc.py
View file @
55b67e39
...
@@ -7,6 +7,12 @@ import numpy
...
@@ -7,6 +7,12 @@ import numpy
import
calc
import
calc
from
pyparsing
import
ParseException
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
):
class
EvaluatorTest
(
unittest
.
TestCase
):
"""
"""
...
@@ -186,17 +192,16 @@ 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_inputs
=
[
'-0.707'
,
'0'
,
'0.5'
,
'0.588'
,
'1.298 + 0.635*j'
]
arcsin_angles
=
[
-
0.785
,
0
,
0.524
,
0.629
,
1
+
1
j
]
arcsin_angles
=
[
-
0.785
,
0
,
0.524
,
0.629
,
1
+
1
j
]
self
.
assert_function_values
(
'arcsin'
,
arcsin_inputs
,
arcsin_angles
)
self
.
assert_function_values
(
'arcsin'
,
arcsin_inputs
,
arcsin_angles
)
# Rather than throwing an exception, numpy.arcsin gives nan
# 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)'
)))
# 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... :-/
# Include those where the real part is between 0 and pi
# Include those where the real part is between 0 and pi
arccos_inputs
=
[
'1'
,
'0.866'
,
'0.809'
,
'0.834-0.989*j'
]
arccos_inputs
=
[
'1'
,
'0.866'
,
'0.809'
,
'0.834-0.989*j'
]
arccos_angles
=
[
0
,
0.524
,
0.628
,
1
+
1
j
]
arccos_angles
=
[
0
,
0.524
,
0.628
,
1
+
1
j
]
self
.
assert_function_values
(
'arccos'
,
arccos_inputs
,
arccos_angles
)
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
# Has the same range as arcsin
arctan_inputs
=
[
'-1'
,
'0'
,
'0.577'
,
'0.727'
,
'0.272 + 1.084*j'
]
arctan_inputs
=
[
'-1'
,
'0'
,
'0.577'
,
'0.727'
,
'0.272 + 1.084*j'
]
...
@@ -535,10 +540,10 @@ class EvaluatorTest(unittest.TestCase):
...
@@ -535,10 +540,10 @@ class EvaluatorTest(unittest.TestCase):
# With case sensitive turned on, it should pick the right function
# With case sensitive turned on, it should pick the right function
functions
=
{
'f'
:
lambda
x
:
x
,
'F'
:
lambda
x
:
x
+
1
}
functions
=
{
'f'
:
lambda
x
:
x
,
'F'
:
lambda
x
:
x
+
1
}
self
.
assertEqual
(
self
.
assertEqual
(
calc
.
evaluator
({},
functions
,
'f(6)'
,
case_sensitive
=
True
),
6
6
,
calc
.
evaluator
({},
functions
,
'f(6)'
,
case_sensitive
=
True
)
)
)
self
.
assertEqual
(
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
):
def
test_undefined_vars
(
self
):
...
...
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