shithub: aubio

Download patch

ref: 5dc1abc932ef8040f2d66da5b3530741cfa65faa
parent: fb3f62e68a600cbb169b0a3ef7b53a6e568183dc
author: Paul Brossier <piem@piem.org>
date: Mon May 2 10:56:40 EDT 2016

python/tests/test_cvec.py: more tests

--- a/python/tests/test_cvec.py
+++ b/python/tests/test_cvec.py
@@ -46,6 +46,38 @@
         assert_equal(spec.phas[39:-1], -np.pi)
         assert_equal(spec.norm, 0)
 
+    def test_assign_cvec_with_other_cvec(self):
+        """ check dest cvec is still reachable after source was deleted """
+        spec = cvec(1024)
+        a = np.random.rand(1024/2+1).astype(float_type)
+        b = np.random.rand(1024/2+1).astype(float_type)
+        spec.norm = a
+        spec.phas = b
+        new_spec = spec
+        del spec
+        assert_equal(a, new_spec.norm)
+        assert_equal(b, new_spec.phas)
+        assert_equal(id(a), id(new_spec.norm))
+        assert_equal(id(b), id(new_spec.phas))
+
+    def test_pass_to_numpy(self):
+        spec = cvec(1024)
+        norm = spec.norm
+        phas = spec.phas
+        del spec
+        new_spec = cvec(1024)
+        new_spec.norm = norm
+        new_spec.phas = phas
+        assert_equal(norm, new_spec.norm)
+        assert_equal(phas, new_spec.phas)
+        assert_equal(id(norm), id(new_spec.norm))
+        assert_equal(id(phas), id(new_spec.phas))
+        del norm
+        del phas
+        assert_equal(new_spec.norm, 0.)
+        assert_equal(new_spec.phas, 0.)
+        del new_spec
+
 if __name__ == '__main__':
     from nose2 import main
     main()