Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions trunk/test/rpy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@
require 'test/unit'
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'rpy'

main()
class TestPython < Test::Unit::TestCase

def test_python_no_return
Py.start # starts the python interperter

output = "hello world"

Py.run( %Q(print "#{output}"), {} )

Py.stop # stops the interperter
end

def test_python_yaml_return
Py.start

result = YAML.load( Py.run( %Q(_rpython_result = {'hello':1,'world':2}), :serialize => 'yaml') )

assert_equal 1, result['hello']
assert_equal 2, result['world']

Py.stop
end


def test_benchmark
Py.start

py_result = ""
iterations = 100
real_times = []

iterations.times do
timer = Time.now
py_result = Py.run( %Q(_rpython_result = {'hello':1,'world':2}), :serialize => 'yaml')
Expand All @@ -50,17 +38,13 @@ def test_benchmark
variance = variance + delta * (time - average)
total += time
end

variance /= n

puts "total: #{total} seconds, average: #{average} seconds, variance: #{variance} seconds"

result = YAML.load( py_result )
assert_equal 1, result['hello']
assert_equal 2, result['world']


Py.stop
end

end
if __name__== '__main__':
main()