Sha256: 58c05bf6727456f77d62a49169bf982bb9378d43abb5ebe61cc6d09d6da04e09

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

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})
    dumped_array=cPickle.dumps([1,2,3,4])
    assert_equal(cPickle.loads(dumped_array),[1,2,3,4])
    assert_raise NoMethodError do
      cPickle.splack
    end
    assert_instance_of(RubyPythonBridge::RubyPyClass,cPickle.PicklingError)
    cPickle.free_pobj
    ObjectSpace.each_object(RubyPythonBridge::RubyPyObject) do |o|
      o.free_pobj
    end
    assert(RubyPython.stop)
  end
  
  def test_double_import
    RubyPython.start
    RubyPython.import "cPickle"
    RubyPython.import "urllib"
    RubyPython.stop
  end
  
  def test_handle_error
    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"
      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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubypython-0.2.1 test/test_rubypython.rb
rubypython-0.2.0 test/test_rubypython.rb