]> gitweb.factorcode.org Git - factor.git/commitdiff
python.tests: more destructors & refcounting tests
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 27 Oct 2014 12:30:54 +0000 (13:30 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 27 Oct 2014 16:52:04 +0000 (09:52 -0700)
extra/python/python-tests.factor

index 837e73475b480d11515774efef6891903911796f..8e8e9f8634bc52fd65eff0502f9ed0a6089341e5 100644 (file)
@@ -1,10 +1,52 @@
-USING: accessors arrays assocs calendar continuations destructors fry kernel
-math namespaces python python.ffi python.objects sequences strings tools.test ;
+USING: accessors alien arrays assocs calendar continuations destructors
+destructors.private fry kernel math namespaces python python.errors python.ffi
+python.objects sequences strings tools.test ;
 IN: python
 
 : py-test ( result quot -- )
     '[ _ with-destructors ] unit-test ; inline
 
+! None testing
+{ t } [
+    "__builtin__" py-import "None" getattr <none> =
+] py-test
+
+! Pretty sure the # of None references should stay constant.
+{ t } [
+    [
+        "sys" py-import "getrefcount" getattr
+        <none> <1py-tuple> call-object py>
+    ] with-destructors
+    [
+        "sys" py-import "getrefcount" getattr
+        <none> <1py-tuple> call-object py>
+    ] with-destructors =
+] unit-test
+
+{ } [ { f f f } >py drop ] py-test
+
+! Destructors
+{ 1 } [ 33 >py drop always-destructors get length ] py-test
+
+{ 1 } [ f >py drop always-destructors get length ] py-test
+
+! The tuple steals the reference properly now.
+{ 1 } [ 33 >py <1py-tuple> drop always-destructors get length ] py-test
+
+{ 1 } [ { } >py drop always-destructors get length ] py-test
+
+{ 1 } [ V{ 1 2 3 4 } >py drop always-destructors get length ] py-test
+
+{ 2 } [
+    99 >py V{ 1 2 3 4 } >py 2drop always-destructors get length
+] py-test
+
+{ 1 } [
+    { { { 33 } } } >py drop always-destructors get length
+] py-test
+
+{ } [ 123 <alien> unsteal-ref ] unit-test
+
 [ t ] [ Py_GetVersion string? ] unit-test
 
 [ "os" ] [ "os" py-import PyModule_GetName ] py-test