test/test_rubypython.rb in rubypython-0.2.3 vs test/test_rubypython.rb in rubypython-0.2.4

- old
+ new

@@ -3,17 +3,18 @@ class TestRubypython < Test::Unit::TestCase def setup end + def test_simple assert RubyPython.start assert RubyPython.import "urllib" assert(RubyPython.stop) assert(!RubyPython.stop) end - + def test_delegation RubyPython.start cPickle=RubyPython.import("cPickle") assert_instance_of(RubyPythonBridge::RubyPyModule,cPickle) assert_equal(cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns."),{"a"=>"n", [1, "2"]=>4}) @@ -27,41 +28,81 @@ ObjectSpace.each_object(RubyPythonBridge::RubyPyObject) do |o| o.free_pobj end assert(RubyPython.stop) end - + def test_two_imports RubyPython.start RubyPython.import "cPickle" RubyPython.import "urllib" RubyPython.stop end - + def test_propogate_python_errror RubyPython.start assert_raise PythonError do RubyPython.import "slasdfj" end RubyPython.stop end - + def test_run_method unpickled=nil RubyPython.run do cPickle=import "cPickle" cPickle.inspect unpickled=cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.") end assert_equal(unpickled,{"a"=>"n", [1, "2"]=>4}) assert(!RubyPython.stop) end - + def test_instance_method_delegation RubyPython.start wave=RubyPython.import "wave" w=wave.open("test/test.wav","rb") assert_equal(w.getframerate,9600) w.close RubyPython.stop end + + def test_pymain_delegation + RubyPython.start + assert_equal(PyMain.float(42),42.to_f) + RubyPython.stop + end + + def test_block_syntax + returned="" + RubyPython.start + returned=PyMain.float(22) do |f| + f*2 + end + assert_equal(returned,44.0) + RubyPython.stop + end + + def test_session_function + RubyPython.session do + cPickle=RubyPython.import "cPickle" + cPickle.inspect + assert_equal(cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns."),{"a"=>"n", [1, "2"]=>4}) + end + end + + + def test_setter_ary + RubyPython.session do + sys=RubyPython.import 'sys' + sys.path=[""] + assert_equal([""],sys.path) + end + end + + def test_setter_instance + RubyPython.session do + + end + end + end