aboutsummaryrefslogtreecommitdiff
path: root/t/05_pysmobs.t
blob: 4ed2ccaf2cfcc0f139d64f7a22814a6081db598f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/guile -s
!#
; PyGuile tests - exercise pysmob handling.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (C) 2008 Omer Zak.
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public License
; along with this library, in a file named COPYING; if not, write to the
; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
; Boston, MA  02111-1307  USA
;
; For licensing issues, contact <w1@zak.co.il>.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
(use-modules (guiletap))
(use-modules (pyguile))

(plan 12)
(python-eval "import sys;sys.path = ['']+sys.path\n")
(define t5smobs (python-import "t.scripts.t5smobs"))

(is-ok 1 "Creation and repr" "opaq('abc')"
       (python-apply '("__builtin__" "repr")
		     (list (python-apply '("t.scripts.t5smobs" "opaq")
					 '("abc") '()))
		     '()))

(is-ok 2 "Creation and object->string" "(python-eval opaq('abcd') #t)"
       (object->string
	(python-apply '("t.scripts.t5smobs" "opaq")
		      '("abcd")
		      '())))

(define objt (python-apply '("t.scripts.t5smobs" "opaq")
			   '(37)
			   '()))
(is-ok 3 "Created opaq with numeric value" "(python-eval opaq(37) #t)"
       (object->string objt))

(python-apply (list objt "transform") '() '())
(is-ok 4 "After transforming opaq with numeric value"
       "(python-eval opaq(74) #t)"
       (object->string objt))

(define objl (python-apply '("t.scripts.t5smobs" "opaq")
			   '(("el1" "el2"))
			   '()))
(is-ok 5 "opaq with list value"
       "(python-eval opaq(['el1', 'el2']) #t)"
       (object->string objl))

(python-apply (list objl "transform") '() '())
(is-ok 6 "opaq with list value"
       "(python-eval opaq(['el1', 'el2', 'el1', 'el2']) #t)"
       (object->string objl))

(define equalities3?
  (lambda (obj1 obj2)
    (list (eq? obj1 obj2) (eqv? obj1 obj2) (equal? obj1 obj2))))

(is-ok 7 "verify equalities3?"
       '(#f #f #t)
       (equalities3? '("a" "b") '("a" "b")))

(define nd1 (python-apply (list t5smobs 'noisydelete) '("nd1a") '()))
(define nd2 (python-apply (list t5smobs 'noisydelete) '("nd2b") '()))
(define nd1same nd1)
(define nd1equal (python-apply (list t5smobs 'noisydelete) '("nd1a") '()))

(is-ok 8 "two different pysmobs"
       '(#f #f #f)
       (equalities3? nd1 nd2))

(is-ok 9 "two identical pysmobs"
       '(#t #t #t)
       (equalities3? nd1 nd1same))

(is-ok 10 "two equal pysmobs"
       '(#f #f #t)
       (equalities3? nd1 nd1equal))

(define nd-me (python-apply (list t5smobs 'noisydelete) '("me") '()))
(define nd-41 (python-apply (list t5smobs 'noisydelete) '(41) '()))
(define nd-42 (python-apply (list t5smobs 'noisydelete) '(42) '()))

(is-ok 11 "'me'!=41 to validate t5smobs.noisydelete.__cmp__ test"
       '(#f #f #f)
       (equalities3? nd-me nd-41))

(is-ok 12 "'me'==42 to prove t5smobs.noisydelete.__cmp__ is being executed"
       '(#f #f #t)
       (equalities3? nd-me nd-42))


; The following tests do not work as expected and I do not have yet
; a way to capture outputs.
; !!! Check strports.h (object->string, scm_object_to_string).

; Garbage collection behavior of pysmobs.
(define noisydel (python-apply (list t5smobs 'noisydelete) '("BOO!") '()))
(diagprint 1001 "verify noisydel object"
       "'BOO!'"
       (python-apply '("__builtin__" repr) (list noisydel) '()))
(display "# Forcing garbage collection...")
(gc)
(display "Done")(newline)
(diagprint 1002 "verify noisydel object after gc"
       "'BOO!'"
       (python-apply '("__builtin__" repr) (list noisydel) '()))
(set! noisydel "losing reference")
(display "# Forcing another garbage collection...")
(gc)
(display "Done - should show deletion of noisydel")
(newline)
(display "# ")(display noisydel)(newline)
(python-eval "import gc\ngc.collect()\n")
; End of 05_pysmobs.t