The test me console is meant as a reference but is hardly perfect. It is also rather hard for me to help you debug it.
I therefore suggest you create a simple standalone script that does something similar to the above. A script is much easier to debug.
Thanks,