Skip to content

Commit

Permalink
Add subprocess.check_call regression test for issue #313
Browse files Browse the repository at this point in the history
  • Loading branch information
robbmcleod committed Aug 16, 2018
1 parent 742628e commit e88d1a5
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions numexpr/tests/test_numexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
from distutils.version import LooseVersion
minimum_numpy_version = LooseVersion('1.7.0')

issue313 = "test that local_dict.clear() does not delete globals"

class test_numexpr(TestCase):
"""Testing with 1 thread"""
nthreads = 1
Expand Down Expand Up @@ -312,26 +310,32 @@ def test_where_scalar_bool(self):

def test_refcount(self):
# Regression test for issue #310

global issue313

a = array([1])
assert sys.getrefcount(a) == 2
evaluate('1')
assert sys.getrefcount(a) == 2

# Regression test for #313, ensure that globals is never `.clear`'d
# accidently when trying to remove the extraneous reference count
# the call to f_locals generates.
issue313 += '.'

# Try permutations of providing `local_dict` and `global_dict`
evaluate('2+2', local_dict={})
issue313 += '.'
evaluate('3+3', global_dict={})
issue313 += '.'
evaluate('4+4', local_dict={}, global_dict={})
issue313 += '.'
def test_locals_clears_globals(self):
# Check for issue #313, whereby clearing f_locals also clear f_globals
# if in the top-frame. This cannot be done inside `unittest` as it is always
# executing code in a child frame.
import subprocess
script = ';'.join([
"import numexpr as ne",
"a=10",
"ne.evaluate('1')",
"a += 1",
r"ne.evaluate('2', local_dict={})",
"a += 1",
r"ne.evaluate('3', global_dict={})",
"a += 1",
r"ne.evaluate('4', local_dict={}, global_dict={})",
"a += 1",
])
# Raises CalledProcessError on a non-normal exit
check = subprocess.check_call('python -c "{}"'.format(script))

This comment has been minimized.

Copy link
@avalentino

avalentino Aug 16, 2018

Contributor

please use sys.executable here

This comment has been minimized.

Copy link
@robbmcleod

robbmcleod Aug 16, 2018

Author Member

Ok done.

# Ideally this test should also be done against ipython but it's not
# a requirement.



Expand Down

0 comments on commit e88d1a5

Please sign in to comment.