rubypython 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data.tar.gz.sig +0 -0
  2. data/{History.txt → History.markdown} +34 -28
  3. data/Manifest.txt +26 -40
  4. data/PostInstall.txt +2 -1
  5. data/README.markdown +103 -0
  6. data/Rakefile +19 -3
  7. data/lib/rubypython.rb +118 -114
  8. data/lib/rubypython/blankobject.rb +21 -0
  9. data/lib/rubypython/conversion.rb +198 -0
  10. data/lib/rubypython/core_ext/string.rb +7 -0
  11. data/lib/rubypython/legacy.rb +15 -0
  12. data/lib/rubypython/macros.rb +47 -0
  13. data/lib/rubypython/operators.rb +111 -0
  14. data/lib/rubypython/pymainclass.rb +51 -0
  15. data/lib/rubypython/pyobject.rb +203 -0
  16. data/lib/rubypython/python.rb +111 -0
  17. data/lib/rubypython/pythonerror.rb +78 -0
  18. data/lib/rubypython/rubypyproxy.rb +214 -0
  19. data/lib/rubypython/version.rb +4 -3
  20. data/spec/conversion_spec.rb +66 -0
  21. data/spec/legacy_spec.rb +22 -0
  22. data/spec/pymainclass_spec.rb +26 -0
  23. data/spec/pyobject_spec.rb +264 -0
  24. data/spec/python_helpers/objects.py +41 -0
  25. data/spec/pythonerror_spec.rb +43 -0
  26. data/spec/refcnt_spec.rb +68 -0
  27. data/spec/rubypyclass_spec.rb +13 -0
  28. data/spec/rubypyproxy_spec.rb +249 -0
  29. data/spec/rubypython_spec.rb +62 -0
  30. data/spec/spec.opts +2 -0
  31. data/spec/spec_helper.rb +51 -0
  32. metadata +79 -73
  33. metadata.gz.sig +0 -0
  34. data/README.txt +0 -60
  35. data/ext/rubypython_bridge/cbridge.c +0 -150
  36. data/ext/rubypython_bridge/cbridge.h +0 -15
  37. data/ext/rubypython_bridge/config.h +0 -14
  38. data/ext/rubypython_bridge/extconf.rb +0 -43
  39. data/ext/rubypython_bridge/ptor.c +0 -242
  40. data/ext/rubypython_bridge/ptor.h +0 -15
  41. data/ext/rubypython_bridge/rp_blankobject.c +0 -42
  42. data/ext/rubypython_bridge/rp_blankobject.h +0 -11
  43. data/ext/rubypython_bridge/rp_class.c +0 -56
  44. data/ext/rubypython_bridge/rp_class.h +0 -7
  45. data/ext/rubypython_bridge/rp_error.c +0 -34
  46. data/ext/rubypython_bridge/rp_error.h +0 -11
  47. data/ext/rubypython_bridge/rp_function.c +0 -31
  48. data/ext/rubypython_bridge/rp_function.h +0 -7
  49. data/ext/rubypython_bridge/rp_instance.c +0 -164
  50. data/ext/rubypython_bridge/rp_instance.h +0 -7
  51. data/ext/rubypython_bridge/rp_module.c +0 -160
  52. data/ext/rubypython_bridge/rp_module.h +0 -8
  53. data/ext/rubypython_bridge/rp_object.c +0 -194
  54. data/ext/rubypython_bridge/rp_object.h +0 -23
  55. data/ext/rubypython_bridge/rp_util.c +0 -63
  56. data/ext/rubypython_bridge/rp_util.h +0 -11
  57. data/ext/rubypython_bridge/rtop.c +0 -212
  58. data/ext/rubypython_bridge/rtop.h +0 -17
  59. data/ext/rubypython_bridge/rubypython_bridge.c +0 -125
  60. data/ext/rubypython_bridge/rubypython_bridge.h +0 -10
  61. data/lib/rubypython/session.rb +0 -4
  62. data/lib/rubypython/wrapper_extensions.rb +0 -83
  63. data/setup.rb +0 -1585
  64. data/tasks/environment.rake +0 -7
  65. data/tasks/extconf.rake +0 -13
  66. data/tasks/extconf/rubypython_bridge.rake +0 -49
  67. data/test/python_helpers/objects.py +0 -12
  68. data/test/test.wav +0 -0
  69. data/test/test_helper.rb +0 -2
  70. data/test/test_rubypython.rb +0 -215
  71. data/test/test_rubypython_bridge_extn.rb +0 -133
  72. data/test/test_session.rb +0 -6
@@ -1,7 +0,0 @@
1
- task :ruby_env do
2
- RUBY_APP = if RUBY_PLATFORM =~ /java/
3
- "jruby"
4
- else
5
- "ruby"
6
- end unless defined? RUBY_APP
7
- end
data/tasks/extconf.rake DELETED
@@ -1,13 +0,0 @@
1
- namespace :extconf do
2
- desc "Compiles the Ruby extension"
3
- task :compile
4
- end
5
-
6
- task :compile => "extconf:compile"
7
-
8
- task :test => :compile
9
-
10
- BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}"
11
- $hoe.clean_globs |= ["ext/**/#{BIN}", "lib/**/#{BIN}", 'ext/**/Makefile']
12
- $hoe.spec.require_paths = Dir['{lib,ext/*}']
13
- $hoe.spec.extensions = FileList["ext/**/extconf.rb"].to_a
@@ -1,49 +0,0 @@
1
- namespace :extconf do
2
- extension = File.basename(__FILE__, '.rake')
3
-
4
- ext = "ext/#{extension}"
5
- ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
6
- ext_files = FileList[
7
- "#{ext}/*.c",
8
- "#{ext}/*.h",
9
- "#{ext}/*.rl",
10
- "#{ext}/extconf.rb",
11
- "#{ext}/Makefile",
12
- # "lib"
13
- ]
14
-
15
-
16
- task :compile => extension do
17
- if Dir.glob("**/#{extension}.{o,so,dll}").length == 0
18
- STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
19
- STDERR.puts "Gem actually failed to build. Your system is"
20
- STDERR.puts "NOT configured properly to build #{GEM_NAME}."
21
- STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
22
- exit(1)
23
- end
24
- end
25
-
26
- desc "Builds just the #{extension} extension"
27
- task extension.to_sym => ["#{ext}/Makefile", ext_so, "lib/#{extension}.#{Config::CONFIG['DLEXT']}"]
28
-
29
- file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
30
- Dir.chdir(ext) do ruby "extconf.rb" end
31
- end
32
-
33
- file "lib/#{extension}.#{Config::CONFIG['DLEXT']}" => ext_so do
34
- require "fileutils"
35
- puts "Copying #{ext_so} into lib directory for testing."
36
- FileUtils.cp(ext_so,"lib/#{extension}.#{Config::CONFIG['DLEXT']}")
37
- end
38
-
39
- file ext_so => ext_files do
40
- Dir.chdir(ext) do
41
- sh(RUBY_PLATFORM =~ /win32/ ? 'nmake' : 'make') do |ok, res|
42
- if !ok
43
- require "fileutils"
44
- FileUtils.rm Dir.glob('*.{so,o,dll,bundle}')
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- def identity(object):
4
- return object
5
-
6
- class RubyPythonMockObject:
7
- STRING = "STRING"
8
- STRING_LIST = ["STRING1", "STRING2"]
9
- INT = 1
10
- INT_LIST = [1,1]
11
- FLOAT = 1.0
12
- FLOAT_LIST = [1.0,1.0]
data/test/test.wav DELETED
Binary file
data/test/test_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/rubypython'
@@ -1,215 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestRubypython < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
-
9
- def test_simple
10
- assert(RubyPython.start,"RubyPython failed to initialize.")
11
- assert(RubyPython.import("urllib"), "urllib library import failed.")
12
- assert(RubyPython.stop,"RubyPython failed to halt.")
13
- assert(!RubyPython.stop,"RubyPython did not realize it had halted.")
14
- end
15
-
16
- def test_delegation
17
- RubyPython.start
18
- cPickle=RubyPython.import("cPickle")
19
-
20
- assert_instance_of(RubyPythonBridge::RubyPyModule,
21
- cPickle,
22
- "Module object not returned by import.")
23
-
24
- assert_equal({"a"=>"n", [1, "2"]=>4},
25
- cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns."),
26
- "Python pickle load test returned incorrect objects.")
27
-
28
- dumped_array=cPickle.dumps([1,2,3,4])
29
-
30
- assert_equal([1,2,3,4],
31
- cPickle.loads(dumped_array),
32
- "Pickled information was not retrieved correctly.")
33
-
34
- assert_raise(NoMethodError, "Rubypython failed to raise NoMethodError on call to nonexistent method") do
35
- cPickle.splack
36
- end
37
-
38
- assert_instance_of(RubyPythonBridge::RubyPyClass,
39
- cPickle.PicklingError,
40
- "Wrapped Python class was not of type RubyPyClass.")
41
-
42
- cPickle.free_pobj
43
-
44
- ObjectSpace.each_object(RubyPythonBridge::RubyPyObject) do |o|
45
- o.free_pobj
46
- end
47
-
48
- assert(RubyPython.stop,"Interpreter did not halt correctly.")
49
- end
50
-
51
- def test_two_imports
52
- RubyPython.start
53
- assert_nothing_raised("Error raised on imports") do
54
- RubyPython.import "cPickle"
55
- RubyPython.import "urllib"
56
- end
57
- RubyPython.stop
58
- end
59
-
60
- def test_propogate_python_error
61
- RubyPython.start
62
-
63
- assert_raise(PythonError,"rubypython failed to propogate python error.") do
64
- RubyPython.import "slasdfj"
65
- end
66
-
67
- RubyPython.stop
68
- end
69
-
70
- def test_run_method
71
- unpickled=nil
72
-
73
- RubyPython.run do
74
- cPickle=import "cPickle"
75
- cPickle.inspect
76
- unpickled=cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.")
77
- end
78
-
79
- assert_equal({"a"=>"n", [1, "2"]=>4},
80
- unpickled,
81
- "Incorrect object returned from cPickle.")
82
-
83
- assert(!RubyPython.stop, "RubyPython did not seem to halt at the correct time.")
84
- end
85
-
86
- def test_instance_method_delegation
87
- RubyPython.start
88
-
89
- wave=RubyPython.import "wave"
90
- w=wave.open("test/test.wav","rb")
91
- assert_equal(9600,
92
- w.getframerate,
93
- "Wrapped wave library incorrectly passing framerate.")
94
- w.close
95
-
96
- RubyPython.stop
97
- end
98
-
99
- def test_pymain_delegation
100
- RubyPython.start
101
-
102
- assert_equal(42.to_f,
103
- PyMain.float(42),
104
- "Integer conversion problems in Python.")
105
-
106
- RubyPython.stop
107
- end
108
-
109
- def test_block_syntax
110
- returned=""
111
-
112
- RubyPython.start
113
-
114
- returned = PyMain.float(22) do |f|
115
- f*2
116
- end
117
-
118
- assert_equal(44.0,
119
- returned,
120
- "Wrapped Python object failed to correctly utilize block syntax.")
121
-
122
- RubyPython.stop
123
- end
124
-
125
- def test_session_function
126
- RubyPython.session do
127
-
128
- cPickle=RubyPython.import "cPickle"
129
-
130
- cPickle.inspect
131
-
132
- assert_equal({"a"=>"n", [1, "2"]=>4},
133
- cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns."),
134
- "cPickle misbehaved in session block.")
135
- end
136
- end
137
-
138
-
139
- def test_setter_ary
140
- RubyPython.session do
141
-
142
- sys=RubyPython.import 'sys'
143
-
144
- sys.path=[".",".."]
145
-
146
- assert_equal([".",".."],
147
- sys.path,
148
- "Ruby failed to modify Python object as expected.")
149
- end
150
- end
151
-
152
- def test_setter_instance
153
- RubyPython.session do
154
- urllib2=RubyPython.import "urllib2"
155
- req=urllib2.Request("google.com")
156
- req.headers={:a=>"2","k"=>4}
157
- assert_equal({"a"=>"2","k"=>4},
158
- req.headers,
159
- "Python dictionary not set as expected.")
160
- end
161
- end
162
-
163
- def test_set_twice
164
- RubyPython.session do
165
- sys = RubyPython.import 'sys'
166
-
167
- sys.path = ['.']
168
-
169
- sys.path = ['..']
170
-
171
- assert_equal(['..'],
172
- sys.path,
173
- "Ruby failed to modify Python object as expected.")
174
-
175
- end
176
- end
177
-
178
- end
179
-
180
- class TestWithCustomObject < Test::Unit::TestCase
181
- def setup
182
- RubyPython.start
183
- sys = RubyPython.import 'sys'
184
- sys.path = ['./test/python_helpers']
185
- @objects = RubyPython.import 'objects'
186
- end
187
-
188
- def teardown
189
- RubyPython.stop
190
- end
191
-
192
- def test_string_access
193
- assert_equal("STRING",
194
- @objects.RubyPythonMockObject.STRING,
195
- "String class members not being converted correctly.")
196
- rbString = @objects.RubyPythonMockObject.STRING
197
- end
198
-
199
- def test_string_ary_access
200
- assert_equal(["STRING1", "STRING2"],
201
- @objects.RubyPythonMockObject.STRING_LIST,
202
- "List of strings class member not being converted correctly.")
203
- rbStringList = @objects.RubyPythonMockObject.STRING_LIST
204
- end
205
-
206
- def test_string_ary_modify
207
- rbStringList = @objects.RubyPythonMockObject.STRING_LIST
208
- rbStringList.push"NEW_STRING"
209
- @objects.RubyPythonMockObject.STRING_LIST = rbStringList
210
- assert_equal("NEW_STRING",
211
- @objects.RubyPythonMockObject.STRING_LIST[2],
212
- "Failed to add object to list.")
213
- end
214
- end
215
-
@@ -1,133 +0,0 @@
1
- require "test/unit"
2
-
3
- $:.unshift File.dirname(__FILE__) + "/../ext/rubypython_bridge"
4
- require "rubypython_bridge.so"
5
-
6
- class TestRubyPythonBridgeExtn < Test::Unit::TestCase
7
-
8
- def test_func_with_module
9
- pickle_return = RubyPythonBridge.func("cPickle",
10
- "loads", "(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.")
11
-
12
- assert_equal({"a"=>"n", [1, "2"]=>4},pickle_return)
13
- end
14
-
15
- def test_start_stop
16
- assert(RubyPythonBridge.start, "Embedded python interpreter failed to start correctly.")
17
-
18
- assert(!RubyPythonBridge.start, "Interpreter attempted to start while running.")
19
-
20
- assert(RubyPythonBridge.stop, "Interpreter failed to halt.")
21
-
22
- assert(!RubyPythonBridge.stop, "Interpreter ran into trouble while halting.")
23
- end
24
-
25
- def test_new_instance
26
- RubyPythonBridge.start
27
-
28
- urllib2 = RubyPythonBridge.import "urllib2"
29
-
30
- assert_instance_of(RubyPythonBridge::RubyPyClass,
31
- urllib2.Request,
32
- "Wrapped Python class not of correct type.")
33
-
34
- assert_instance_of(RubyPythonBridge::RubyPyInstance,
35
- urllib2.Request("google.com"),
36
- "Wrapped python instance not of correct type.")
37
-
38
- RubyPythonBridge.stop
39
- end
40
-
41
- def test_new_instance_with_new_method
42
- RubyPythonBridge.start
43
-
44
- urllib2=RubyPythonBridge.import "urllib2"
45
-
46
- assert_instance_of(RubyPythonBridge::RubyPyClass,
47
- urllib2.Request,
48
- "Wrapped Python class not of correct type.")
49
-
50
- assert_instance_of(RubyPythonBridge::RubyPyInstance,
51
- urllib2.Request.new("google.com"),
52
- "New call misbehaving of wrapped class.")
53
-
54
- RubyPythonBridge.stop
55
- end
56
-
57
- end
58
-
59
- class TestRubyPythonBridgeWithCPickle < Test::Unit::TestCase
60
- def setup
61
- RubyPythonBridge.start
62
- @cPickle=RubyPythonBridge.import "cPickle"
63
- end
64
-
65
- def teardown
66
- ObjectSpace.each_object(RubyPythonBridge::RubyPyObject) do |o|
67
- o.free_pobj
68
- end
69
- RubyPythonBridge.stop
70
- end
71
-
72
- def test_mod_respond_to
73
- assert(@cPickle.respond_to?(:loads),
74
- "Ruby respond to method not working on wrapped module.")
75
- end
76
-
77
- def test_data_passing
78
- assert_equal({"a"=>"n", [1, "2"]=>4},
79
- @cPickle.loads( "(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns."),
80
- "Data returned from wrapped cPickle is incorrect." )
81
-
82
- orig_array = [1,2,3,4]
83
- dumped_array = @cPickle.dumps(orig_array)
84
-
85
- assert_equal(orig_array,
86
- @cPickle.loads(dumped_array),
87
- "Array returned from cPickle is not equivalent to input array.")
88
- end
89
-
90
- def test_unknown_method
91
- assert_raise(NoMethodError, "Missing method failed to raise NoMethodError") do
92
- @cPickle.splack
93
- end
94
- end
95
-
96
- def test_class_wrapping
97
- assert_instance_of(RubyPythonBridge::RubyPyClass,
98
- @cPickle.PicklingError,
99
- "Wrapped class is not an instance of RubyPyClass.")
100
- end
101
-
102
- def test_module_wrapping
103
- assert_instance_of(RubyPythonBridge::RubyPyModule,
104
- @cPickle,
105
- "Wrapped module is not of class RubyPyModule.")
106
- end
107
-
108
- end
109
-
110
-
111
- class TestRubyPythonBridgeWithUrllib2 < Test::Unit::TestCase
112
- def setup
113
- RubyPythonBridge.start
114
- @urllib2=RubyPythonBridge.import "urllib2"
115
- end
116
-
117
- def teardown
118
- ObjectSpace.each_object(RubyPythonBridge::RubyPyObject) do |o|
119
- o.free_pobj
120
- end
121
- RubyPythonBridge.stop
122
- end
123
-
124
- def test_class_respond_to
125
- assert(@urllib2.Request.respond_to? :get_data)
126
- end
127
-
128
- def test_instance_respond_to
129
- assert(@urllib2.Request.new("google.com").respond_to? :get_data)
130
- end
131
-
132
- end
133
-
data/test/test_session.rb DELETED
@@ -1,6 +0,0 @@
1
- class TestSessionImport < Test::Unit::TestCase
2
- def test_session
3
- require 'rubypython/session'
4
- assert(RubyPython.import("cPickle"), "Import failed during session test.")
5
- end
6
- end