MCPcopy Create free account
hub / github.com/pydata/numexpr / test_weakref_expiry

Method test_weakref_expiry

numexpr3/tests/test_numexpr.py:81–103  ·  view source on GitHub ↗

import gc gc.enable() logger.warning('Test expiry of weak reference') x = np.arange(self.ssize) func = ne3.NumExpr( 'x+x' ) logging.warning( 'x is tracked: ' + str(gc.is_tracked(x) ) ) del x # kill original array, should expire weak ref in fu

(self)

Source from the content-addressed store, hash-verified

79 npt.assert_array_almost_equal( out, a*b )
80
81 def test_weakref_expiry(self):
82 # I have no idea how to turn on gc in unittest. I can't find anything
83 # in unittest that does that:
84 # https://github.com/python/cpython/tree/master/Lib/unittest
85 # This script works fine when run independantly.
86 '''
87 import gc
88 gc.enable()
89 logger.warning('Test expiry of weak reference')
90 x = np.arange(self.ssize)
91 func = ne3.NumExpr( 'x+x' )
92 logging.warning( 'x is tracked: ' + str(gc.is_tracked(x) ) )
93 del x # kill original array, should expire weak ref in func.registers
94 gc.collect(generation=2)
95 gc.collect(generation=1)
96 gc.collect(generation=0)
97 logging.warning( "Garbage is {}".format(gc.garbage ) )
98 # For some reason the garbage collection isn't performed inside unittest?
99 x = np.arange(self.ssize) + 50
100 out = func( verify=False )
101 npt.assert_array_almost_equal( x+x, out )
102 '''
103 pass
104
105 def test_copy_output(self):
106 logger.info( 'Test copy output' )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected