aboutsummaryrefslogtreecommitdiff
path: root/t/06_guile2python.t
blob: 346d478224360fee6769ec97f2aac5c2aac20414 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/guile -s
!#
; Additional Pyguile tests - transferring data from Guile to Python.
; Tests added to complete code coverage.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 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 13)

(is-ok 1 "Float 1.5" "1.5"
       (python-apply '("__builtin__" repr) '(1.5) '()))
(is-ok 2 "Float 1000000000.5" "1000000000.5"
       (python-apply '("__builtin__" repr) '(1000000000.5) '()))
(is-ok 3 "Float 1e+20" "1e+20"
       (python-apply '("__builtin__" repr) '(100000000000000000000.5) '()))

(is-ok 4 "Complex" "[(1+1j), (2-3j), (-3-4j), (-4+5j)]"
       (python-apply '("__builtin__" repr) '((1+1i 2-3i -3-4i -4+5i)) '()))

;(if (equal? (effective-version) "1.6")
;    (is-ok 5 "Dash-only keyword" "''"
;		(python-apply '("__builtin__" repr) '(#:) '()))
;    (ok 5 "Dash-only keyword not supported in Guile 1.8" #t))
(ok 5 "Dash-only keyword not supported in Guile 1.8" #t)

;(if (equal? (effective-version) "1.6")
;    (is-ok 6 "String, symbol and keywords (version 1.6.x)"
;		"['abc', 'def', 'ghi', 'gh', 'g', '']"
;		(python-apply '("__builtin__" repr)
;			      '(("abc" def #:ghi #:gh #:g #:))
;			      '()))
;    (is-ok 6 "String, symbol and keywords (version 1.8.x)"
;		"['abc', 'def', 'ghi', 'gh', 'g']"
;		(python-apply '("__builtin__" repr)
;			      '(("abc" def #:ghi #:gh #:g))
;			      '())))
(is-ok 6 "String, symbol and keywords (version 1.8 compatible)"
	    "['abc', 'def', 'ghi', 'gh', 'g']"
	    (python-apply '("__builtin__" repr)
			  '(("abc" def #:ghi #:gh #:g))
			  '()))

; Illegal positional keyword arguments handling

(is-ok 7 "Positional argument list is not legal list"
	   '(misc-error ("python-apply" "positional arguments conversion failure (~S)" (42) #f))
	   (catch #t
		  (lambda () (python-apply '("__builtin__" repr)
					   42
					   '()))
		  (lambda (key . args) (list key args))))


; Illegal keyword arguments handling

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

(is-ok 8 "good alist" "positional: ('a',)      keywords: {'arg1': 'b'}"
       (catch #t
	      (lambda () (python-apply '("t.scripts.t4apply" return_args)
				       '("a")
				       '((#:arg1 . "b"))))
	      (lambda (key . args) (list key args))))

(is-ok 9 "bad alist - not list"
       '(wrong-type-arg ("guileassoc2pythondict"
			 "Wrong type argument in position ~A: ~S"
			 (1 "b")
			 #f))
       (catch #t
	      (lambda () (python-apply '("t.scripts.t4apply" return_args)
				       '("a")
				       '("b")))
	      (lambda (key . args) (list key args))))

(is-ok 10 "bad alist - item not pair"
       '(wrong-type-arg ("guileassoc2pythondict"
			 "Wrong type argument in position ~A: ~S"
			 (2 "c")
			 #f))
       (catch #t
	      (lambda () (python-apply '("t.scripts.t4apply" return_args)
				       '("a")
				       '((#:b . 3) "c" (#:d . 5))))
	      (lambda (key . args) (list key args))))

(is-ok 11 "bad alist - key not string"
       '(wrong-type-arg ("guileassoc2pythondict"
			 "Wrong type argument in position ~A: ~S"
			 (2 4)
			 #f))
       (catch #t
	      (lambda () (python-apply '("t.scripts.t4apply" return_args)
				       '("a")
				       '((#:b . 3) (4 . "c") ("d" . 5))))
	      (lambda (key . args) (list key args))))


(is-ok 12 "bad alist - duplicate key"
       '(misc-error ("guileassoc2pythondict"
		     "duplicate key (~S)"
		     (#:b)
		     #f))
       (catch #t
	      (lambda () (python-apply '("t.scripts.t4apply" return_args)
				       '("a")
				       '((#:b . 3) (#:c . 4) (#:b . 5))))
	      (lambda (key . args) (list key args))))

(like 13 "bad alist - inconvertible data"
      "^\\(wrong-type-arg \\(\"guile2python\" \"Wrong type argument in position ~A: ~S\" \\(1 #<input: [^>]*>\\) #f\\)\\)$"
      (catch #t
	     (lambda () (python-apply '("t.scripts.t4apply" return_args)
				      '("a")
				      `((#:b . 3)
					(#:c . 4)
					(#:d . ,(current-input-port)))))
	     (lambda (key . args) (object->string (list key args)))))

; End of 06_guile2python.t