Sha256: 79bbfabb705199323cf4743b45ccde32f2cdc15f18ac279e9dbeef7d9b612f80

Contents?: true

Size: 1.57 KB

Versions: 99

Compression:

Stored size: 1.57 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
require 'rbbt/util/python'

class TestPython < Test::Unit::TestCase
  def test_python
    TmpFile.with_file do |tmpdir|
      code =<<-EOF
def python_test(a, b):
	c = a + b
	return c
      EOF
      Open.write(File.join(tmpdir, 'file1.py'), code)
      Open.write(File.join(tmpdir, 'file2.py'), code)
      Open.write(File.join(tmpdir, 'file3.py'), code)
      Open.write(File.join(tmpdir, 'file4.py'), code)
      RbbtPython.add_path tmpdir

      res = nil

      RbbtPython.run 'file2', :python_test do 
        res = python_test(1, 3)
      end
      assert_equal 4, res

      RbbtPython.run do
        pyfrom :file3, :import => :python_test
        res = python_test(1, 4)
      end
      assert_equal 5, res

      RbbtPython.run do
        pyimport :file4
        res = file4.python_test(1, 4)
      end
      assert_equal 5, res

      RbbtPython.run 'file1' do 
        res = file1.python_test(1, 2)
      end
      assert_equal 3, res
    end
  end

  def test_run_log
    Log.severity = 0
    TmpFile.with_file do |tmpdir|
      code =<<-EOF
import sys
def python_print():
	print("Test STDERR", file=sys.stderr)
	print("Test STDOUT")
      EOF
      Open.write(File.join(tmpdir, 'file_print.py'), code)
      RbbtPython.add_path tmpdir

      RbbtPython.run_log 'file_print' do 
        file_print.python_print
      end
      RbbtPython.run_log_stderr 'file_print' do 
        file_print.python_print
      end

      RbbtPython.run_log 'file_print' do 
        file_print.python_print
      end
    end
  end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
rbbt-util-5.28.9 test/rbbt/util/test_python.rb
rbbt-util-5.28.8 test/rbbt/util/test_python.rb
rbbt-util-5.28.7 test/rbbt/util/test_python.rb
rbbt-util-5.28.6 test/rbbt/util/test_python.rb
rbbt-util-5.28.5 test/rbbt/util/test_python.rb
rbbt-util-5.28.4 test/rbbt/util/test_python.rb
rbbt-util-5.28.2 test/rbbt/util/test_python.rb
rbbt-util-5.28.1 test/rbbt/util/test_python.rb
rbbt-util-5.28.0 test/rbbt/util/test_python.rb
rbbt-util-5.27.13 test/rbbt/util/test_python.rb
rbbt-util-5.27.12 test/rbbt/util/test_python.rb
rbbt-util-5.27.11 test/rbbt/util/test_python.rb
rbbt-util-5.27.10 test/rbbt/util/test_python.rb
rbbt-util-5.27.9 test/rbbt/util/test_python.rb
rbbt-util-5.27.8 test/rbbt/util/test_python.rb
rbbt-util-5.27.7 test/rbbt/util/test_python.rb
rbbt-util-5.27.6 test/rbbt/util/test_python.rb
rbbt-util-5.27.5 test/rbbt/util/test_python.rb
rbbt-util-5.27.4 test/rbbt/util/test_python.rb
rbbt-util-5.27.3 test/rbbt/util/test_python.rb