diff options
author | Omer Zak <w1@zak.co.il> | 2016-05-22 11:03:43 +0300 |
---|---|---|
committer | Omer Zak <w1@zak.co.il> | 2016-05-22 11:03:43 +0300 |
commit | c26aec892f26ee21067a0beb9dd79a8c834e6dba (patch) | |
tree | e06cc2a5e207b089fa324faaf9114267edaa0e3a /t | |
parent | 7abc0d1d0b05198e10f5207aa17f1c14e37c0fa7 (diff) | |
download | pyguile-c26aec892f26ee21067a0beb9dd79a8c834e6dba.tar pyguile-c26aec892f26ee21067a0beb9dd79a8c834e6dba.tar.gz |
Added all old files of interest to version control.
Diffstat (limited to 't')
-rwxr-xr-x | t/01_basic.t | 34 | ||||
-rw-r--r-- | t/02_pyguile.t | 49 | ||||
-rw-r--r-- | t/03_guile2python.t | 58 | ||||
-rw-r--r-- | t/04_python_apply.t | 66 | ||||
-rw-r--r-- | t/05_pysmobs.t | 128 | ||||
-rw-r--r-- | t/06_guile2python.t | 143 | ||||
-rw-r--r-- | t/07_apply.t | 129 | ||||
-rw-r--r-- | t/08_eval.t | 69 | ||||
-rw-r--r-- | t/09_import.t | 59 | ||||
-rw-r--r-- | t/10_python2guile.t | 56 | ||||
-rw-r--r-- | t/11_g2p2g.t | 49 | ||||
-rw-r--r-- | t/12_g2p_templated.t | 225 | ||||
-rw-r--r-- | t/13_hashes.t | 167 | ||||
-rw-r--r-- | t/14_p2g_templated.t | 293 | ||||
-rw-r--r-- | t/15_p2g_errors.t | 126 | ||||
-rwxr-xr-x | t/16_verbose.t | 50 | ||||
-rw-r--r-- | t/17_verbose.t | 161 | ||||
-rw-r--r-- | t/18_bignum.t | 55 | ||||
-rw-r--r-- | t/19_verbose_always.t | 733 | ||||
-rw-r--r-- | t/20_pyscm.t | 247 | ||||
-rw-r--r-- | t/__init__.py | 2 | ||||
-rwxr-xr-x | t/scripts/RunGuileTests.pl | 36 | ||||
-rw-r--r-- | t/scripts/__init__.py | 0 | ||||
-rw-r--r-- | t/scripts/t2conv.py | 67 | ||||
-rw-r--r-- | t/scripts/t4apply.py | 46 | ||||
-rw-r--r-- | t/scripts/t5smobs.py | 51 | ||||
-rw-r--r-- | t/scripts/t7except.py | 32 | ||||
-rw-r--r-- | t/scripts/test_auxiliary_functions.scm | 177 |
28 files changed, 3308 insertions, 0 deletions
diff --git a/t/01_basic.t b/t/01_basic.t new file mode 100755 index 0000000..acce403 --- /dev/null +++ b/t/01_basic.t @@ -0,0 +1,34 @@ +#!/usr/bin/guile -s +!# +; Basic tests of the guiletap module (for TAP based test scripting). +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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)) + +(plan 4) +(ok 1 "Should pass" #t) +(ok 2 "Should fail # TODO deliberate failure" #f) +(is-ok 3 "Should be okay" '(1 . "abc") (cons 1 (string-append "a" "bc"))) +(is-ok 4 "Should not be okay # TODO deliberate failure" '(3 . "def") '(3 "def")) + +; End of 01_basic.t diff --git a/t/02_pyguile.t b/t/02_pyguile.t new file mode 100644 index 0000000..5eea12f --- /dev/null +++ b/t/02_pyguile.t @@ -0,0 +1,49 @@ +#!/usr/bin/guile -s +!# +; Pyguile tests - transferring data from Python to Guile +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 10) +(python-eval "import sys;sys.path = ['']+sys.path\n") +(python-eval "from t.scripts.t2conv import *\n") + +;(if (python-import "t.scripts.t2conv") (ok 1 "Imported t2conv" #t) +; (bail-out "Could not import t2conv")) + +(is-ok 1 "None" 0 (length (python-eval "return_None()" #t))) +(is-ok 2 "True" #t (python-eval "return_True()" #t)) +(is-ok 3 "False" #f (python-eval "return_False()" #t)) +(is-ok 4 "1" 1 (python-eval "return_Int1()" #t)) +(is-ok 5 "-5" -5 (python-eval "return_Int_5()" #t)) +(is-ok 6 "2^65" 36893488147419103232 (python-eval "return_BigInt()" #t)) +(is-ok 7 "-2^65" -36893488147419103232 (python-eval "return_BigInt_neg()" #t)) +(is-ok 8 "string 1" "abcdefghi" (python-eval "return_String1()" #t)) +(is-ok 9 "string 2" "01abCD%^" (python-eval "return_String2()" #t)) +(is-ok 10 "string 3" + (string-append "bef" (list->string (list (integer->char 0) (integer->char 163))) "ore") + (python-eval "return_String_Zero()" #t)) + +; End of 02_pyguile.t diff --git a/t/03_guile2python.t b/t/03_guile2python.t new file mode 100644 index 0000000..9ef7964 --- /dev/null +++ b/t/03_guile2python.t @@ -0,0 +1,58 @@ +#!/usr/bin/guile -s +!# +; Pyguile tests - transferring data from Guile to Python. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 14) + +(define invoke-python-func + (lambda (module func arg) + (python-apply (list module func) (list arg) '()))) + +(is-ok 1 "None" "None" (invoke-python-func "__builtin__" "repr" (list))) +(is-ok 2 "True" "True" (invoke-python-func "__builtin__" "repr" #t)) +(is-ok 3 "False" "False" (invoke-python-func "__builtin__" "repr" #f)) +(is-ok 4 "int 1" "1" (invoke-python-func "__builtin__" "repr" 1)) +(is-ok 5 "int -5" "-5" (invoke-python-func "__builtin__" "repr" -5)) +(is-ok 6 "string 1" "'string 1'" + (invoke-python-func "__builtin__" "repr" "string 1")) +(is-ok 7 "char P" "'P'" (invoke-python-func "__builtin__" "repr" #\P)) +(is-ok 8 "symbol symba" "'symba'" + (invoke-python-func "__builtin__" "repr" 'symba)) +(is-ok 9 "complex 1-1i" "(1-1j)" (invoke-python-func "__builtin__" "repr" 1-1i)) +(is-ok 10 "float 3.125" "3.125" (invoke-python-func "__builtin__" "repr" 3.125)) +(define big10to7th 10000000) +(define big10to35th (* big10to7th big10to7th big10to7th big10to7th big10to7th)) +(is-ok 11 "bignum 10^35" "100000000000000000000000000000000000L" + (invoke-python-func "__builtin__" "repr" big10to35th)) +(is-ok 12 "pair" "('mycar', 42)" + (invoke-python-func "__builtin__" "repr" (cons "mycar" (* 21 2)))) +(is-ok 13 "list 1" "['item1', 'item2', 'item3']" + (invoke-python-func "__builtin__" "repr" '(item1 item2 "item3"))) +(is-ok 14 "list 2" "['lambda', ['arg1', 'arg2'], ['display', 'textA'], ['newline'], ['display', 'arg1'], ['newline'], ['display', 'arg2']]" + (invoke-python-func "__builtin__" "repr" '(lambda (arg1 arg2)(display "textA")(newline)(display arg1)(newline)(display arg2)))) + +; End of 03_guile2python.t diff --git a/t/04_python_apply.t b/t/04_python_apply.t new file mode 100644 index 0000000..a22fd3a --- /dev/null +++ b/t/04_python_apply.t @@ -0,0 +1,66 @@ +#!/usr/bin/guile -s +!# +; Pyguile tests - exercise python-apply +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 10) +(python-import "os.path") + +(is-ok 1 "exists" #t + (python-apply '("os.path" exists) '("t/04_python_apply.t") '())) +(is-ok 2 "does not exist" #f + (python-apply '("os.path" exists) '("t/04_python_apply.tnone") '())) +(is-ok 3 "join 3 arguments" "Pyguile/t/04_python_apply.t" + (python-apply '("os.path" "join") '("Pyguile" "t" "04_python_apply.t") '())) + +(python-eval "import sys;sys.path = ['']+sys.path\n") +(python-import "t.scripts.t4apply") + +(is-ok 4 "object path without arguments" "33y" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '() '())) + +(is-ok 5 "object path with positional argument as symbol" "33pos" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '(pos) '())) + +(is-ok 6 "object path with positional argument as string" "33:str" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '(":str") '())) + +(is-ok 7 "object path with kw+argument as symbols" "33symkw" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '() '((#:argx . symkw )))) + +(is-ok 8 "object path with kw+argument as strings" "33=strkw" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '() '((#:argx . "=strkw" )))) + +(is-ok 9 "object path with kw symbol, argument as string" "33<><>" + (python-apply '("t.scripts.t4apply" mainobj "cl2func") '() '((#:argx . "<><>" )))) + +(is-ok 10 "Return arguments" "positional: (True, 1, -3, 'mystr', 'symbolic') keywords: {'kw4n': 65537, 'keyword1': 'symb1', 'kw3': 'trying3', 'KW_stri2': 'symb2'}" + (python-apply '("t.scripts.t4apply" return_args) + '(#t 1 -3 "mystr" symbolic) + '((#:keyword1 . symb1) (#:KW_stri2 . symb2) + (#:kw3 . #:trying3 ) (#:kw4n . 65537)))) + +; End of 04_guile2python.t diff --git a/t/05_pysmobs.t b/t/05_pysmobs.t new file mode 100644 index 0000000..4ed2cca --- /dev/null +++ b/t/05_pysmobs.t @@ -0,0 +1,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 diff --git a/t/06_guile2python.t b/t/06_guile2python.t new file mode 100644 index 0000000..346d478 --- /dev/null +++ b/t/06_guile2python.t @@ -0,0 +1,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 diff --git a/t/07_apply.t b/t/07_apply.t new file mode 100644 index 0000000..368bc3f --- /dev/null +++ b/t/07_apply.t @@ -0,0 +1,129 @@ +#!/usr/bin/guile -s +!# +; Additional Pyguile tests - python-apply tests. +; 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 18) + +(python-eval "import sys;sys.path = ['']+sys.path\n") +(python-eval "from t.scripts.t4apply import return_args") +(python-eval "def myfunc():\n return('this was myfunc')\n") + +(define myfunc-smob (python-eval "myfunc" #t)) + +(is-ok 1 "string funcname" "positional: ('xyzzy',) keywords: {}" + (python-apply "return_args" '(xyzzy) '())) + +(is-ok 2 "symbol funcname" "positional: () keywords: {'arg': 7}" + (python-apply #:return_args '() '((#:arg . 7)))) + +(is-ok 3 "pysmob func" "this was myfunc" + (python-apply myfunc-smob '() '())) + +(is-ok 4 "list consisting of pysmob func" "this was myfunc" + (python-apply (list myfunc-smob) '() '())) + + +; python-apply funcname tests + +(is-ok 5 "funcname not in list and is illegal" + '(wrong-type-arg ("python-apply" "Wrong type argument in position ~A: ~S" (1 42) #f)) + (catch #t + (lambda () (python-apply 42 '("a") '((#:arg1 . "b")))) + (lambda (key . args) (list key args)))) + +(is-ok 6 "funcname in list and is illegal" + ;like 6: "^\\(misc-error \\(\"python-apply\" \"Python exception: ~A\" \\(\"<class exceptions.TypeError at 0x[0-9a-f]{8}>\"\\) #f\\)\\)$" + "(misc-error (\"python-apply\" \"function denoted by ~S is not callable\" ((45)) #f))" + (catch #t + (lambda () (python-apply '(45) '("a") '((#:arg1 . "b")))) + (lambda (key . args) (object->string (list key args))))) + +(is-ok 7 "non-imported module" + "(misc-error (\"python-apply\" \"could not dereference ~Ath level attribute in ~S\" (1 (\"math\" sin)) #f))" + (catch #t + (lambda () (python-apply '("math" sin) '(3.14159) '())) + (lambda (key . args) (object->string (list key args))))) + +(define t2conv (python-import "t.scripts.t2conv")) + +; Run python-apply under catch harness. +(define catch-test + (lambda (func posargs kwargs) + (catch #t + (lambda () (python-apply func posargs kwargs)) + (lambda (key . args) (object->string (list key args)))))) + +(is-ok 8 "finding attribute in module by string" + -5 + (catch-test '("t.scripts.t2conv" "return_Int_5") '() '())) + +(is-ok 9 "nonexistent attribute in module by string" + "(misc-error (\"python-apply\" \"could not dereference ~Ath level attribute in ~S\" (1 (\"t.scripts.t2conv\" \"return_jnt_5\")) #f))" + (catch-test '("t.scripts.t2conv" "return_jnt_5") '() '())) + +(is-ok 10 "finding attribute in module by symbol" + -5 + (catch-test '("t.scripts.t2conv" return_Int_5) '() '())) + +(is-ok 11 "nonexistent attribute in module by symbol" + "(misc-error (\"python-apply\" \"could not dereference ~Ath level attribute in ~S\" (1 (\"t.scripts.t2conv\" return_jnt_5)) #f))" + (catch-test '("t.scripts.t2conv" return_jnt_5) '() '())) + +(is-ok 12 "finding attribute in module by pysmob" + -5 + (catch-test (list t2conv "return_Int_5") '() '())) + +(is-ok 13 "nonexistent attribute in module by pysmob" + "(misc-error (\"python-apply\" \"could not dereference ~Ath level attribute in ~S\" (1 ((python-eval <module 't.scripts.t2conv' from 't/scripts/t2conv.pyc'> #t) \"return_jnt_5\")) #f))" + (catch-test (list t2conv "return_jnt_5") '() '())) + +; Python function raises uncaught exception during its work. + +(define t7except (python-import "t.scripts.t7except")) + +(like 14 "exception inside Python code" + "^\\(misc-error \\(\"python-apply\" \"Python exception: ~A\" \\(\"<class t.scripts.t7except.myexception at 0x[0-9a-f]{8}>\"\\) #f\\)\\)$" + (catch-test (list t7except 'raiser) '(script7) '())) + +(is-ok 15 "kw argument is datum rather than list" + "(wrong-type-arg (\"guileassoc2pythondict\" \"Wrong type argument in position ~A: ~S\" (1 \"shut up\") #f))" + (catch-test '("__builtin__" repr) '((3 4 5)) "shut up")) + +(is-ok 16 "kw argument is pair rather than list" + "(wrong-type-arg (\"guileassoc2pythondict\" \"Wrong type argument in position ~A: ~S\" (1 (\"shut\" . \"up\")) #f))" + (catch-test '("__builtin__" repr) '((3 4 5)) '("shut" . "up"))) + +(is-ok 17 "no proc specified" + "(wrong-type-arg (\"python-apply\" \"Wrong type argument in position ~A: ~S\" (1 ()) #f))" + (catch-test '() '() '())) + +(is-ok 18 "nonexistent module" + "(misc-error (\"python-apply\" \"could not dereference ~Ath level attribute in ~S\" (1 (\"no.such.module\" repr)) #f))" + (catch-test '("no.such.module" repr) '((3 4 5)) '("shut" . "up"))) + +; End of 07_apply.t diff --git a/t/08_eval.t b/t/08_eval.t new file mode 100644 index 0000000..96d1dcb --- /dev/null +++ b/t/08_eval.t @@ -0,0 +1,69 @@ +#!/usr/bin/guile -s +!# +; python-eval tests. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 7) + +(is-ok 1 "regular python-eval" + 42 + (python-eval "7*3*2" #t)) + + +; Run python-eval under catch harness. +(define catch-test-eval + (lambda (txt retval) + (catch #t + (lambda () (python-eval txt retval)) + (lambda (key . args) (object->string (list key args)))))) + +(is-ok 2 "trying to run python-eval on non-string" + "(wrong-type-arg (\"python-eval\" \"Wrong type argument in position ~A: ~S\" (1 -42) #f))" + (catch-test-eval -42 #t)) + +(is-ok 3 "trying to run python-eval with non-boolean/non-P2G_SMOB argument" + "(misc-error (\"p2g_apply\" \"bad template item ~S\" (42) #f))" + (catch-test-eval "7*3*2" 42)) + +(like 4 "Raising exception inside python-eval f" + "\\(misc-error \\(\"python-eval\" \"Python exception: ~A\" \\(\"<class exceptions.ImportError at 0x[0-9a-f]{8}>\"\\) #f\\)\\)" + (catch-test-eval "import t7except\nraiser('xyzzy')\n" #f)) + +(python-eval "import sys;sys.path = ['']+sys.path\n") +(python-eval "from t.scripts.t7except import raiser") +(like 5 "Raising exception inside python-eval t" + "^\\(misc-error \\(\"python-eval\" \"Python exception: ~A\" \\(\"<class t.scripts.t7except.myexception at 0x[0-9a-f]{8}>\"\\) #f\\)\\)$" + (catch-test-eval "1+raiser('foo fee dom')" #t)) + +(like 6 "code does not return requested result" + "^\\(misc-error \\(\"python-eval\" \"Python exception: ~A\" \\(\"<class exceptions.SyntaxError at 0x[0-9a-f]{8}>\"\\) #f\\)\\)$" + (catch-test-eval "print '# no value was returned'\n" #t)) + +(is-ok 7 "code returns unsolicited result" + "#<unspecified>" + (object->string (python-eval "99+101" #f))) + +; End of 08_eval.t diff --git a/t/09_import.t b/t/09_import.t new file mode 100644 index 0000000..4d2c406 --- /dev/null +++ b/t/09_import.t @@ -0,0 +1,59 @@ +#!/usr/bin/guile -s +!# +; python-import tests. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 5) + +; Run python-import under catch harness. +(define catch-test-import + (lambda (arg) + (catch #t + (lambda () (python-import arg)) + (lambda (key . args) (object->string (list key args)))))) + +(like 1 "good python-import" + "^\\(python-eval <module 'math' from '[^']*'> #t\\)$" + (object->string (catch-test-import "math"))) + +(like 2 "nonexistent module" + "^\\(misc-error \\(\"python-import\" \"Python exception during module ~A import: ~A\" \\(\"mathalternate\" \"<class exceptions.ImportError at 0x[0-9a-f]{8}>\"\\) #f\\)\\)$" + (catch-test-import "mathalternate")) + +(is-ok 3 "bad argument datatype" + "(wrong-type-arg (\"python-import\" \"Wrong type argument in position ~A: ~S\" (1 2.7818) #f))" + (catch-test-import 2.7818)) + +(is-ok 4 "python-import with symbol" + "(wrong-type-arg (\"python-import\" \"Wrong type argument in position ~A: ~S\" (1 os.path) #f))" + (catch-test-import 'os.path)) + +(is-ok 5 "python-import with keyword" + "(wrong-type-arg (\"python-import\" \"Wrong type argument in position ~A: ~S\" (1 #:re) #f))" + (catch-test-import #:re)) + + +; End of 09_import.t diff --git a/t/10_python2guile.t b/t/10_python2guile.t new file mode 100644 index 0000000..9c57829 --- /dev/null +++ b/t/10_python2guile.t @@ -0,0 +1,56 @@ +#!/usr/bin/guile -s +!# +; Additional PyGuile tests - transferring data from Python to Guile. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 8) + +(is-ok 1 "Float 1.5" 1.5 + (python-eval "1.5" #t)) + +(is-ok 2 "Float 10000000.5" 10000000.5 + (python-eval "10000000 + 0.5" #t)) + +(is-ok 3 "Float 1e+20" 1e20 + (python-eval "1e11*1e9" #t)) + +(is-ok 4 "Complex" '(1.0+1.0i 2.0-3.0i -3.0-4.0i -4.0+5.0i) + (python-eval "[1+1j,2-3j,-3-4j,-4+5j]" #t)) + +(is-ok 5 "bigint" 123456789101112131415 + (python-eval "15 + 100*1234567891011121314" #t)) + +(is-ok 6 "list" '("ab" "cd") + (python-eval "['ab','cd']" #t)) + +(is-ok 7 "tuple" '("ab" "cd") + (python-eval "('ab','cd')" #t)) + +; !!! Need to sort to ensure consistent test results. +(is-ok 8 "dict" '((6 . (78 90)) (3 . "4.5") (1 . 2.2)) + (python-eval "{1 : 2.2, 3 : '4.5', 6 : (78,90)}" #t)) + +; End of 10_python2guile.t diff --git a/t/11_g2p2g.t b/t/11_g2p2g.t new file mode 100644 index 0000000..de7721f --- /dev/null +++ b/t/11_g2p2g.t @@ -0,0 +1,49 @@ +#!/usr/bin/guile -s +!# +; Basic g2p2g_smob tests +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 6) + +(is-ok 1 "g2p_null2PyNone" "'g2p_null2PyNone" + (with-output-to-string (lambda () (display g2p_null2PyNone)))) + +(is-ok 2 "guile2python" "'guile2python" + (with-output-to-string (lambda () (display guile2python)))) + +(is-ok 3 "guileassoc2pythondict" "'guileassoc2pythondict" + (with-output-to-string (lambda () (display guileassoc2pythondict)))) + +(is-ok 4 "p2g_None2SCM_EOL" "'p2g_None2SCM_EOL" + (with-output-to-string (lambda () (display p2g_None2SCM_EOL)))) + +(is-ok 5 "p2g_Dict2alist" "'p2g_Dict2alist" + (with-output-to-string (lambda () (display p2g_Dict2alist)))) + +(is-ok 6 "python2guile" "'python2guile" + (with-output-to-string (lambda () (display python2guile)))) + +; End of 11_g2p2g.t diff --git a/t/12_g2p_templated.t b/t/12_g2p_templated.t new file mode 100644 index 0000000..7956443 --- /dev/null +++ b/t/12_g2p_templated.t @@ -0,0 +1,225 @@ +#!/usr/bin/guile -s +!# +; Basic g2p template tests +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 36) + +(is-ok 1 "real" "1.0" + (python-apply '("__builtin__" "repr") '(1.0) '() (list g2p_list2Tuple g2p_real2Float))) + +(is-ok 2 "int" "3" + (python-apply '("__builtin__" "repr") '(3) '() (list g2p_list2Tuple g2p_num2Int))) + +(is-ok 3 "mixed int-real" "[4, 5.0, 6, 7.0, 8]" + (python-apply '("__builtin__" "repr") '((4 5 6 7 8)) '() + (list g2p_list2Tuple (list g2p_list2List g2p_num2Int g2p_real2Float)))) + +(is-ok 4 "mixed int-real(tuple)" "(4, 5.0, 6, 7.0, 8)" + (python-apply '("__builtin__" "repr") '((4 5 6 7 8)) '() + (list g2p_list2Tuple (list g2p_list2Tuple g2p_num2Int g2p_real2Float)))) + +(is-ok 5 "list2Tuple" "(4.0, 5.0, 6.0, 7.0, 8.0)" + (python-apply '("__builtin__" "repr") '((4 5 6 7 8)) '() + (list g2p_list2Tuple (cons g2p_list2Tuple g2p_real2Float)))) + +(is-ok 6 "bool vs. int -> List" "[True, 5, 6, 7, False]" + (python-apply '("__builtin__" "repr") '((#t 5 6 7 #f)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_bool2Bool))))) + +(is-ok 7 "pair2tuple" "('a', 5)" + (python-apply '("__builtin__" "repr") '(("a" . 5)) '() + (list g2p_list2Tuple (cons g2p_pair2Tuple (cons g2p_string2String g2p_num2Int))))) + +(is-ok 8 "pair2list" "['c', 55]" + (python-apply '("__builtin__" "repr") '(("c" . 55)) '() + (list g2p_list2Tuple (cons g2p_pair2List (cons g2p_string2String g2p_num2Int))))) + +; Run python-apply under catch harness. +(define catch-test-apply + (lambda (func args kws . targ) + (catch #t + (lambda () (python-apply func args kws (car targ))) + (lambda (key . args2) (object->string (list key args2)))))) + +(is-ok 9 "bad template in g2p_apply" + "(misc-error (\"g2p_apply\" \"bad template item ~S\" (\"pooh\") #f))" + (catch-test-apply '("__builtin__" "repr") '() '() "pooh")) + +(is-ok 10 "bad template 2 in g2p_apply" + "(misc-error (\"g2p_apply\" \"bad template CAR item ~S\" (\"pooh\") #f))" + (catch-test-apply '("__builtin__" "repr") '() '() '("pooh" . "bar"))) + +(is-ok 11 "g2p_leaf in pair" "'pair'" + (python-apply '("__builtin__" "repr") '("pair") '() (list g2p_list2Tuple (cons g2p_leaf g2p_string2String)))) + +(is-ok 12 "g2p_leaf missing conversion datatype" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((#t 5 \"rude\" 7 #f))) #f))" + (catch-test-apply '("__builtin__" "repr") '((#t 5 "rude" 7 #f)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_bool2Bool))))) + +; Exercise various g2p_* functions not otherwise covered. + +(is-ok 13 "null" "None" + (python-apply '("__builtin__" "repr") '(()) '() + (list g2p_list2Tuple (list g2p_null2PyNone)))) + +(is-ok 14 "Other nulls" "[(), [], {}]" + (python-apply '("__builtin__" "repr") '((() () ())) '() + (list g2p_list2Tuple (list g2p_list2List g2p_null2Tuple0 g2p_null2List0 g2p_null2DictEmpty)))) + +(is-ok 15 "g2p_copmlex" + "[1, 2, 3.5, (4+6j)]" + (python-apply '("__builtin__" "repr") '((1 2 3.5 4+6i)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_real2Float g2p_complex2Complex))))) + +(is-ok 16 "bignums" + "[1000000, 100000000, 10000000000L, 1000000000000L]" + (python-apply '("__builtin__" "repr") '((1000000 100000000 10000000000 1000000000000)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_bignum2Long g2p_num2Int))))) + +; Exercise g2p_pair2Tuple with bad templates and data + +(is-ok 17 "bad template for g2p_pair2Tuple" + "(misc-error (\"g2p_pair2Tuple\" \"bad template ~S\" (\"pooh\") #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2Tuple "pooh")))) + +(is-ok 18 "validate datatype tests for g2p_pair2Tuple" + "(1, 2)" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2Tuple (cons g2p_num2Int g2p_num2Int))))) + +(is-ok 19 "bad CAR datatype for g2p_pair2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((1 . 2))) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2Tuple (cons g2p_bool2Bool g2p_num2Int))))) + +(is-ok 20 "bad CDR datatype for g2p_pair2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((1 . 2))) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2Tuple (cons g2p_num2Int g2p_bool2Bool))))) + +; Exercise g2p_pair2List with bad templates and data + +(is-ok 21 "bad template for g2p_pair2List" + "(misc-error (\"g2p_pair2List\" \"bad template ~S\" (\"pooh\") #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2List "pooh")))) + +(is-ok 22 "validate datatype tests for g2p_pair2List" + "[1, 2]" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2List (cons g2p_num2Int g2p_num2Int))))) + +(is-ok 23 "bad CAR datatype for g2p_pair2List" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((1 . 2))) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2List (cons g2p_bool2Bool g2p_num2Int))))) + +(is-ok 24 "bad CDR datatype for g2p_pair2List" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((1 . 2))) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 . 2)) '() + (list g2p_list2Tuple (cons g2p_pair2List (cons g2p_num2Int g2p_bool2Bool))))) + +; Exercise g2p_list2Tuple and g2p_list2List with bad arguments + +(is-ok 25 "bad argument to g2p_list2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((\"not a list\")) #f))" + (catch-test-apply '("__builtin__" "repr") '("not a list") '() + (list g2p_list2Tuple (list g2p_list2Tuple g2p_string2String)))) + +(is-ok 26 "bad argument to g2p_list2List" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((\"not a list\")) #f))" + (catch-test-apply '("__builtin__" "repr") '("not a list") '() + (list g2p_list2Tuple (list g2p_list2List g2p_string2String)))) + + +(is-ok 27 "no bad argument datatype to g2p_list2Tuple (test validation)" + "(1, 2, 3, 4, 5)" + (catch-test-apply '("__builtin__" "repr") '((1 2 3 4 5)) '() + (list g2p_list2Tuple (list g2p_list2Tuple g2p_num2Int)))) + +(is-ok 28 "bad argument datatype to g2p_list2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((1 2 3 #f 4 5))) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 2 3 #f 4 5)) '() + (list g2p_list2Tuple (list g2p_list2Tuple g2p_num2Int)))) + + +(is-ok 29 "bad argument datatype to g2p_list2List" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((6 7 #t 8 9 10))) #f))" + (catch-test-apply '("__builtin__" "repr") '((6 7 #t 8 9 10)) '() + (list g2p_list2Tuple (list g2p_list2List g2p_num2Int)))) + +(is-ok 30 "bad template (not list) to g2p_list2Tuple" + "(wrong-type-arg (\"g2p_list2Tuple\" \"Wrong type argument in position ~A: ~S\" (2 #<unspecified>) #f))" + (catch-test-apply '("__builtin__" "repr") '((1 2 3 #f 4 5)) '() + (list g2p_list2Tuple g2p_list2Tuple "fadiha"))) + + +(is-ok 31 "bad template (not list) to g2p_list2List" + "(wrong-type-arg (\"g2p_list2List\" \"Wrong type argument in position ~A: ~S\" (2 #<unspecified>) #f))" + (catch-test-apply '("__builtin__" "repr") '((6 7 #t 8 9 10)) '() + (list g2p_list2Tuple g2p_list2List "fadiha"))) + +; g2p_char2String + +(is-ok 32 "g2p_char2String" + "['a', 5, 6, 7, ' ', 'Q']" + (python-apply '("__builtin__" "repr") '((#\a 5 6 7 #\space #\Q)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_char2String g2p_num2Int g2p_bool2Bool))))) + +; g2p_symbol2String + +(is-ok 33 "g2p_symbol2String" + "['one', 'two', 'three', 'four', 'five', 'six']" + (python-apply '("__builtin__" "repr") '(("one" two #:three "four" five #:six)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_string2String g2p_symbol2String g2p_keyword2String))))) + +(python-eval "class opaq(object):\n def __init__(self,v):\n self.v=v\n def __repr__(self): return('*** opaque %s ***' % str(self.v))\n" #f) +(define opaq1 (python-eval "opaq('o p a q 1')" #t)) +(define opaq2 (python-eval "opaq(['o p a q',2])" #t)) + +(is-ok 34 "opaque data" + "[*** opaque o p a q 1 ***, 3, *** opaque ['o p a q', 2] ***]" + (python-apply '("__builtin__" "repr") (list (list opaq1 3 opaq2)) '() + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_opaque2Object g2p_num2Int))))) + +; Additional tests: g2p_list2Tuple and g2p_list2List getting data with +; item inappropriate to the single G2P_SMOB template argument. + +(is-ok 35 "list2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((4 \"Gorilla!\" 6 7 8))) #f))" + (catch-test-apply '("__builtin__" "repr") '((4 "Gorilla!" 6 7 8)) '() + (list g2p_list2Tuple (cons g2p_list2Tuple g2p_real2Float)))) + +(is-ok 36 "list2Tuple" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" (((4 \"Chimpanzee!\" 6 7 8))) #f))" + (catch-test-apply '("__builtin__" "repr") '((4 "Chimpanzee!" 6 7 8)) '() + (list g2p_list2Tuple (cons g2p_list2List g2p_real2Float)))) + + +; End of 12_g2p_templated.t diff --git a/t/13_hashes.t b/t/13_hashes.t new file mode 100644 index 0000000..881039c --- /dev/null +++ b/t/13_hashes.t @@ -0,0 +1,167 @@ +#!/usr/bin/guile -s +!# +; Pyguile hash tests - keyword arguments to functions and general Dicts. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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)) + +(python-eval "import sys;sys.path = ['']+sys.path\n") +(python-eval "from t.scripts.t4apply import return_args\n") + +(define check-kw-conversion + (lambda (keywords kwtemplate) + (python-apply '("__main__" "return_args") '() keywords + (list g2p_list2Tuple guile2python) + kwtemplate))) + +(define catch-test-kw-conversion + (lambda (keywords kwtemplate) + (catch #t + (lambda () (check-kw-conversion keywords kwtemplate)) + (lambda (key . args2) (object->string (list key args2)))))) + +(plan 20) + +(is-ok 1 "validate test" + "positional: () keywords: {'a': 'argument A'}" + (catch-test-kw-conversion '((#:a . "argument A")) + (make-hash-table 2))) + +(is-ok 2 "no kw template" + "positional: () keywords: {'bob': 'buba'}" + (python-apply '("__main__" "return_args") + '() + '((#:bob . "buba")))) + +(is-ok 3 "no kw template 2" + "positional: () keywords: {'n': None}" + (python-apply '("__main__" "return_args") + '() + '((#:n . ())) + (list g2p_list2Tuple guile2python))) + +(is-ok 4 "not a list of pairs" + "(wrong-type-arg (\"guileassoc2pythondict\" \"Wrong type argument in position ~A: ~S\" (1 not-a-list) #f))" + (catch-test-kw-conversion 'not-a-list + (make-hash-table 2))) + +(is-ok 5 "not a list of pairs 2" + "(wrong-type-arg (\"guileassoc2pythondict\" \"Wrong type argument in position ~A: ~S\" (1 not-list-either) #f))" + (catch-test-kw-conversion '(not-list-either) + (make-hash-table 2))) + +(is-ok 6 "bad key" + "(wrong-type-arg (\"guileassoc2pythondict\" \"Wrong type argument in position ~A: ~S\" (1 bad-key) #f))" + (catch-test-kw-conversion '((bad-key . 'val)) + (make-hash-table 2))) + +; Our own hash table for keywords + +(define kwhash (make-hash-table 7)) +(hashq-set! kwhash #:inpstr (list g2p_apply g2p_string2String)) +(hashq-set! kwhash #:inpkw (list g2p_apply g2p_keyword2String)) +(hashq-set! kwhash #:mynum (list g2p_apply g2p_num2Int)) + +(is-ok 7 "our own conversions" + "positional: () keywords: {'inpkw': 'must-be-kw', 'mynum': -3, 'inpstr': 'must be string', 'unverified': ['a', 'b', 'c']}" + (catch-test-kw-conversion '((#:unverified . (a b c)) (#:inpstr . "must be string") (#:inpkw . #:must-be-kw) (#:mynum . -3)) + kwhash)) + +(is-ok 8 "bad conversion" + "(misc-error (\"python-apply\" \"keyword arguments conversion failure (~S)\" (((#:unverified . -3) (#:inpstr . 7) (#:inpkw . #:must-be-kw) (#:mynum . -3))) #f))" + (catch-test-kw-conversion '((#:unverified . -3) (#:inpstr . 7) (#:inpkw . #:must-be-kw) (#:mynum . -3)) + kwhash)) + +; Passing a Dict argument to Python function + +(define catch-python-apply + (lambda (args keywords argtemplate) + (catch #t + (lambda () (python-apply '("__main__" "return_args") args keywords argtemplate)) + (lambda (key . args2) (object->string (list key args2)))))) + +(is-ok 9 "basic Dict" + "positional: ({1: 2},) keywords: {}" + (catch-python-apply '(((1 . 2))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)))))) + +(is-ok 10 "more complicated Dict" + "positional: ({1: 2, '3': 4.0},) keywords: {}" + (catch-python-apply '(((1 . 2) ("3" . 4.0))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)) (cons (list g2p_apply g2p_string2String) (list g2p_apply g2p_real2Float)))))) + +(is-ok 11 "bad conversion" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((((1 . 2) (\"3\" four-dot-zero)))) #f))" + (catch-python-apply '(((1 . 2) ("3" . (four-dot-zero)))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)) (cons (list g2p_apply g2p_string2String) (list g2p_apply g2p_real2Float)))))) + +(is-ok 12 "no alist template" + "positional: ([[1, 3, 1, 4], ['2', '6', '2', '8']],) keywords: {}" + (python-apply '("__main__" "return_args") + '(((1 . (3 1 4)) ("2" . ("6" "2" "8")))) + '())) + +(is-ok 13 "default template 2" + "positional: ({1: [3, 1, 4], '2': ['6', '2', '8']},) keywords: {}" + (python-apply '("__main__" "return_args") + '(((1 . (3 1 4)) ("2" . ("6" "2" "8")))) + '() + (list g2p_list2Tuple (list g2p_apply g2p_alist2Dict)))) + +(is-ok 14 "Dict template with non-list argument" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((\"not-a-list\")) #f))" + (catch-python-apply '("not-a-list") '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)))))) + +(is-ok 15 "basic Dict with non-list template" + "(wrong-type-arg (\"g2p_alist2Dict\" \"Wrong type argument in position ~A: ~S\" (2 'guile2python) #f))" + (catch-python-apply '(((1 . 2))) '() + (list g2p_list2Tuple (list g2p_apply g2p_alist2Dict guile2python)))) + +(is-ok 16 "Dict with malformed template" + "(wrong-type-arg (\"g2p_alist2Dict\" \"Wrong type argument in position ~A: ~S\" (2 \"notapair\") #f))" + (catch-python-apply '(((1 . 2) ("3" . 4.0))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)) "notapair")))) + +(is-ok 17 "malformed alist" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((((1 . 2) conjugate (\"3\" . 4.0)))) #f))" + (catch-python-apply '(((1 . 2) conjugate ("3" . 4.0))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)) (cons (list g2p_apply g2p_string2String) (list g2p_apply g2p_real2Float)))))) + +(is-ok 18 "Dict with keys matching template" + "positional: ({1: '2', '3': 4.0},) keywords: {}" + (catch-python-apply '(((1 . "2") ("3" . 4.0))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply g2p_num2Int) (list g2p_apply g2p_string2String)) (cons (list g2p_apply g2p_string2String) (list g2p_apply g2p_real2Float)))))) + +(is-ok 19 "Dict with keys not matching template" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((((1.5 . 2) (\"3\" . 4.0)))) #f))" + (catch-python-apply '(((1.5 . 2) ("3" . 4.0))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply g2p_num2Int) (list g2p_apply g2p_string2String)) (cons (list g2p_apply g2p_string2String) (list g2p_apply g2p_real2Float)))))) + +(is-ok 20 "alist with duplicate key" + "(misc-error (\"g2p_alist2Dict\" \"duplicate key (~S)\" (1) #f))" + (catch-python-apply '(((1 . 2) ("3" . 4.0) (1 . a55))) '() + (list g2p_list2Tuple (list g2p_alist2Dict (cons (list g2p_apply guile2python) (list g2p_apply guile2python)) (cons (list g2p_apply guile2python) (list g2p_apply guile2python)))))) + +; End of 13_hashes.t diff --git a/t/14_p2g_templated.t b/t/14_p2g_templated.t new file mode 100644 index 0000000..88611ae --- /dev/null +++ b/t/14_p2g_templated.t @@ -0,0 +1,293 @@ +#!/usr/bin/guile -s +!# +; Basic p2g template tests +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 57) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; p2g_None2SCM_EOL + +(is-ok 1 "default None" '() + (python-eval "None" #t)) + +(is-ok 2 "default None 2" '() + (python-eval "None" python2guile)) + +(is-ok 3 "default None 3" '() + (python-eval "None" p2g_None2SCM_EOL)) + +(is-ok 4 "default None 4" '() + (python-eval "None" (cons p2g_None2SCM_EOL '()))) + +(is-ok 5 "None becomes 'None'" "None" + (python-eval "None" (cons p2g_None2SCM_EOL "None"))) + +(is-ok 6 "non-None" "#<undefined>" + (object->string (python-eval "True" p2g_None2SCM_EOL))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; p2g_Bool2SCM_BOOL + +(is-ok 7 "p2g_Bool2SCM_BOOL True" #t + (python-eval "True" p2g_Bool2SCM_BOOL)) + +(is-ok 8 "p2g_Bool2SCM_BOOL False" #f + (python-eval "False" p2g_Bool2SCM_BOOL)) + +(is-ok 9 "p2g_Bool2SCM_BOOL Other" "#<undefined>" + (object->string (python-eval "2239" p2g_Bool2SCM_BOOL))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; p2g_Int2num, p2g_Long2bignum + +(is-ok 10 "p2g_Int2num ok" 12 + (python-eval "12" p2g_Int2num)) + +(is-ok 11 "p2g_Int2num bad" "#<undefined>" + (object->string (python-eval "None" p2g_Int2num))) + +(is-ok 12 "p2g_Int2num long" "#<undefined>" + (object->string (python-eval "1000200030004" p2g_Int2num))) + +(is-ok 13 "p2g_Long2bignum ok" 12 + (python-eval "12L" p2g_Long2bignum)) + +(is-ok 14 "p2g_Long2bignum bad" "#<undefined>" + (object->string (python-eval "'q'" p2g_Long2bignum))) + +(is-ok 15 "p2g_Long2bignum long" "1000200030004" + (object->string (python-eval "1000200030004" p2g_Long2bignum))) + +; p2g_leaf + +(is-ok 16 "p2g_Int2num+p2g_Long2bignum" "5000600070008" + (object->string (python-eval "5000600070008" (list p2g_leaf p2g_Int2num p2g_Long2bignum)))) + +(is-ok 17 "p2g_Int2num+p2g_Long2bignum/cons" "5100600070008" + (object->string (python-eval "5100600070008" (cons p2g_leaf p2g_Long2bignum)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; float and complex + +(is-ok 18 "p2g_Float2real" 2.718 + (python-eval "2.7+0.018" p2g_Float2real)) + +(is-ok 19 "p2g_Complex2complex" 1.5+3.6i + (python-eval "1.5+3.6j" p2g_Complex2complex)) + +; Tuple2list of numbers + +(is-ok 20 "Numbers in tuple" '(1023 -445 4.75 -8.1e5 2e7+3.125i) + (python-eval "(1023,-445,4.75,-8.1e5,(2e7+3.125j))" + (list p2g_apply p2g_Tuple2list (list p2g_leaf p2g_Int2num p2g_Long2bignum p2g_Float2real p2g_Complex2complex)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Strings + +(is-ok 21 "String" "a message" + (python-eval "'''a message'''" p2g_String2string)) + +(is-ok 22 "Sumbol" 'a-message + (python-eval "'''a-message'''" p2g_String2symbol)) + +(is-ok 23 "Keyword" #:another-message + (python-eval "'''another-message'''" p2g_String2keyword)) + +; string to char + +(is-ok 24 "single char" #\space + (python-eval "' '" p2g_1String2char)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; 2-tuple/2-list to pairs + +(is-ok 25 "2-tuple to pair" '(12.0 . 34) + (python-eval "(12.0,34)" (cons p2g_2Tuple2pair (cons p2g_Float2real p2g_Int2num)))) + +(is-ok 26 "2-tuple to pair, wrong template" "#<undefined>" + (object->string (python-eval "(12.0,34)" (cons p2g_2Tuple2pair (cons p2g_Int2num p2g_Float2real))))) + +(is-ok 27 "2-tuple to pair, wrong template due another reason" "#<undefined>" + (object->string (python-eval "[12.0,34]" (cons p2g_2Tuple2pair (cons p2g_Int2num p2g_Float2real))))) + +(is-ok 28 "2-list to pair" '("ab" . "cd") + (python-eval "['ab','cd']" (cons p2g_2List2pair (cons p2g_String2string p2g_String2string)))) + +(is-ok 29 "2-tuple (or 2-list) to pair" '("ef" . 3) + (python-eval "('ef',3)" + (cons p2g_leaf + (list + (cons p2g_2Tuple2pair (cons p2g_String2string p2g_Int2num)) + (cons p2g_2List2pair (cons p2g_String2string p2g_Int2num)))))) + + +(is-ok 30 "(2-tuple or) 2-list to pair" '("ef" . 3) + (python-eval "['ef',3]" + (cons p2g_leaf + (list + (cons p2g_2Tuple2pair (cons p2g_String2string p2g_Int2num)) + (cons p2g_2List2pair (cons p2g_String2string p2g_Int2num)))))) + +(is-ok 31 "2-list to pair, wrong template" "#<undefined>" + (object->string (python-eval "[12.0,34]" (cons p2g_2List2pair (cons p2g_Int2num p2g_Float2real))))) + +(is-ok 32 "2-list to pair, wrong template due another reason" "#<undefined>" + (object->string (python-eval "(12.0,34)" (cons p2g_2List2pair (cons p2g_Int2num p2g_Float2real))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Aggregates - N-Tuples/N-Lists to lists + +; from Tuples +(is-ok 33 "tuple to list, mixed datatypes" "(11 12.0 13 34.5 38 780.25)" + (object->string (python-eval "(11,12.0,13,34.5,38,780.25)" (cons p2g_Tuple2list (list p2g_Int2num p2g_Float2real))))) + +(is-ok 34 "tuple to list, wrong data type" "#<undefined>" + (object->string (python-eval "[11,12.0,13,34.5,38,780.25]" (cons p2g_Tuple2list (list p2g_Int2num p2g_Float2real))))) + +(is-ok 35 "tuple to list, P2G_SMOB" "(11 12 13 34 38 780)" + (object->string (python-eval "(11,12,13,34,38,780)" (cons p2g_Tuple2list p2g_Int2num)))) + +(is-ok 36 "tuple to list, P2G_SMOB, one bad value" "#<undefined>" + (object->string (python-eval "(11,12,'a13',34,38,780)" (cons p2g_Tuple2list p2g_Int2num)))) + +; from Lists +(is-ok 37 "List to list, mixed datatypes" "(11 12.0 13 34.5 38 780.25)" + (object->string (python-eval "[11,12.0,13,34.5,38,780.25]" (cons p2g_List2list (list p2g_Int2num p2g_Float2real))))) + +(is-ok 38 "List to list, wrong data type" "#<undefined>" + (object->string (python-eval "(11,12.0,13,34.5,38,780.25)" (cons p2g_List2list (list p2g_Int2num p2g_Float2real))))) + +(is-ok 39 "List to list, P2G_SMOB" "(11 12 13 34 38 780)" + (object->string (python-eval "[11,12,13,34,38,780]" (cons p2g_List2list p2g_Int2num)))) + +(is-ok 40 "List to list, P2G_SMOB, one bad value" "#<undefined>" + (object->string (python-eval "[11,12,'a13',34,38,780]" (cons p2g_List2list p2g_Int2num)))) + +; p2g_Dict2alist + +(define alist-properly-included? + (lambda (included includor) + (if (null? included) #t + (let ((key (caar included)) + (value (cdar included)) + (rest (cdr included))) + (let ((includor-ref (assoc key includor))) + (cond ((not includor-ref) #f) + ((not (equal? (cdr includor-ref) value)) #f) + (else (alist-properly-included? rest includor)))))))) + +(define alist-equal? + (lambda (alista alistb) + (and (alist-properly-included? alista alistb) + (alist-properly-included? alistb alista)))) + +; Quick tests of alist-properly-included? +(ok 41 "should pass 1" + (alist-equal? '((1 . 2)("3" . "4")) + '(("3" . "4")(1 . 2)))) + +(ok 42 "should pass 2" + (alist-equal? '((1 . 2)("3" . "4")) + '((1 . 2)("3" . "4")))) + +(ok 43 "should fail 1" + (not (alist-equal? '((1 . 2)("3" . "4")) + '((11 . 2)("3" . "4"))))) + +(ok 44 "should fail 2" + (not (alist-equal? '((1 . 2)("3" . "4")) + '((1 . 21)("3" . "4"))))) + +(ok 45 "should fail 3" + (not (alist-equal? '((1 . 2)("3" . "4")) + '((1 . 2)("3a" . "4"))))) + +(ok 46 "should fail 4" + (not (alist-equal? '((1 . 2)("3" . "4")) + '((1 . 2)("3" . "4b"))))) + +(ok 47 "should fail 1a" + (not (alist-equal? '(("3" . "4")(1 . 2)) + '((11 . 2)("3" . "4"))))) + +(ok 48 "should fail 2a" + (not (alist-equal? '(("3" . "4")(1 . 2)) + '((1 . 21)("3" . "4"))))) + +(ok 49 "should fail 3a" + (not (alist-equal? '(("3" . "4")(1 . 2)) + '((1 . 2)("3a" . "4"))))) + +(ok 50 "should fail 4a" + (not (alist-equal? '(("3" . "4")(1 . 2)) + '((1 . 2)("3" . "4b"))))) + +(ok 51 "should fail 5" + (not (alist-equal? '(("3" . "4")(1 . 2)(5 . 6)) + '((1 . 2)("3" . "4"))))) + +(ok 52 "should fail 5a" + (not (alist-equal? '(("3" . "4")(1 . 2)(5 . 6)) + '((1 . 2)("3" . "4")(7 . 8)(5 . 6))))) + + +; Proper p2g_Dict2alist tests + + +(ok 53 "Default p2g_Dict2alist" + (alist-equal? '((1 . 2) ("3" . "4")) + (python-eval "{1 : 2, '3' : '4'}" #t))) + +(ok 54 "Explicit p2g_Dict2alist template" + (alist-equal? '((#\b . 42) (gg . 3)) + (python-eval "{'b' : None, 'gg' : 3}" + (cons p2g_Dict2alist + (cons + (cons p2g_leaf (list p2g_1String2char p2g_String2symbol)) + (cons p2g_leaf (list (cons p2g_None2SCM_EOL 42) p2g_Int2num))))))) + +(ok 55 "P2G_SMOBP based p2g_Dict2alist template" + (alist-equal? '(("key1" . val1) ("key2" . myval2) ("k3" . yourval3)) + (python-eval "{'key1' : 'val1', 'key2' : 'myval2', 'k3' : 'yourval3'}" + (cons p2g_Dict2alist + (cons p2g_String2string p2g_String2symbol))))) + +(is-ok 56 "p2g_Dict2alist key conversion failure" "#<undefined>" + (object->string (python-eval "{'b' : None, 1.2 : 3}" + (cons p2g_Dict2alist + (cons + (cons p2g_leaf (list p2g_1String2char p2g_String2symbol)) + (cons p2g_leaf (list (cons p2g_None2SCM_EOL 42) p2g_Int2num))))))) + +(is-ok 57 "p2g_Dict2alist value conversion failure" "#<undefined>" + (object->string (python-eval "{'b' : 'None', 'gg' : 3}" + (cons p2g_Dict2alist + (cons + (cons p2g_leaf (list p2g_1String2char p2g_String2symbol)) + (cons p2g_leaf (list (cons p2g_None2SCM_EOL 42) p2g_Int2num))))))) + +; End of 14_p2g_templated.t diff --git a/t/15_p2g_errors.t b/t/15_p2g_errors.t new file mode 100644 index 0000000..13398bd --- /dev/null +++ b/t/15_p2g_errors.t @@ -0,0 +1,126 @@ +#!/usr/bin/guile -s +!# +; p2g conversion error handling tests. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 20) + +; Run python-eval under catch harness. +(define catch-test-eval + (lambda (txt template) + (catch #t + (lambda () (python-eval txt template)) + (lambda (key . args) (object->string (list key args)))))) + +(is-ok 1 "template with bad CAR" + "(misc-error (\"p2g_apply\" \"bad template CAR item ~S\" (42) #f))" + (catch-test-eval "-42" (cons 42 "None"))) + +(is-ok 2 "p2g_leaf template with bad CDR" + "(wrong-type-arg (\"p2g_leaf\" \"Wrong type argument in position ~A: ~S\" (2 \"foofoo\") #f))" + (catch-test-eval "-42" (cons p2g_leaf "foofoo"))) + +(is-ok 3 "no p2g_leaf template matches the data" + "#<undefined>" + (object->string (catch-test-eval "'a-42'" (list p2g_leaf p2g_Int2num p2g_Long2bignum)))) + +(is-ok 4 "too short string for keyword" + "#<undefined>" + (object->string (catch-test-eval "''" p2g_String2keyword))) + +(is-ok 5 "too long string for char" + "#<undefined>" + (object->string (catch-test-eval "'lg'" p2g_1String2char))) + +(is-ok 6 "too short string for char" + "#<undefined>" + (object->string (catch-test-eval "''''''" p2g_1String2char))) + +(is-ok 7 "2-tuple to pair, bad template" + "(misc-error (\"p2g_2Tuple2pair\" \"bad template item ~S\" (12.3) #f))" + (catch-test-eval "(12.0,34)" (cons p2g_2Tuple2pair 12.3))) + +(is-ok 8 "2-tuple to pair, wrong tuple length - too long" "#<undefined>" + (object->string (python-eval "(1,2,3)" (cons p2g_2Tuple2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 9 "2-tuple to pair, wrong tuple length - too short" "#<undefined>" + (object->string (python-eval "(1,)" (cons p2g_2Tuple2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 10 "2-tuple to pair, wrong 2nd item datatype" "#<undefined>" + (object->string (python-eval "(1,'zuzu')" (cons p2g_2Tuple2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 11 "2-list to pair, bad template" + "(misc-error (\"p2g_2List2pair\" \"bad template item ~S\" (12.3) #f))" + (catch-test-eval "[12.0,34]" (cons p2g_2List2pair 12.3))) + +(is-ok 12 "2-list to pair, wrong tuple length - too long" "#<undefined>" + (object->string (python-eval "[1,2,3]" (cons p2g_2List2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 13 "2-list to pair, wrong tuple length - too short" "#<undefined>" + (object->string (python-eval "[1]" (cons p2g_2List2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 14 "2-list to pair, wrong 1st item datatype" "#<undefined>" + (object->string (python-eval "['xyxy',11]" (cons p2g_2List2pair (cons p2g_Int2num p2g_Int2num))))) + +(is-ok 15 "2-list to pair, wrong 2nd item datatype" "#<undefined>" + (object->string (python-eval "[1,'zuzu']" (cons p2g_2List2pair (cons p2g_Int2num p2g_Int2num))))) + + +; template not a proper list + +(is-ok 16 "Tuple to list, template improper list" + "(wrong-type-arg (\"p2g_Tuple2list\" \"Wrong type argument in position ~A: ~S\" (2 ('p2g_Int2num 'p2g_Float2real . 'p2g_Float2real)) #f))" + (catch-test-eval + "(11,12.0,13,34.5,38,780.25)" + (cons p2g_Tuple2list (cons p2g_Int2num (cons p2g_Float2real p2g_Float2real))))) + +(is-ok 17 "List to list, template improper list" + "(wrong-type-arg (\"p2g_List2list\" \"Wrong type argument in position ~A: ~S\" (2 ('p2g_Int2num 'p2g_Float2real . 'p2g_Float2real)) #f))" + (catch-test-eval + "[11,12.0,13,34.5,38,780.25]" + (cons p2g_List2list (cons p2g_Int2num (cons p2g_Float2real p2g_Float2real))))) + +; p2g_Dict2alist - bad templates + +(is-ok 18 "Dict to alist, template is not pair" + "(misc-error (\"p2g_Dict2alist\" \"bad template ~S\" ('p2g_Int2num) #f))" + (catch-test-eval + "{1 : 2, 3 : 4}" + (cons p2g_Dict2alist p2g_Int2num))) + +(is-ok 19 "Dict to alist, bad template CAR" + "(misc-error (\"p2g_apply\" \"bad template item ~S\" (12) #f))" + (catch-test-eval + "{1 : 2, 3 : 4}" + (cons p2g_Dict2alist (cons 12 p2g_Int2num)))) + +(is-ok 20 "Dict to alist, bad template CDR" + "(misc-error (\"p2g_apply\" \"bad template item ~S\" (\"cde\") #f))" + (catch-test-eval + "{1 : 2, 3 : 4}" + (cons p2g_Dict2alist (cons p2g_Int2num "cde")))) + +; End of 15_p2g_errors.t diff --git a/t/16_verbose.t b/t/16_verbose.t new file mode 100755 index 0000000..58adb75 --- /dev/null +++ b/t/16_verbose.t @@ -0,0 +1,50 @@ +#!/usr/bin/guile -s +!# +; Basic tests of the PyGuile verbosity control +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 4) + +(pyguile-verbosity-set! 43) +(is-ok 1 "Verbosity value should be 43" + 43 + (pyguile-verbosity-set! 10)) + +(is-ok 2 "Verbosity value should be 10" + 10 + (pyguile-verbosity-set! 0)) + +(is-ok 3 "Verbosity value should be 0" + 0 + (pyguile-verbosity-set! 0)) + +(is-ok 4 "Trying to set verbosity value to a non-number" + "(wrong-type-arg (\"pyguile-verbosity-set!\" \"Wrong type argument in position ~A: ~S\" (1 \"NAN\") #f))" + (catch #t + (lambda () (pyguile-verbosity-set! "NAN")) + (lambda (key . args) (object->string (list key args))))) + +; End of 16_verbose.t diff --git a/t/17_verbose.t b/t/17_verbose.t new file mode 100644 index 0000000..c807ed8 --- /dev/null +++ b/t/17_verbose.t @@ -0,0 +1,161 @@ +#!/usr/bin/guile -s +!# +; Tests of PyGuile verbosity messages - for full source 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)) +;(use-modules (srfi srfi-6)) ; string ports +(use-modules (srfi srfi-13)) ; string-concatenate +(use-modules (ice-9 regex)) ; regexp-substitute + +;(define get-output +; (lambda (thunk) +; (let ((my-output-port open-output-string)) +; (call-with-output-string (thunk)) +; (get-output-string my-output-port)))) + +(define thunk-invoke-python-repr + (lambda (arg . template) + (lambda () + (if (null? template) + (python-apply '("__builtin__" "repr") arg '()) + (python-apply '("__builtin__" "repr") arg '() (car template)))))) + +(plan 6) + +(pyguile-verbosity-set! 1) + +(define successful-verbose-builtin-repr-conversion-report + (string-concatenate + '("# g2p_string2String: successful conversion of \"__builtin__\" into a Python String value\n" + "# g2p_string2String: successful conversion of \"repr\" into a Python String value\n"))) + +(define expres1 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# p2g_String2string: successful conversion of \"'True'\" into SCM\n"))) +(is-ok 1 "Verbosity with a single value" + expres1 + (with-output-to-string + (thunk-invoke-python-repr '(#t)))) + +(define expres2 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_null2PyNone: successful conversion of () into Python None\n" + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# g2p_bool2Bool: successful conversion of #f into a Python Bool value\n" + "# g2p_num2Int: successful conversion of 1 into a Python Int value\n" + "# g2p_num2Int: successful conversion of -5 into a Python Int value\n" + "# g2p_symbol2String: successful conversion of quote into a Python String value\n" + "# g2p_symbol2String: successful conversion of symba into a Python String value\n" + "# g2p_complex2Complex: successful conversion of 1.0-1.0i into a Python Complex value\n" + "# g2p_real2Float: successful conversion of 3.125 into a Python Float value\n" + "# p2g_String2string: successful conversion of \"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" into SCM\n"))) +(is-ok 2 "Verbosity when successful" + expres2 + (with-output-to-string + (thunk-invoke-python-repr '((() #t #f 1 -5 #\P 'symba 1-1i 3.125))))) + +(define expres3 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_null2Tuple0: successful conversion of () into Python ()\n" + "# g2p_null2List0: successful conversion of () into Python []\n" + "# g2p_null2DictEmpty: successful conversion of () into Python {}\n" + "# p2g_String2string: successful conversion of \"'((), [], {})'\" into SCM\n"))) +(is-ok 3 "g2p* verbosity coverage" + expres3 + (with-output-to-string + (thunk-invoke-python-repr + '((() () ())) + (list g2p_list2Tuple (list g2p_list2Tuple g2p_null2Tuple0 g2p_null2List0 g2p_null2DictEmpty))))) + +(define expres4 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_num2Int: successful conversion of 1000000 into a Python Int value\n" + "# g2p_bignum2Long: successful conversion of 1000000000000 into a Python Long value\n" + "# p2g_String2string: successful conversion of \"'[1000000, 1000000000000L]'\" into SCM\n"))) +(is-ok 4 "g2p* verbosity coverage - bignums,list2Tuple,list2List" + expres4 + (with-output-to-string + (thunk-invoke-python-repr + '((1000000 1000000000000)) + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_bignum2Long g2p_num2Int)))))) + +(define expres5 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_symbol2String: successful conversion of p1at into a Python String value\n" + "# g2p_string2String: successful conversion of \"p1bt\" into a Python String value\n" + "# g2p_keyword2String: successful conversion of #:p2al into a Python String value\n" + "# g2p_symbol2String: successful conversion of p2bl into a Python String value\n" + "# p2g_String2string: successful conversion of \"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" into SCM\n"))) +(is-ok 5 "g2p* verbosity coverage - pair2Tuple,pair2List" + expres5 + (with-output-to-string + (thunk-invoke-python-repr + '(((p1at . "p1bt") (#:p2al . p2bl))) + (list g2p_list2Tuple (list g2p_list2Tuple (cons g2p_pair2Tuple (cons guile2python guile2python)) (cons g2p_pair2List (cons guile2python guile2python))))))) + +(define substitute-hex-addresses-for-gggggggg + (lambda (strarg) + (regexp-substitute/global #f + "0x[0-9a-f]{8}" + strarg + 'pre "0xgggggggg" 'post))) + +(define expres6 + (string-concatenate + (list + successful-verbose-builtin-repr-conversion-report + "# g2p_opaque2Object: the Python object inside opaque pysmob (python-eval <function func at 0xgggggggg> #t) is unwrapped\n" + "# g2p_num2Int: successful conversion of 1 into a Python Int value\n" + "# g2p_string2String: successful conversion of \"one\" into a Python String value\n" + "# g2p_num2Int: successful conversion of 2 into a Python Int value\n" + "# g2p_string2String: successful conversion of \"two\" into a Python String value\n" + "# g2p_num2Int: successful conversion of 3 into a Python Int value\n" + "# g2p_string2String: successful conversion of \"three\" into a Python String value\n" + "# p2g_String2string: successful conversion of \"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" into SCM\n"))) +(python-eval "def func(a):\n print a\n" #f) +(define opaqueobj (python-eval "func" #t)) +(define run-test-opaque + (lambda () + (with-output-to-string + (thunk-invoke-python-repr + (list (list opaqueobj '((1 . "one")(2 . "two")(3 . "three")))) + (list g2p_list2Tuple (list g2p_list2List g2p_opaque2Object (cons g2p_alist2Dict (list (cons g2p_num2Int g2p_string2String))))))))) +(is-ok 6 "g2p* verbosity coverage - opaque2Object,g2p_alist2Dict" + expres6 + (substitute-hex-addresses-for-gggggggg + (run-test-opaque))) + +; End of 17_verbose.t diff --git a/t/18_bignum.t b/t/18_bignum.t new file mode 100644 index 0000000..d30adb6 --- /dev/null +++ b/t/18_bignum.t @@ -0,0 +1,55 @@ +#!/usr/bin/guile -s +!# +; Miscellaneous tests of PyGuile data 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)) + +(python-eval "def func(val):\n global longint\n longint=val\n" #f) + +(plan 3) + +(python-apply "func" '("abc") '()) +; The following won't work because Guile's and Python's stdout are +; separately controlled. +;;(is-ok 1 "should yield 'abc'" +;; "abc\n" +;; (with-output-to-string +;; (lambda () +;; (python-eval "print longint\n" #f)))) +(is-ok 1 "should yield 'abc'" + "abc" + (python-eval "longint" #t)) + +(python-apply "func" '(3773) '()) +(is-ok 2 "should yield 3773" + 3773 + (python-eval "longint" #t)) + +(python-apply "func" '(36893488147419103232) '()) +(is-ok 3 "should yield the bignum" + 36893488147419103232 + (python-eval "longint" #t)) + +; End of 18_bignum.t diff --git a/t/19_verbose_always.t b/t/19_verbose_always.t new file mode 100644 index 0000000..f65f3df --- /dev/null +++ b/t/19_verbose_always.t @@ -0,0 +1,733 @@ +#!/usr/bin/guile -s +!# +; Tests of PyGuile verbosity messages - for full source code coverage +; +; Same tests as 17_verbose.t, except that the verbosity level was set +; to 3 (PYGUILE_VERBOSE_G2P2G_SUCCESSFUL+PYGUILE_VERBOSE_G2P2G_ALWAYS). +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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)) +(use-modules (srfi srfi-13)) ; string-concatenate +(use-modules (ice-9 regex)) ; regexp-substitute + +(define thunk-invoke-python-repr + (lambda (arg . template) + (lambda () + (if (null? template) + (python-apply '("__builtin__" "repr") arg '()) + (python-apply '("__builtin__" "repr") arg '() (car template)))))) + +(plan 13) + +(pyguile-verbosity-set! 3) + +(define successful-verbose-3-report + (string-concatenate + '("# guile2python: entry: seeking to convert sobj=(\"__builtin__\" \"repr\"); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: (\"__builtin__\" \"repr\") is not null\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=\"__builtin__\" CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=\"__builtin__\" stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=\"__builtin__\"; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: \"__builtin__\" is not null\n" + "# g2p_list2List: unsuccessful conversion: \"__builtin__\" is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: \"__builtin__\" is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: \"__builtin__\" is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: \"__builtin__\" is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: \"__builtin__\" is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: \"__builtin__\" is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: \"__builtin__\" is not a complex value\n" + "# g2p_string2String: successful conversion of \"__builtin__\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=\"repr\" CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=\"repr\" stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=\"repr\"; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: \"repr\" is not null\n" + "# g2p_list2List: unsuccessful conversion: \"repr\" is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: \"repr\" is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: \"repr\" is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: \"repr\" is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: \"repr\" is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: \"repr\" is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: \"repr\" is not a complex value\n" + "# g2p_string2String: successful conversion of \"repr\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n"))) + +(define expres1 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(#t) stemplate=('g2p_list2Tuple 'guile2python)\n" + "# g2p_list2Tuple - processing item CAR(sobj)=#t CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=#t stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=#t; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: #t is not null\n" + "# g2p_list2List: unsuccessful conversion: #t is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: #t is not a pair\n" + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"'True'\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"'True'\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"'True'\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"'True'\" into SCM\n"))) +(is-ok 1 "Verbosity/3 with a single value" + expres1 + (with-output-to-string + (thunk-invoke-python-repr '(#t)))) + +(define expres2 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((() #t #f 1 -5 #\\P (quote symba) 1.0-1.0i 3.125)) stemplate=('g2p_list2Tuple 'guile2python)\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(() #t #f 1 -5 #\\P (quote symba) 1.0-1.0i 3.125) CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=(() #t #f 1 -5 #\\P (quote symba) 1.0-1.0i 3.125) stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=(() #t #f 1 -5 #\\P (quote symba) 1.0-1.0i 3.125); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: (() #t #f 1 -5 #\\P (quote symba) 1.0-1.0i 3.125) is not null\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=() CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=() stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=(); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: successful conversion of () into Python None\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=#t CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=#t stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=#t; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: #t is not null\n" + "# g2p_list2List: unsuccessful conversion: #t is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: #t is not a pair\n" + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=#f CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=#f stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=#f; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: #f is not null\n" + "# g2p_list2List: unsuccessful conversion: #f is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: #f is not a pair\n" + "# g2p_bool2Bool: successful conversion of #f into a Python Bool value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=1 CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=1 stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=1; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: 1 is not null\n" + "# g2p_list2List: unsuccessful conversion: 1 is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: 1 is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: 1 is not a bool value\n" + "# g2p_num2Int: successful conversion of 1 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=-5 CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=-5 stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=-5; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: -5 is not null\n" + "# g2p_list2List: unsuccessful conversion: -5 is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: -5 is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: -5 is not a bool value\n" + "# g2p_num2Int: successful conversion of -5 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=#\\P CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=#\\P stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=#\\P; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: #\\P is not null\n" + "# g2p_list2List: unsuccessful conversion: #\\P is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: #\\P is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: #\\P is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: #\\P is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: #\\P is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: #\\P is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: #\\P is not a complex value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=(quote symba) CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=(quote symba) stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=(quote symba); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: (quote symba) is not null\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=quote CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=quote stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=quote; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: quote is not null\n" + "# g2p_list2List: unsuccessful conversion: quote is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: quote is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: quote is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: quote is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: quote is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: quote is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: quote is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: quote is not a string value\n" + "# g2p_symbol2String: successful conversion of quote into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=symba CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=symba stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=symba; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: symba is not null\n" + "# g2p_list2List: unsuccessful conversion: symba is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: symba is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: symba is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: symba is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: symba is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: symba is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: symba is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: symba is not a string value\n" + "# g2p_symbol2String: successful conversion of symba into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=1.0-1.0i CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=1.0-1.0i stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=1.0-1.0i; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: 1.0-1.0i is not null\n" + "# g2p_list2List: unsuccessful conversion: 1.0-1.0i is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: 1.0-1.0i is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: 1.0-1.0i is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: 1.0-1.0i is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: 1.0-1.0i is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: 1.0-1.0i is not a real value\n" + "# g2p_complex2Complex: successful conversion of 1.0-1.0i into a Python Complex value\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=3.125 CAR(stemp)='guile2python\n" + "# Entered g2p_apply: sobj=3.125 stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=3.125; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: 3.125 is not null\n" + "# g2p_list2List: unsuccessful conversion: 3.125 is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: 3.125 is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: 3.125 is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: 3.125 is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: 3.125 is not a bignum value\n" + "# g2p_real2Float: successful conversion of 3.125 into a Python Float value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"\\\"[None, True, False, 1, -5, 'P', ['quote', 'symba'], (1-1j), 3.125]\\\"\" into SCM\n"))) +(is-ok 2 "Verbosity/3 when successful" + expres2 + (with-output-to-string + (thunk-invoke-python-repr '((() #t #f 1 -5 #\P 'symba 1-1i 3.125))))) + +(define expres3 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((() () ())) stemplate=('g2p_list2Tuple ('g2p_list2Tuple 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(() () ()) CAR(stemp)=('g2p_list2Tuple 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty)\n" + "# Entered g2p_apply: sobj=(() () ()) stemplate=('g2p_list2Tuple 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty)\n" + "# g2p_list2Tuple - processing item CAR(sobj)=() CAR(stemp)='g2p_null2Tuple0\n" + "# Entered g2p_apply: sobj=() stemplate='g2p_null2Tuple0\n" + "# g2p_null2Tuple0: successful conversion of () into Python ()\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple - processing item CAR(sobj)=() CAR(stemp)='g2p_null2List0\n" + "# Entered g2p_apply: sobj=() stemplate='g2p_null2List0\n" + "# g2p_null2List0: successful conversion of () into Python []\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple - processing item CAR(sobj)=() CAR(stemp)='g2p_null2DictEmpty\n" + "# Entered g2p_apply: sobj=() stemplate='g2p_null2DictEmpty\n" + "# g2p_null2DictEmpty: successful conversion of () into Python {}\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"'((), [], {})'\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"'((), [], {})'\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"'((), [], {})'\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"'((), [], {})'\" into SCM\n"))) +(is-ok 3 "g2p* verbosity/3 coverage" + expres3 + (with-output-to-string + (thunk-invoke-python-repr + '((() () ())) + (list g2p_list2Tuple (list g2p_list2Tuple g2p_null2Tuple0 g2p_null2List0 g2p_null2DictEmpty))))) + +(define expres4 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((1000000 1000000000000)) stemplate=('g2p_list2Tuple ('g2p_list2List ('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(1000000 1000000000000) CAR(stemp)=('g2p_list2List ('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int))\n" + "# Entered g2p_apply: sobj=(1000000 1000000000000) stemplate=('g2p_list2List ('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int))\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=1000000 CAR(stemp)=('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int)\n" + "# Entered g2p_apply: sobj=1000000 stemplate=('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int)\n" + "# Entered g2p_leaf: sobj=1000000 stemplate=('g2p_bignum2Long 'g2p_num2Int)\n" + "# g2p_leaf: trying another stemplate 'g2p_bignum2Long on sobj\n" + "# Entered g2p_apply: sobj=1000000 stemplate='g2p_bignum2Long\n" + "# g2p_bignum2Long: unsuccessful conversion: 1000000 is not a bignum value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=1000000 stemplate='g2p_num2Int\n" + "# g2p_num2Int: successful conversion of 1000000 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_leaf: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=1000000000000 CAR(stemp)=('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int)\n" + "# Entered g2p_apply: sobj=1000000000000 stemplate=('g2p_leaf 'g2p_bignum2Long 'g2p_num2Int)\n" + "# Entered g2p_leaf: sobj=1000000000000 stemplate=('g2p_bignum2Long 'g2p_num2Int)\n" + "# g2p_leaf: trying another stemplate 'g2p_bignum2Long on sobj\n" + "# Entered g2p_apply: sobj=1000000000000 stemplate='g2p_bignum2Long\n" + "# g2p_bignum2Long: successful conversion of 1000000000000 into a Python Long value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_leaf: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"'[1000000, 1000000000000L]'\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"'[1000000, 1000000000000L]'\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"'[1000000, 1000000000000L]'\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"'[1000000, 1000000000000L]'\" into SCM\n"))) +(is-ok 4 "g2p* verbosity/3 coverage - bignums,list2Tuple,list2List" + expres4 + (with-output-to-string + (thunk-invoke-python-repr + '((1000000 1000000000000)) + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_bignum2Long g2p_num2Int)))))) + +(define expres5 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(((p1at . \"p1bt\") (#:p2al . p2bl))) stemplate=('g2p_list2Tuple ('g2p_list2Tuple ('g2p_pair2Tuple 'guile2python . 'guile2python) ('g2p_pair2List 'guile2python . 'guile2python)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=((p1at . \"p1bt\") (#:p2al . p2bl)) CAR(stemp)=('g2p_list2Tuple ('g2p_pair2Tuple 'guile2python . 'guile2python) ('g2p_pair2List 'guile2python . 'guile2python))\n" + "# Entered g2p_apply: sobj=((p1at . \"p1bt\") (#:p2al . p2bl)) stemplate=('g2p_list2Tuple ('g2p_pair2Tuple 'guile2python . 'guile2python) ('g2p_pair2List 'guile2python . 'guile2python))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(p1at . \"p1bt\") CAR(stemp)=('g2p_pair2Tuple 'guile2python . 'guile2python)\n" + "# Entered g2p_apply: sobj=(p1at . \"p1bt\") stemplate=('g2p_pair2Tuple 'guile2python . 'guile2python)\n" + "# Entered g2p_apply: sobj=p1at stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=p1at; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: p1at is not null\n" + "# g2p_list2List: unsuccessful conversion: p1at is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: p1at is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: p1at is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: p1at is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: p1at is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: p1at is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: p1at is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: p1at is not a string value\n" + "# g2p_symbol2String: successful conversion of p1at into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=\"p1bt\" stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=\"p1bt\"; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: \"p1bt\" is not null\n" + "# g2p_list2List: unsuccessful conversion: \"p1bt\" is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: \"p1bt\" is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: \"p1bt\" is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: \"p1bt\" is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: \"p1bt\" is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: \"p1bt\" is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: \"p1bt\" is not a complex value\n" + "# g2p_string2String: successful conversion of \"p1bt\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_pair2Tuple: successful conversion of (p1at . \"p1bt\") into a Python 2-Tuple\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(#:p2al . p2bl) CAR(stemp)=('g2p_pair2List 'guile2python . 'guile2python)\n" + "# Entered g2p_apply: sobj=(#:p2al . p2bl) stemplate=('g2p_pair2List 'guile2python . 'guile2python)\n" + "# Entered g2p_apply: sobj=#:p2al stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=#:p2al; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: #:p2al is not null\n" + "# g2p_list2List: unsuccessful conversion: #:p2al is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: #:p2al is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: #:p2al is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: #:p2al is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: #:p2al is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: #:p2al is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: #:p2al is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: #:p2al is not a string value\n" + "# g2p_symbol2String: unsuccessful conversion: #:p2al is not a symbol value\n" + "# g2p_keyword2String: successful conversion of #:p2al into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=p2bl stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=p2bl; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: p2bl is not null\n" + "# g2p_list2List: unsuccessful conversion: p2bl is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: p2bl is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: p2bl is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: p2bl is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: p2bl is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: p2bl is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: p2bl is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: p2bl is not a string value\n" + "# g2p_symbol2String: successful conversion of p2bl into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_pair2List: successful conversion of (#:p2al . p2bl) into a Python 2-List\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"\\\"(('p1at', 'p1bt'), ['p2al', 'p2bl'])\\\"\" into SCM\n"))) +(is-ok 5 "g2p* verbosity/3 coverage - pair2Tuple,pair2List" + expres5 + (with-output-to-string + (thunk-invoke-python-repr + '(((p1at . "p1bt") (#:p2al . p2bl))) + (list g2p_list2Tuple (list g2p_list2Tuple (cons g2p_pair2Tuple (cons guile2python guile2python)) (cons g2p_pair2List (cons guile2python guile2python))))))) + +(define substitute-hex-addresses-for-gggggggg + (lambda (strarg) + (regexp-substitute/global #f + "0x[0-9a-f]{8}" + strarg + 'pre "0xgggggggg" 'post))) + +(define expres6 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(((python-eval <function func at 0xgggggggg> #t) ((1 . \"one\") (2 . \"two\") (3 . \"three\")))) stemplate=('g2p_list2Tuple ('g2p_list2List 'g2p_opaque2Object ('g2p_alist2Dict ('g2p_num2Int . 'g2p_string2String))))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=((python-eval <function func at 0xgggggggg> #t) ((1 . \"one\") (2 . \"two\") (3 . \"three\"))) CAR(stemp)=('g2p_list2List 'g2p_opaque2Object ('g2p_alist2Dict ('g2p_num2Int . 'g2p_string2String)))\n" + "# Entered g2p_apply: sobj=((python-eval <function func at 0xgggggggg> #t) ((1 . \"one\") (2 . \"two\") (3 . \"three\"))) stemplate=('g2p_list2List 'g2p_opaque2Object ('g2p_alist2Dict ('g2p_num2Int . 'g2p_string2String)))\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=(python-eval <function func at 0xgggggggg> #t) CAR(stemp)='g2p_opaque2Object\n" + "# Entered g2p_apply: sobj=(python-eval <function func at 0xgggggggg> #t) stemplate='g2p_opaque2Object\n" + "# g2p_opaque2Object: the Python object inside opaque pysmob (python-eval <function func at 0xgggggggg> #t) is unwrapped\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=((1 . \"one\") (2 . \"two\") (3 . \"three\")) CAR(stemp)=('g2p_alist2Dict ('g2p_num2Int . 'g2p_string2String))\n" + "# Entered g2p_apply: sobj=((1 . \"one\") (2 . \"two\") (3 . \"three\")) stemplate=('g2p_alist2Dict ('g2p_num2Int . 'g2p_string2String))\n" + "# g2p_alist2Dict sobj=((1 . \"one\") (2 . \"two\") (3 . \"three\")) stemplate=(('g2p_num2Int . 'g2p_string2String))\n" + "# Entered g2p_apply: sobj=1 stemplate='g2p_num2Int\n" + "# g2p_num2Int: successful conversion of 1 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=\"one\" stemplate='g2p_string2String\n" + "# g2p_string2String: successful conversion of \"one\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=2 stemplate='g2p_num2Int\n" + "# g2p_num2Int: successful conversion of 2 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=\"two\" stemplate='g2p_string2String\n" + "# g2p_string2String: successful conversion of \"two\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=3 stemplate='g2p_num2Int\n" + "# g2p_num2Int: successful conversion of 3 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# Entered g2p_apply: sobj=\"three\" stemplate='g2p_string2String\n" + "# g2p_string2String: successful conversion of \"three\" into a Python String value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_alist2Dict: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"\\\"[<function func at 0xgggggggg>, {1: 'one', 2: 'two', 3: 'three'}]\\\"\" into SCM\n"))) +(python-eval "def func(a):\n print a\n" #f) +(define opaqueobj (python-eval "func" #t)) +(define run-test-opaque + (lambda () + (with-output-to-string + (thunk-invoke-python-repr + (list (list opaqueobj '((1 . "one")(2 . "two")(3 . "three")))) + (list g2p_list2Tuple (list g2p_list2List g2p_opaque2Object (cons g2p_alist2Dict (list (cons g2p_num2Int g2p_string2String))))))))) +(is-ok 6 "g2p* verbosity/3 coverage - opaque2Object,g2p_alist2Dict" + expres6 + (substitute-hex-addresses-for-gggggggg + (run-test-opaque))) + +; Additional tests + +(define expres7 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((#t 5)) stemplate=('g2p_list2Tuple ('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(#t 5) CAR(stemp)=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# Entered g2p_apply: sobj=(#t 5) stemplate=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=#t CAR(stemp)=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_apply: sobj=#t stemplate=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_leaf: sobj=#t stemplate=('g2p_num2Int 'g2p_bool2Bool)\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=#t stemplate='g2p_num2Int\n" + "# g2p_num2Int: unsuccessful conversion: #t is not a num value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_bool2Bool on sobj\n" + "# Entered g2p_apply: sobj=#t stemplate='g2p_bool2Bool\n" + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_leaf: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=5 CAR(stemp)=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_apply: sobj=5 stemplate=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_leaf: sobj=5 stemplate=('g2p_num2Int 'g2p_bool2Bool)\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=5 stemplate='g2p_num2Int\n" + "# g2p_num2Int: successful conversion of 5 into a Python Int value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_leaf: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2List: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"'[True, 5]'\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"'[True, 5]'\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"'[True, 5]'\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"'[True, 5]'\" into SCM\n"))) +(is-ok 7 "g2p_leaf verbosity/3 coverage - all values recognized by leaf" + expres7 + (with-output-to-string + (thunk-invoke-python-repr + '((#t 5 )) + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_bool2Bool)))))) + +; Run thunk-invoke-python-repr under catch harness. +(define catch-thunk-invoke-python-repr + (lambda (arg . template) + (lambda () + (catch + #t + (lambda () + (if (null? template) + (python-apply '("__builtin__" "repr") arg '()) + (python-apply '("__builtin__" "repr") arg '() (car template)))) + (lambda (key . args2) (object->string (list key args2))))))) + +(define expres8 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((3.1 5)) stemplate=('g2p_list2Tuple ('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(3.1 5) CAR(stemp)=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# Entered g2p_apply: sobj=(3.1 5) stemplate=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=3.1 CAR(stemp)=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_apply: sobj=3.1 stemplate=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_leaf: sobj=3.1 stemplate=('g2p_num2Int 'g2p_bool2Bool)\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=3.1 stemplate='g2p_num2Int\n" + "# g2p_num2Int: unsuccessful conversion: 3.1 is not a num value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_bool2Bool on sobj\n" + "# Entered g2p_apply: sobj=3.1 stemplate='g2p_bool2Bool\n" + "# g2p_bool2Bool: unsuccessful conversion: 3.1 is not a bool value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: unsuccessful conversion, no stemplate fit the sobj\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2List: unsuccessful conversion of element 0: 3.1 does not match personalized template\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2Tuple: unsuccessful conversion of element 0: (3.1 5) does not match personalized template\n" + "# Leaving g2p_apply: with null result\n"))) +(is-ok 8 "g2p_leaf verbosity/3 coverage - first value not recognized by leaf" + expres8 + (with-output-to-string + (catch-thunk-invoke-python-repr + '((3.1 5)) + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_bool2Bool)))))) + +(define expres9 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=((#t \"string\")) stemplate=('g2p_list2Tuple ('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=(#t \"string\") CAR(stemp)=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# Entered g2p_apply: sobj=(#t \"string\") stemplate=('g2p_list2List ('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool))\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=#t CAR(stemp)=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_apply: sobj=#t stemplate=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_leaf: sobj=#t stemplate=('g2p_num2Int 'g2p_bool2Bool)\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=#t stemplate='g2p_num2Int\n" + "# g2p_num2Int: unsuccessful conversion: #t is not a num value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_bool2Bool on sobj\n" + "# Entered g2p_apply: sobj=#t stemplate='g2p_bool2Bool\n" + "# g2p_bool2Bool: successful conversion of #t into a Python Bool value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_leaf: successful conversion\n" + "# Leaving g2p_apply: with non-null result\n" + "# DEBUG: g2p_list2List - processing item CAR(sobj)=\"string\" CAR(stemp)=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_apply: sobj=\"string\" stemplate=('g2p_leaf 'g2p_num2Int 'g2p_bool2Bool)\n" + "# Entered g2p_leaf: sobj=\"string\" stemplate=('g2p_num2Int 'g2p_bool2Bool)\n" + "# g2p_leaf: trying another stemplate 'g2p_num2Int on sobj\n" + "# Entered g2p_apply: sobj=\"string\" stemplate='g2p_num2Int\n" + "# g2p_num2Int: unsuccessful conversion: \"string\" is not a num value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_bool2Bool on sobj\n" + "# Entered g2p_apply: sobj=\"string\" stemplate='g2p_bool2Bool\n" + "# g2p_bool2Bool: unsuccessful conversion: \"string\" is not a bool value\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: unsuccessful conversion, no stemplate fit the sobj\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2List: unsuccessful conversion of element 1: \"string\" does not match personalized template\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2Tuple: unsuccessful conversion of element 0: (#t \"string\") does not match personalized template\n" + "# Leaving g2p_apply: with null result\n"))) +(is-ok 9 "g2p_leaf verbosity/3 coverage - last value not recognized by leaf" + expres9 + (with-output-to-string + (catch-thunk-invoke-python-repr + '((#t "string")) + (list g2p_list2Tuple (list g2p_list2List (list g2p_leaf g2p_num2Int g2p_bool2Bool)))))) + +(define saved-verbosity (pyguile-verbosity-set! 0)) + +(define catch-test-apply + (lambda (func args kws . targ) + (catch #t + (lambda () (python-apply func args kws (car targ))) + (lambda (key . args2) (object->string (list key args2)))))) + +(is-ok 10 "g2p_null2* validate test - non-null values" + "(misc-error (\"python-apply\" \"positional arguments conversion failure (~S)\" ((\"string\")) #f))" + (catch-test-apply '("__builtin__" "repr") '("string") '() + (list g2p_list2Tuple (list g2p_leaf g2p_null2Tuple0 g2p_null2List0 g2p_null2DictEmpty)))) + +(pyguile-verbosity-set! saved-verbosity) + +(define expres11 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(\"string\") stemplate=('g2p_list2Tuple ('g2p_leaf 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=\"string\" CAR(stemp)=('g2p_leaf 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty)\n" + "# Entered g2p_apply: sobj=\"string\" stemplate=('g2p_leaf 'g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty)\n" + "# Entered g2p_leaf: sobj=\"string\" stemplate=('g2p_null2Tuple0 'g2p_null2List0 'g2p_null2DictEmpty)\n" + "# g2p_leaf: trying another stemplate 'g2p_null2Tuple0 on sobj\n" + "# Entered g2p_apply: sobj=\"string\" stemplate='g2p_null2Tuple0\n" + "# g2p_null2Tuple0: unsuccessful conversion: \"string\" is not null\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_null2List0 on sobj\n" + "# Entered g2p_apply: sobj=\"string\" stemplate='g2p_null2List0\n" + "# g2p_null2List0: unsuccessful conversion: \"string\" is not null\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: trying another stemplate 'g2p_null2DictEmpty on sobj\n" + "# Entered g2p_apply: sobj=\"string\" stemplate='g2p_null2DictEmpty\n" + "# g2p_null2DictEmpty: unsuccessful conversion: \"string\" is not null\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_leaf: unsuccessful conversion, no stemplate fit the sobj\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2Tuple: unsuccessful conversion of element 0: \"string\" does not match personalized template\n" + "# Leaving g2p_apply: with null result\n"))) +(is-ok 11 "g2p_null2* verbosity/3 coverage - non-null values" + expres11 + (with-output-to-string + (catch-thunk-invoke-python-repr + '("string") + (list g2p_list2Tuple (list g2p_leaf g2p_null2Tuple0 g2p_null2List0 g2p_null2DictEmpty))))) + + +(define expres12 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(()) stemplate=('g2p_list2Tuple ('g2p_leaf . 'g2p_null2Tuple0))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=() CAR(stemp)=('g2p_leaf . 'g2p_null2Tuple0)\n" + "# Entered g2p_apply: sobj=() stemplate=('g2p_leaf . 'g2p_null2Tuple0)\n" + "# Entered g2p_leaf: sobj=() stemplate='g2p_null2Tuple0\n" + "# g2p_null2Tuple0: successful conversion of () into Python ()\n" + "# Leaving g2p_leaf, after G2P_SMOBP conversion, with non-null result\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# p2g_apply: pobj=\"'()'\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"'()'\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"'()'\" using stemplate=#<unspecified>\n" + "# p2g_String2string: successful conversion of \"'()'\" into SCM\n"))) +(is-ok 12 "g2p_leaf verbosity/3 coverage - G2P_SMOB, successful" + expres12 + (with-output-to-string + (catch-thunk-invoke-python-repr + '(()) + (list g2p_list2Tuple (cons g2p_leaf g2p_null2Tuple0))))) + +(define expres13 + (string-concatenate + (list + successful-verbose-3-report + "# Entered g2p_apply: sobj=(#t) stemplate=('g2p_list2Tuple ('g2p_leaf . 'g2p_null2Tuple0))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=#t CAR(stemp)=('g2p_leaf . 'g2p_null2Tuple0)\n" + "# Entered g2p_apply: sobj=#t stemplate=('g2p_leaf . 'g2p_null2Tuple0)\n" + "# Entered g2p_leaf: sobj=#t stemplate='g2p_null2Tuple0\n" + "# g2p_null2Tuple0: unsuccessful conversion: #t is not null\n" + "# Leaving g2p_leaf, after G2P_SMOBP conversion, with null result\n" + "# Leaving g2p_apply: with null result\n" + "# g2p_list2Tuple: unsuccessful conversion of element 0: #t does not match personalized template\n" + "# Leaving g2p_apply: with null result\n"))) +(is-ok 13 "g2p_leaf verbosity/3 coverage - G2P_SMOB, failed" + expres13 + (with-output-to-string + (catch-thunk-invoke-python-repr + '(#t) + (list g2p_list2Tuple (cons g2p_leaf g2p_null2Tuple0))))) + +; End of 19_verbose_always.t diff --git a/t/20_pyscm.t b/t/20_pyscm.t new file mode 100644 index 0000000..ef19cea --- /dev/null +++ b/t/20_pyscm.t @@ -0,0 +1,247 @@ +#!/usr/bin/guile -s +!# +; PySCM related tests. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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)) +(use-modules (srfi srfi-13)) ; string-concatenate +(load "scripts/test_auxiliary_functions.scm") + +(plan 7) + +(define guilefunc0 + (lambda (dummy1 dummy2) 2.73)) +(define pyfunc0code + (string-concatenate + '("def pyfunc0(func):\n" + " return(4.1 + func())\n"))) +(python-eval pyfunc0code) +(define pyfunc0-smob (python-eval "pyfunc0" #t)) + + +(is-ok 1 "show argumentless guile procedure and Python function" + "#<procedure guilefunc0 (dummy1 dummy2)>\n(python-eval <function pyfunc0 at 0xgggggggg> #t)\n" + (substitute-hex-addresses-for-gggggggg + (cdr + (capture-result-output-catch + (lambda () + (display guilefunc0) + (newline) + (display pyfunc0-smob) + (newline)))))) + +(is-ok 2 "pysmob func, using argumentless guile procedure" + 6.83 + (python-apply pyfunc0-smob (list guilefunc0) '() + (list g2p_list2Tuple (cons g2p_procedure2PySCMObject pyscm-default-template)))) + +(define expres3_cdr + (string-concatenate + (list + "# guile2python: entry: seeking to convert sobj=(python-eval <function pyfunc0 at 0xgggggggg> #t); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not null\n" + "# g2p_list2List: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a string value\n" + "# g2p_symbol2String: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a symbol value\n" + "# g2p_keyword2String: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a keyword value\n" + "# g2p_procedure2PySCMObject: unsuccessful conversion: (python-eval <function pyfunc0 at 0xgggggggg> #t) is not a procedure\n" + "# g2p_opaque2Object: the Python object inside opaque pysmob (python-eval <function pyfunc0 at 0xgggggggg> #t) is unwrapped\n" + "# python_apply: decoded pfunc \"<function pyfunc0 at 0xgggggggg>\"\n" + "# python_apply: decoded function actually to be invoked: \"<function pyfunc0 at 0xgggggggg>\"\n" + "# Entered g2p_apply: sobj=(#<procedure guilefunc0 (dummy1 dummy2)>) stemplate=('g2p_list2Tuple ('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=#<procedure guilefunc0 (dummy1 dummy2)> CAR(stemp)=('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f))\n" + "# Entered g2p_apply: sobj=#<procedure guilefunc0 (dummy1 dummy2)> stemplate=('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f))\n" + "# wrap_scm: was called to wrap #<procedure guilefunc0 (dummy1 dummy2)>\n" + "# g2p_procedure2PySCMObject: successful conversion: #<procedure guilefunc0 (dummy1 dummy2)> has been wrapped\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# python_apply: decoded positional arguments \"(<pyscm.PySCM object at 0xgggggggg>,)\"\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# python_apply: decoded keyword arguments \"{}\"\n" + "# pyscm_PySCM_call: calling #<procedure guilefunc0 (dummy1 dummy2)> with args=\"()\" and keywords=\"(null PyObject)\"; stemplate=#('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f)\n" + "# p2g_apply: pobj=\"()\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"()\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# p2g_String2string: failed to convert pobj=\"()\" using stemplate=#<unspecified>\n" + "# Entered g2p_apply: sobj=2.73 stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=2.73; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: 2.73 is not null\n" + "# g2p_list2List: unsuccessful conversion: 2.73 is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: 2.73 is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: 2.73 is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: 2.73 is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: 2.73 is not a bignum value\n" + "# g2p_real2Float: successful conversion of 2.73 into a Python Float value\n" + "# Leaving g2p_apply: with non-null result\n" + "# p2g_apply: pobj=\"6.8300000000000001\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"6.8300000000000001\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"6.8300000000000001\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"6.8300000000000001\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"6.8300000000000001\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"6.8300000000000001\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: successful conversion of \"6.8300000000000001\" into SCM\n" + "# python_apply: decoded results:\n" + "# Python: \"6.8300000000000001\"\n" + "# Scheme: 6.83\n"))) +(define saved-verbosity (pyguile-verbosity-set! (+ 3 64 128 256))) +(define gggggggg-transform-cdr ; perform substitute-hex-addresses-for-gggggggg only on cdr of the argument + (lambda (arg) + (cons (car arg) + (substitute-hex-addresses-for-gggggggg (cdr arg))))) +(is-ok 3 "pysmob func, using argumentless guile procedure" + (cons 6.83 expres3_cdr) + (gggggggg-transform-cdr + (capture-result-output-catch + python-apply pyfunc0-smob (list guilefunc0) '() + (list g2p_list2Tuple (cons g2p_procedure2PySCMObject pyscm-default-template))))) +(pyguile-verbosity-set! saved-verbosity) + +(define guilefunc + (lambda (arg dummy) (+ 3.5 (car arg)))) +(define pyfunccode + (string-concatenate + '("def pyfunc(argu,func):\n" + " return(4.2 + func(argu))\n"))) +(python-eval pyfunccode) +(define pyfunc-smob (python-eval "pyfunc" #t)) + +(is-ok 4 "show guile procedure with argument and Python function" + "#<procedure guilefunc (arg dummy)>\n(python-eval <function pyfunc at 0xgggggggg> #t)\n" + (substitute-hex-addresses-for-gggggggg + (cdr + (capture-result-output-catch + (lambda () + (display guilefunc) + (newline) + (display pyfunc-smob) + (newline)))))) + + +(is-ok 5 "pysmob func, using guile procedure with argument" + 67.7 + (python-apply pyfunc-smob (list 60.0 guilefunc) '() + (list g2p_list2Tuple g2p_real2Float (cons g2p_procedure2PySCMObject pyscm-default-template)))) + +(define expres6_cdr + (string-concatenate + (list + "# guile2python: entry: seeking to convert sobj=(python-eval <function pyfunc at 0xgggggggg> #t); unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not null\n" + "# g2p_list2List: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a bignum value\n" + "# g2p_real2Float: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a real value\n" + "# g2p_complex2Complex: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a complex value\n" + "# g2p_string2String: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a string value\n" + "# g2p_symbol2String: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a symbol value\n" + "# g2p_keyword2String: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a keyword value\n" + "# g2p_procedure2PySCMObject: unsuccessful conversion: (python-eval <function pyfunc at 0xgggggggg> #t) is not a procedure\n" + "# g2p_opaque2Object: the Python object inside opaque pysmob (python-eval <function pyfunc at 0xgggggggg> #t) is unwrapped\n" + "# python_apply: decoded pfunc \"<function pyfunc at 0xgggggggg>\"\n" + "# python_apply: decoded function actually to be invoked: \"<function pyfunc at 0xgggggggg>\"\n" + "# Entered g2p_apply: sobj=(60.0 #<procedure guilefunc (arg dummy)>) stemplate=('g2p_list2Tuple 'g2p_real2Float ('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f)))\n" + "# g2p_list2Tuple - processing item CAR(sobj)=60.0 CAR(stemp)='g2p_real2Float\n" + "# Entered g2p_apply: sobj=60.0 stemplate='g2p_real2Float\n" + "# g2p_real2Float: successful conversion of 60.0 into a Python Float value\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple - processing item CAR(sobj)=#<procedure guilefunc (arg dummy)> CAR(stemp)=('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f))\n" + "# Entered g2p_apply: sobj=#<procedure guilefunc (arg dummy)> stemplate=('g2p_procedure2PySCMObject . #('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f))\n" + "# wrap_scm: was called to wrap #<procedure guilefunc (arg dummy)>\n" + "# g2p_procedure2PySCMObject: successful conversion: #<procedure guilefunc (arg dummy)> has been wrapped\n" + "# Leaving g2p_apply: with non-null result\n" + "# g2p_list2Tuple: successful conversion of list () by template\n" + "# Leaving g2p_apply: with non-null result\n" + "# python_apply: decoded positional arguments \"(60.0, <pyscm.PySCM object at 0xgggggggg>)\"\n" + "# guileassoc2pythondict: entry: seeking to convert sobj=() using stemplate=#<undefined>\n" + "# guileassoc2pythondict: successful conversion of ()\n" + "# python_apply: decoded keyword arguments \"{}\"\n" + "# pyscm_PySCM_call: calling #<procedure guilefunc (arg dummy)> with args=\"(60.0,)\" and keywords=\"(null PyObject)\"; stemplate=#('python2guile 'python2guile 'guile2python #<procedure apply (fun . args)> #f)\n" + "# p2g_apply: pobj=\"(60.0,)\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"(60.0,)\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_Complex2complex: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_String2string: failed to convert pobj=\"(60.0,)\" using stemplate=#<unspecified>\n" + "# p2g_apply: pobj=\"60.0\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"60.0\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"60.0\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"60.0\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"60.0\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"60.0\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: successful conversion of \"60.0\" into SCM\n" + "# p2g_Tuple2list: 1. converted item pobj=0[\"60.0\"], stemplate='python2guile\n" + "# Entered g2p_apply: sobj=63.5 stemplate='guile2python\n" + "# guile2python: entry: seeking to convert sobj=63.5; unused stemplate=#<unspecified>\n" + "# g2p_null2PyNone: unsuccessful conversion: 63.5 is not null\n" + "# g2p_list2List: unsuccessful conversion: 63.5 is not a list\n" + "# g2p_pair2Tuple: unsuccessful conversion: 63.5 is not a pair\n" + "# g2p_bool2Bool: unsuccessful conversion: 63.5 is not a bool value\n" + "# g2p_num2Int: unsuccessful conversion: 63.5 is not a num value\n" + "# g2p_bignum2Long: unsuccessful conversion: 63.5 is not a bignum value\n" + "# g2p_real2Float: successful conversion of 63.5 into a Python Float value\n" + "# Leaving g2p_apply: with non-null result\n" + "# p2g_apply: pobj=\"67.700000000000003\" smob-stemplate='python2guile\n" + "# python2guile: trying to convert pobj=\"67.700000000000003\" using stemplate=#<unspecified>\n" + "# p2g_None2SCM_EOL: pobj=\"67.700000000000003\" stemplate=#<unspecified>\n" + "# p2g_Bool2SCM_BOOL: failed to convert pobj=\"67.700000000000003\" using stemplate=#<unspecified>\n" + "# p2g_Int2num: failed to convert pobj=\"67.700000000000003\" using stemplate=#<unspecified>\n" + "# p2g_Long2bignum: failed to convert pobj=\"67.700000000000003\" using stemplate=#<unspecified>\n" + "# p2g_Float2real: successful conversion of \"67.700000000000003\" into SCM\n" + "# python_apply: decoded results:\n" + "# Python: \"67.700000000000003\"\n" + "# Scheme: 67.7\n"))) +(set! saved-verbosity (pyguile-verbosity-set! (+ 3 64 128 256))) +(is-ok 6 "pysmob func, using guile procedure with argument" + (cons 67.7 expres6_cdr) + (gggggggg-transform-cdr + (capture-result-output-catch + python-apply pyfunc-smob (list 60.0 guilefunc) '() + (list g2p_list2Tuple g2p_real2Float (cons g2p_procedure2PySCMObject pyscm-default-template))))) +(pyguile-verbosity-set! saved-verbosity) + +(python-eval "def holdval(val):\n global heldval\n heldval=val\n") +(python-apply '("__main__" "holdval") (list guilefunc0) '()) +(like 7 "obtain python representation of a procedure value" + "^#<procedure guilefunc0 \\([-a-zA-Z0-9_]+ [-a-zA-Z0-9_]+\\)>$" + (object->string (python-eval "heldval" #t))) + +; End of 20_pyscm.t diff --git a/t/__init__.py b/t/__init__.py new file mode 100644 index 0000000..5dff9f3 --- /dev/null +++ b/t/__init__.py @@ -0,0 +1,2 @@ +# Dummy module - needed to keep happy import commands +# which import t/scripts/*.py modules diff --git a/t/scripts/RunGuileTests.pl b/t/scripts/RunGuileTests.pl new file mode 100755 index 0000000..a61a18a --- /dev/null +++ b/t/scripts/RunGuileTests.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +# Run Guile tests - filenames are given as arguments to the script. +######################################################################## +# +# 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 strict; +use TAP::Harness; +my @tests = @ARGV; +my %args = ( + verbosity => 0, + timer => 1, + exec => ['/usr/bin/guile', '-s'], + ); +my $harness = TAP::Harness->new( \%args ); + $harness->runtests(@tests); + +# End of RunGuileTests.pl diff --git a/t/scripts/__init__.py b/t/scripts/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/scripts/__init__.py diff --git a/t/scripts/t2conv.py b/t/scripts/t2conv.py new file mode 100644 index 0000000..160c3b6 --- /dev/null +++ b/t/scripts/t2conv.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# Basic tests to validate conversions from Python to Guile and vice versa. +######################################################################## +# +# 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>. +# +######################################################################## + +def return_None(): + return None + +def return_True(): + return True + +def return_False(): + return False + +def return_Int1(): + return 1 + +def return_Int_5(): + return(-5) + +def return_BigInt(): + return(1048576*1048576*1048576*32) + +def return_BigInt_neg(): + return(-1048576*1048576*1048576*32) + +def return_String1(): + return("abcdefghi") + +def return_String2(): + return("01abCD%^") + +def return_String_Zero(): + return("bef" + chr(0) + chr(163) + "ore") + +if (__name__ == '__main__'): + print "return_None: ",return_None() + print "return_True: ",return_True() + print "return_False: ",return_False() + print "return_Int1: ",return_Int1() + print "return_Int_5: ",return_Int_5() + print "return_BigInt: ",return_BigInt() + print "return_BigInt_neg: ",return_BigInt_neg() + print "String1: ",return_String1() + print "String2: ",return_String2() + print "String_Zero: ",return_String_Zero(),repr(return_String_Zero()) + +# End of t2conv.py diff --git a/t/scripts/t4apply.py b/t/scripts/t4apply.py new file mode 100644 index 0000000..a716462 --- /dev/null +++ b/t/scripts/t4apply.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# Auxiliary functions for exercising python-apply. +######################################################################## +# +# 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>. +# +######################################################################## + +def return_args(*args,**kw): + return("positional: %s keywords: %s" % (repr(args),repr(kw))) + +class cl1(object): + def __init__(self,num=1,str="2"): + self.num = num + self.str = str + + def myfunc(self,arg="x"): + return(arg + self.str) + +class cl2(object): + def __init__(self,num=3): + self.num2 = num + self.mycl1 = cl1(10,str="Twenty") + + def cl2func(self,argx="y"): + return(str(self.num2) + argx) + +mainobj = cl2(33) + +# End of t4apply.py diff --git a/t/scripts/t5smobs.py b/t/scripts/t5smobs.py new file mode 100644 index 0000000..2f4b4a5 --- /dev/null +++ b/t/scripts/t5smobs.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# Auxiliary functions for exercising pysmobs. +######################################################################## +# +# 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>. +# +######################################################################## + +class opaq(object): + def __init__(self,arg1): + self.arg1 = arg1 + def transform(self): + self.arg1 = self.arg1 + self.arg1 + def __repr__(self): + return("opaq(%s)" % repr(self.arg1)) + +# Work around temporary problem in PyGuile. +def genopaq(arg): + return(opaq(arg)) + +class noisydelete(object): + def __init__(self,id): + self.id = id + def __del__(self): + print "# Deleting class instance %s" % self.id + #object.__del__() + def __repr__(self): + return(repr(self.id)) + def __cmp__(self,other): + if ((self.id == "me") and (other.id == 42)): + # Want to prove that this function has indeed been exercised. + return(0) + return(cmp(self.id,other.id)) + +# End of t5smobs.py diff --git a/t/scripts/t7except.py b/t/scripts/t7except.py new file mode 100644 index 0000000..d2f6948 --- /dev/null +++ b/t/scripts/t7except.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# Raising exception inside my own code +######################################################################## +# +# 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>. +# +######################################################################## + +import exceptions +class myexception(exceptions.Exception): + pass + +def raiser(arg="typical!"): + raise myexception("This is my exception",arg) + +# End of t7except.py diff --git a/t/scripts/test_auxiliary_functions.scm b/t/scripts/test_auxiliary_functions.scm new file mode 100644 index 0000000..f420fab --- /dev/null +++ b/t/scripts/test_auxiliary_functions.scm @@ -0,0 +1,177 @@ +#!/usr/bin/guile -s +!# +; Auxiliary functions, for use by test scripts +; Those functions are used by scripts from 20_* and on. +; Earlier scripts usually define their own versions of the +; functions. +; +; To use the functions, add +; (load "scripts/test_auxliary_functions.scm") +; at the beginning of your test script, after any (use-modules ...) +; calls. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; 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 (ice-9 regex)) ; regexp-substitute + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions from modules, unlikely to be generally useful +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; from 03_guile2python.t +(define invoke-python-func + (lambda (module func arg) + (python-apply (list module func) (list arg) '()))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions likely to be generally useful +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Miscellaneous data manipulation ; +; functions ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Returns a 3-element list of booleans. +(define equalities3? + (lambda (obj1 obj2) + (list (eq? obj1 obj2) (eqv? obj1 obj2) (equal? obj1 obj2)))) + +; Does one alist include another alist. +; Inclusion means that all keys of the included alist are in the +; including one, and the corresponding values are equal. +; The equality criteria used here is equal? (for both key and value). +(define alist-properly-included? + (lambda (included includor) + (if (null? included) #t + (let ((key (caar included)) + (value (cdar included)) + (rest (cdr included))) + (let ((includor-ref (assoc key includor))) + (cond ((not includor-ref) #f) + ((not (equal? (cdr includor-ref) value)) #f) + (else (alist-properly-included? rest includor)))))))) + +; Are two alists equal? +(define alist-equal? + (lambda (alista alistb) + (and (alist-properly-included? alista alistb) + (alist-properly-included? alistb alista)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Modify actual results for easier ; +; comparison to expected results ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Replace all hex addresses appearing in a string +; by a specific literal. +(define substitute-hex-addresses-for-gggggggg + (lambda (strarg) + (regexp-substitute/global #f + "0x[0-9a-f]{8}" + strarg + 'pre "0xgggggggg" 'post))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Running inside catch harness ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Run a function, so that anything it writes to the current +; output port is captured, together with its return value. +; The return value to caller of capture-result-output is the +; pair of (return-value . output-string). + +(define capture-result-output + (lambda (func . args) + (let ((stdoutstr #f) + (retval #f)) + (set! stdoutstr + (with-output-to-string + (lambda () (set! retval + (apply func args))))) + (cons retval stdoutstr)))) + +; Run a function in an environment, in which any exceptions +; raised by it are caught; and anything it writes to the +; current output port is captured as well. +; The return value to caller of capture-result-output-catch +; is the pair of (return-value . output-string). +(define capture-result-output-catch + (lambda (func . args) + (let ((output-string #f) + (return-value #f)) + (set! output-string + (with-output-to-string + (lambda () (set! return-value + (catch #t + (lambda () (apply func args)) + (lambda (key . args2) + (object->string (list key args2)))))))) + (cons return-value output-string)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Functions specific to PyGuile ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Run python-eval under catch harness. +; template can be #f when no return value is expected, or #t when +; the default template is to be used. +(define catch-python-eval + (lambda (txt template) + (catch #t + (lambda () (python-eval txt template)) + (lambda (key . args) (object->string (list key args)))))) + +; Run python-import under catch harness. +(define catch-python-import + (lambda (arg) + (catch #t + (lambda () (python-import arg)) + (lambda (key . args) (object->string (list key args)))))) + +; Run python-apply under catch harness. +; The positional argument list must be supplied. +; The keyword argument list and the templates are optional. +(define catch-python-apply + (lambda (func posargs . kwargs-templates) + (catch #t + (lambda () (apply python-apply func posargs kwargs-templates)) + (lambda (key . args) (object->string (list key args)))))) + +; The following function is useful for checking how a SCM is +; actually converted into a PyObject using a template. +; The conversion is run under a catch harness. +(define catch-thunk-invoke-python-repr + (lambda (arg . template) + (catch #t + (lambda () + (if (null? template) + (python-apply '("__builtin__" "repr") arg '()) + (python-apply '("__builtin__" "repr") arg '() (car template)))) + (lambda (key . args2) (object->string (list key args2)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; End of test_axuliary_functions.scm |