python: Fix unit tests -- only test when library is loaded.
Also reformat some unit tests that have a quot as the stack output.windows-high-dpi
parent
7a729b7637
commit
f2a86e0bae
|
@ -4,7 +4,7 @@ python.ffi python.objects sequences strings tools.test ;
|
||||||
IN: python
|
IN: python
|
||||||
|
|
||||||
: py-test ( result quot -- )
|
: py-test ( result quot -- )
|
||||||
'[ _ with-destructors ] unit-test ; inline
|
'[ python-dll-loaded? [ _ [ _ with-destructors ] unit-test ] when ] call ; inline
|
||||||
|
|
||||||
! None testing
|
! None testing
|
||||||
{ t } [
|
{ t } [
|
||||||
|
@ -17,11 +17,12 @@ IN: python
|
||||||
"sys" py-import "getrefcount" getattr
|
"sys" py-import "getrefcount" getattr
|
||||||
<none> <1py-tuple> call-object py>
|
<none> <1py-tuple> call-object py>
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
{ t } [
|
{ t } [
|
||||||
! For some reason, the count increased by one the first time.
|
! For some reason, the count increased by one the first time.
|
||||||
count-none-refs drop
|
count-none-refs drop
|
||||||
count-none-refs count-none-refs =
|
count-none-refs count-none-refs =
|
||||||
] unit-test
|
] py-test
|
||||||
|
|
||||||
{ } [ { f f f } >py drop ] py-test
|
{ } [ { f f f } >py drop ] py-test
|
||||||
|
|
||||||
|
@ -47,16 +48,16 @@ IN: python
|
||||||
|
|
||||||
{ } [ 123 <alien> unsteal-ref ] unit-test
|
{ } [ 123 <alien> unsteal-ref ] unit-test
|
||||||
|
|
||||||
{ t } [ Py_GetVersion string? ] unit-test
|
{ t } [ Py_GetVersion string? ] py-test
|
||||||
|
|
||||||
[ "os" ] [ "os" py-import PyModule_GetName ] py-test
|
[ "os" ] [ "os" py-import PyModule_GetName ] py-test
|
||||||
|
|
||||||
[ t ] [
|
{ t } [
|
||||||
"os" py-import "getpid" getattr
|
"os" py-import "getpid" getattr
|
||||||
{ } >py call-object py> 0 >
|
{ } >py call-object py> 0 >
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
[ t ] [ Py_IsInitialized ] py-test
|
{ t } [ Py_IsInitialized ] py-test
|
||||||
|
|
||||||
! py-importing
|
! py-importing
|
||||||
[ { "ImportError" "No module named kolobi" f } ] [
|
[ { "ImportError" "No module named kolobi" f } ] [
|
||||||
|
@ -66,22 +67,22 @@ IN: python
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! setattr
|
! setattr
|
||||||
[ 73 ] [
|
{ 73 } [
|
||||||
"sys" py-import "testit" [ 73 >py setattr ] [ getattr py> ] 2bi
|
"sys" py-import "testit" [ 73 >py setattr ] [ getattr py> ] 2bi
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Tuples
|
! Tuples
|
||||||
[ 2 ] [ 2 <py-tuple> py-tuple-size ] py-test
|
{ 2 } [ 2 <py-tuple> py-tuple-size ] py-test
|
||||||
|
|
||||||
: py-datepy> ( py-obj -- timestamp )
|
: py-datepy> ( py-obj -- timestamp )
|
||||||
{ "year" "month" "day" } [ getattr py> ] with map
|
{ "year" "month" "day" } [ getattr py> ] with map
|
||||||
first3 0 0 0 instant <timestamp> ;
|
first3 0 0 0 instant <timestamp> ;
|
||||||
|
|
||||||
! Lists
|
! Lists
|
||||||
[ t ] [ V{ 4 8 15 16 23 42 } dup >py py> = ] py-test
|
{ t } [ V{ 4 8 15 16 23 42 } dup >py py> = ] py-test
|
||||||
|
|
||||||
! ! Datetimes
|
! ! Datetimes
|
||||||
[ t ] [
|
{ t } [
|
||||||
[ py-datepy> ] "date" py-type-dispatch get set-at
|
[ py-datepy> ] "date" py-type-dispatch get set-at
|
||||||
"datetime" py-import "date" getattr "today" getattr
|
"datetime" py-import "date" getattr "today" getattr
|
||||||
{ } >py call-object py>
|
{ } >py call-object py>
|
||||||
|
@ -89,38 +90,38 @@ IN: python
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Unicode
|
! Unicode
|
||||||
[ "غثههح" ] [
|
{ "غثههح" } [
|
||||||
"os.path" py-import "basename" getattr { "غثههح" } >py call-object py>
|
"os.path" py-import "basename" getattr { "غثههح" } >py call-object py>
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Instance variables
|
! Instance variables
|
||||||
[ 7 ] [
|
{ 7 } [
|
||||||
"datetime" py-import "timedelta" getattr
|
"datetime" py-import "timedelta" getattr
|
||||||
{ 7 } >py call-object "days" getattr py>
|
{ 7 } >py call-object "days" getattr py>
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Create a dictonary
|
! Create a dictonary
|
||||||
[ 0 ] [ <py-dict> py-dict-size ] py-test
|
{ 0 } [ <py-dict> py-dict-size ] py-test
|
||||||
|
|
||||||
! Dictionary with object keys
|
! Dictionary with object keys
|
||||||
[ 1 ] [
|
{ 1 } [
|
||||||
<py-dict> dup 0 >py 33 >py py-dict-set-item py-dict-size
|
<py-dict> dup 0 >py 33 >py py-dict-set-item py-dict-size
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Dictionary with string keys
|
! Dictionary with string keys
|
||||||
[ 1 ] [
|
{ 1 } [
|
||||||
<py-dict> [ "foo" 33 >py py-dict-set-item-string ] [ py-dict-size ] bi
|
<py-dict> [ "foo" 33 >py py-dict-set-item-string ] [ py-dict-size ] bi
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Get dictionary items
|
! Get dictionary items
|
||||||
[ 33 ] [
|
{ 33 } [
|
||||||
<py-dict> "tjaba"
|
<py-dict> "tjaba"
|
||||||
[ 33 >py py-dict-set-item-string ]
|
[ 33 >py py-dict-set-item-string ]
|
||||||
[ py-dict-get-item-string py> ] 2bi
|
[ py-dict-get-item-string py> ] 2bi
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Nest dicts
|
! Nest dicts
|
||||||
[ 0 ] [
|
{ 0 } [
|
||||||
<py-dict> "foo"
|
<py-dict> "foo"
|
||||||
[ <py-dict> py-dict-set-item-string ]
|
[ <py-dict> py-dict-set-item-string ]
|
||||||
[ py-dict-get-item-string ] 2bi
|
[ py-dict-get-item-string ] 2bi
|
||||||
|
@ -128,20 +129,21 @@ IN: python
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Nested tuples
|
! Nested tuples
|
||||||
[ 3 ] [
|
{ 3 } [
|
||||||
1 <py-tuple> dup 0 3 <py-tuple> py-tuple-set-item
|
1 <py-tuple> dup 0 3 <py-tuple> py-tuple-set-item
|
||||||
0 py-tuple-get-item py-tuple-size
|
0 py-tuple-get-item py-tuple-size
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Round tripping!
|
! Round tripping!
|
||||||
[ { "foo" { 99 77 } } ] [ { "foo" { 99 77 } } >py py> ] py-test
|
{ { "foo" { 99 77 } } }
|
||||||
|
[ { "foo" { 99 77 } } >py py> ] py-test
|
||||||
|
|
||||||
[ H{ { "foo" "bar" } { 3 4 } } ] [
|
{ H{ { "foo" "bar" } { 3 4 } } } [
|
||||||
H{ { "foo" "bar" } { 3 4 } } >py py>
|
H{ { "foo" "bar" } { 3 4 } } >py py>
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Kwargs
|
! Kwargs
|
||||||
[ 2014 10 22 ] [
|
{ 2014 10 22 } [
|
||||||
"datetime" py-import "date" getattr
|
"datetime" py-import "date" getattr
|
||||||
{ } >py H{ { "year" 2014 } { "month" 10 } { "day" 22 } } >py
|
{ } >py H{ { "year" 2014 } { "month" 10 } { "day" 22 } } >py
|
||||||
call-object-full py>
|
call-object-full py>
|
||||||
|
@ -149,7 +151,7 @@ IN: python
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Modules
|
! Modules
|
||||||
[ t ] [
|
{ t } [
|
||||||
"os" py-import PyModule_GetDict dup Py_IncRef &Py_DecRef py-dict-size 100 >
|
"os" py-import PyModule_GetDict dup Py_IncRef &Py_DecRef py-dict-size 100 >
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
|
|
|
@ -116,5 +116,8 @@ ERROR: missing-type type ;
|
||||||
: with-quot>py-cfunction ( alien quot -- )
|
: with-quot>py-cfunction ( alien quot -- )
|
||||||
'[ <py-cfunction> @ ] with-callback ; inline
|
'[ <py-cfunction> @ ] with-callback ; inline
|
||||||
|
|
||||||
[ "PyIsInitialized" "python2.7" library-dll dlsym? [ py-initialize ] when ] "python" add-startup-hook
|
: python-dll-loaded? ( -- ? )
|
||||||
[ py-finalize ] "python" add-shutdown-hook
|
"PyIsInitialized" "python2.7" library-dll dlsym? ;
|
||||||
|
|
||||||
|
[ python-dll-loaded? [ py-initialize ] when ] "python" add-startup-hook
|
||||||
|
[ python-dll-loaded? [ py-finalize ] when ] "python" add-shutdown-hook
|
||||||
|
|
|
@ -8,7 +8,10 @@ QUALIFIED-WITH: sequences s
|
||||||
IN: python.syntax.tests
|
IN: python.syntax.tests
|
||||||
|
|
||||||
: py-test ( result quot -- )
|
: py-test ( result quot -- )
|
||||||
'[ _ with-destructors ] unit-test ; inline
|
'[ python-dll-loaded? [ _ [ _ with-destructors ] unit-test ] when ] call ; inline
|
||||||
|
|
||||||
|
: long-py-test ( result quot -- )
|
||||||
|
'[ python-dll-loaded? [ _ [ _ with-destructors ] long-unit-test ] when ] call ; inline
|
||||||
|
|
||||||
{ t } [ getpid py> integer? ] py-test
|
{ t } [ getpid py> integer? ] py-test
|
||||||
|
|
||||||
|
@ -22,22 +25,22 @@ IN: python.syntax.tests
|
||||||
[ ] [ 0 >py sleep ] py-test
|
[ ] [ 0 >py sleep ] py-test
|
||||||
|
|
||||||
! Module variables are bound as zero-arg functions
|
! Module variables are bound as zero-arg functions
|
||||||
[ t ] [ $path py> s:sequence? ] py-test
|
{ t } [ $path py> s:sequence? ] py-test
|
||||||
|
|
||||||
[ t ] [ $path len int py> 5 > ] py-test
|
{ t } [ $path len int py> 5 > ] py-test
|
||||||
|
|
||||||
[ 10 ] [ 10 >py range len py> ] py-test
|
[ 10 ] [ 10 >py range len py> ] py-test
|
||||||
|
|
||||||
! Callables
|
! Callables
|
||||||
[ t ] [
|
{ t } [
|
||||||
"os" py-import "getpid" getattr
|
"os" py-import "getpid" getattr
|
||||||
[ callable ] [ PyCallable_Check 1 = ] bi and
|
[ callable ] [ PyCallable_Check 1 = ] bi and
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Reference counting
|
! Reference counting
|
||||||
[ 1 ] [ 3 <py-tuple> getrefcount py> ] py-test
|
{ 1 } [ 3 <py-tuple> getrefcount py> ] py-test
|
||||||
|
|
||||||
[ -1 ] [
|
{ -1 } [
|
||||||
H{ { "foo" 33 } { "bar" 44 } } >py
|
H{ { "foo" 33 } { "bar" 44 } } >py
|
||||||
[ "foo" py-dict-get-item-string getrefcount py> ]
|
[ "foo" py-dict-get-item-string getrefcount py> ]
|
||||||
[
|
[
|
||||||
|
@ -48,7 +51,7 @@ IN: python.syntax.tests
|
||||||
[ "foo" py-dict-get-item-string getrefcount py> ] tri -
|
[ "foo" py-dict-get-item-string getrefcount py> ] tri -
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
[ -1 ] [
|
{ -1 } [
|
||||||
"abcd" >py <1py-tuple>
|
"abcd" >py <1py-tuple>
|
||||||
[ 0 py-tuple-get-item getrefcount py> ]
|
[ 0 py-tuple-get-item getrefcount py> ]
|
||||||
[
|
[
|
||||||
|
@ -63,14 +66,14 @@ IN: python.syntax.tests
|
||||||
[ always-destructors get [ alien>> = ] with s:count ] bi =
|
[ always-destructors get [ alien>> = ] with s:count ] bi =
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
[ t ] [
|
{ t } [
|
||||||
"python-file" temp-file >py "wb" >py open
|
"python-file" temp-file >py "wb" >py open
|
||||||
[ tell ] [ fileno ] [ close ] tri
|
[ tell ] [ fileno ] [ close ] tri
|
||||||
[ py> integer? ] both?
|
[ py> integer? ] both?
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Method chaining
|
! Method chaining
|
||||||
[ t ] [
|
{ t } [
|
||||||
"hello there" >py title 20 >py zfill "00" >py startswith py>
|
"hello there" >py title 20 >py zfill "00" >py startswith py>
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
|
@ -85,10 +88,10 @@ PY-METHODS: func =>
|
||||||
PY-METHODS: code =>
|
PY-METHODS: code =>
|
||||||
co_argcount ( code -- n ) ;
|
co_argcount ( code -- n ) ;
|
||||||
|
|
||||||
[ 1 ] [ $splitext $func_code $co_argcount py> ] py-test
|
{ 1 } [ $splitext $func_code $co_argcount py> ] py-test
|
||||||
|
|
||||||
! Change sys.path
|
! Change sys.path
|
||||||
[ t ] [
|
{ t } [
|
||||||
$path "test" >py [ append ] [ drop py> ] [ remove ] 2tri
|
$path "test" >py [ append ] [ drop py> ] [ remove ] 2tri
|
||||||
"test" swap in?
|
"test" swap in?
|
||||||
] py-test
|
] py-test
|
||||||
|
@ -99,7 +102,7 @@ PY-METHODS: code =>
|
||||||
] py-test
|
] py-test
|
||||||
|
|
||||||
! Kwargs in methods
|
! Kwargs in methods
|
||||||
[ t ] [
|
{ t } [
|
||||||
[
|
[
|
||||||
ArgumentParser dup
|
ArgumentParser dup
|
||||||
"--foo" >py H{ { "help" "badger" } } >py add_argument
|
"--foo" >py H{ { "help" "badger" } } >py add_argument
|
||||||
|
@ -118,14 +121,14 @@ PY-METHODS: code =>
|
||||||
100000 [
|
100000 [
|
||||||
[ [ 987 >py basename drop ] ignore-errors ] with-destructors
|
[ [ 987 >py basename drop ] ignore-errors ] with-destructors
|
||||||
] times
|
] times
|
||||||
] long-unit-test
|
] long-py-test
|
||||||
|
|
||||||
! Another leaky test
|
! Another leaky test
|
||||||
{ } [
|
{ } [
|
||||||
1000000 [
|
1000000 [
|
||||||
[ { 9 8 7 6 5 4 3 2 1 } >py ] with-destructors drop
|
[ { 9 8 7 6 5 4 3 2 1 } >py ] with-destructors drop
|
||||||
] times
|
] times
|
||||||
] long-unit-test
|
] long-py-test
|
||||||
|
|
||||||
! Working with types
|
! Working with types
|
||||||
PY-QUALIFIED-FROM: types => UnicodeType ( -- ) ;
|
PY-QUALIFIED-FROM: types => UnicodeType ( -- ) ;
|
||||||
|
|
Loading…
Reference in New Issue