rubypython 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/History.markdown +5 -0
- data/License.txt +2 -2
- data/Manifest.txt +13 -8
- data/README.markdown +5 -3
- data/Rakefile +7 -5
- data/lib/rubypython/conversion.rb +18 -1
- data/lib/rubypython/legacy.rb +25 -0
- data/lib/rubypython/operators.rb +7 -0
- data/lib/rubypython/options.rb +69 -0
- data/lib/rubypython/pymainclass.rb +13 -2
- data/lib/rubypython/pyobject.rb +17 -5
- data/lib/rubypython/python.rb +176 -153
- data/lib/rubypython/rubypyproxy.rb +60 -14
- data/lib/rubypython/version.rb +1 -1
- data/lib/rubypython.rb +51 -5
- data/spec/callback_spec.rb +63 -0
- data/spec/conversion_spec.rb +17 -9
- data/spec/legacy_spec.rb +41 -2
- data/spec/pymainclass_spec.rb +12 -5
- data/spec/pyobject_spec.rb +44 -37
- data/spec/python_helpers/objects.py +3 -0
- data/spec/python_helpers/objects.pyc +0 -0
- data/spec/pythonerror_spec.rb +13 -6
- data/spec/refcnt_spec.rb +4 -4
- data/spec/rubypyclass_spec.rb +9 -2
- data/spec/rubypyproxy_spec.rb +55 -34
- data/spec/rubypython_spec.rb +41 -8
- data/spec/spec_helper.rb +11 -13
- data.tar.gz.sig +0 -0
- metadata +30 -12
- metadata.gz.sig +0 -0
- data/spec/spec.opts +0 -2
data/spec/rubypyproxy_spec.rb
CHANGED
@@ -3,7 +3,14 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
3
3
|
|
4
4
|
include TestConstants
|
5
5
|
describe RubyPython::RubyPyProxy do
|
6
|
-
|
6
|
+
|
7
|
+
before do
|
8
|
+
RubyPython.start
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
RubyPython.start
|
13
|
+
end
|
7
14
|
|
8
15
|
before do
|
9
16
|
@a = RubyPython::PyObject.new "a"
|
@@ -20,7 +27,7 @@ describe RubyPython::RubyPyProxy do
|
|
20
27
|
end
|
21
28
|
|
22
29
|
describe "#new" do
|
23
|
-
it "
|
30
|
+
it "accepts a PyObject instance" do
|
24
31
|
rbPyObject = RubyPython::PyObject.new AString
|
25
32
|
lambda {described_class.new rbPyObject}.should_not raise_exception
|
26
33
|
end
|
@@ -37,7 +44,7 @@ describe RubyPython::RubyPyProxy do
|
|
37
44
|
type, input, output = arr
|
38
45
|
output ||= input
|
39
46
|
|
40
|
-
it "
|
47
|
+
it "converts #{type} to wrapped pObject" do
|
41
48
|
described_class.new(input).pObject.rubify.should == output
|
42
49
|
end
|
43
50
|
|
@@ -53,7 +60,7 @@ describe RubyPython::RubyPyProxy do
|
|
53
60
|
["a symbol", ASym],
|
54
61
|
["a hash", AHash]
|
55
62
|
].each do |title, obj|
|
56
|
-
it "
|
63
|
+
it "faithfully unwraps #{title}" do
|
57
64
|
pyObject = RubyPython::PyObject.new obj
|
58
65
|
proxy = described_class.new pyObject
|
59
66
|
proxy.rubify.should == pyObject.rubify
|
@@ -63,57 +70,65 @@ describe RubyPython::RubyPyProxy do
|
|
63
70
|
|
64
71
|
describe "#inspect" do
|
65
72
|
|
66
|
-
it "
|
73
|
+
it "returns 'repr' of wrapped object" do
|
67
74
|
@six.inspect.should == '6'
|
68
75
|
end
|
69
76
|
|
70
|
-
it "
|
77
|
+
it "gracefully handles lack of defined __repr__" do
|
71
78
|
lambda { @objects.RubyPythonMockObject.inspect }.should_not raise_exception
|
72
79
|
end
|
73
80
|
|
81
|
+
it "always tries the 'repr' function if __repr__ produces an error" do
|
82
|
+
RubyPython::PyMain.list.inspect.should == run_python_command('print repr(list)').chomp
|
83
|
+
end
|
84
|
+
|
74
85
|
end
|
75
86
|
|
76
87
|
describe "#to_s" do
|
77
|
-
it "
|
88
|
+
it "returns 'str' of wrapped object" do
|
78
89
|
@six.to_s.should == '6'
|
79
90
|
end
|
80
91
|
|
81
|
-
it "
|
92
|
+
it "gracefully handles lack of defined __str__" do
|
82
93
|
lambda { @objects.RubyPythonMockObject.to_s }.should_not raise_exception
|
83
94
|
end
|
95
|
+
|
96
|
+
it "always tries the 'str' function if __repr__ produces an error" do
|
97
|
+
RubyPython::PyMain.list.to_s.should == run_python_command('print str(list)').chomp
|
98
|
+
end
|
84
99
|
end
|
85
100
|
|
86
101
|
describe "#to_a" do
|
87
|
-
it "
|
102
|
+
it "converts a list to an array of its entries" do
|
88
103
|
list = @objects.a_list
|
89
104
|
list.to_a.should == AnArray.map { |x| described_class.new(x) }
|
90
105
|
end
|
91
106
|
|
92
|
-
it "
|
107
|
+
it "converts a tuple to an array of its entries" do
|
93
108
|
tuple = @objects.a_tuple
|
94
109
|
tuple.to_a.should == AnArray.map { |x| described_class.new(x) }
|
95
110
|
end
|
96
111
|
|
97
|
-
it "
|
112
|
+
it "converts a dict to an array of keys" do
|
98
113
|
dict = @objects.a_dict
|
99
114
|
dict.to_a.sort.should == AConvertedHash.keys.map {|x| described_class.new(x)}.sort
|
100
115
|
end
|
101
116
|
end
|
102
117
|
|
103
118
|
describe "#respond_to?" do
|
104
|
-
it "
|
119
|
+
it "is true for getters" do
|
105
120
|
@objects.should respond_to(:RubyPythonMockObject)
|
106
121
|
end
|
107
122
|
|
108
|
-
it "
|
123
|
+
it "is false for undefined methods" do
|
109
124
|
@objects.should_not respond_to(:undefined_attr)
|
110
125
|
end
|
111
126
|
|
112
|
-
it "
|
127
|
+
it "is true for any setter" do
|
113
128
|
@objects.should respond_to(:any_variable=)
|
114
129
|
end
|
115
130
|
|
116
|
-
it "
|
131
|
+
it "is true for methods on RubyPyProxy instance" do
|
117
132
|
@objects.should respond_to(:inspect)
|
118
133
|
end
|
119
134
|
|
@@ -121,45 +136,51 @@ describe RubyPython::RubyPyProxy do
|
|
121
136
|
|
122
137
|
describe "method delegation" do
|
123
138
|
|
124
|
-
it "
|
139
|
+
it "refers method calls to wrapped object" do
|
125
140
|
aProxy = described_class.new(@a)
|
126
141
|
bProxy = described_class.new(@b)
|
127
142
|
aProxy.__add__(bProxy).rubify.should == (@a.rubify + @b.rubify)
|
128
143
|
end
|
129
144
|
|
130
|
-
it "
|
145
|
+
it "raises NoMethodError when method is undefined" do
|
131
146
|
aProxy = described_class.new @a
|
132
147
|
lambda {aProxy.wat}.should raise_exception(NoMethodError)
|
133
148
|
end
|
134
149
|
|
135
|
-
it "
|
150
|
+
it "raises NoMethodError when boolean method is undefine" do
|
151
|
+
aProxy = described_class.new @a
|
152
|
+
lambda { aProxy.wat? }.should raise_exception(NoMethodError)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "allows methods to be called with no arguments" do
|
136
156
|
builtinProxy = described_class.new @builtin
|
137
157
|
rbStrClass = builtinProxy.str
|
138
158
|
rbStrClass.new.rubify.should == String.new
|
139
159
|
end
|
140
160
|
|
141
|
-
it "
|
161
|
+
it "fetchs attributes when method name is an attribute" do
|
142
162
|
pyLetters = @string.getAttr "ascii_letters"
|
143
163
|
stringProxy = described_class.new @string
|
144
164
|
stringProxy.ascii_letters.rubify.should == pyLetters.rubify
|
145
165
|
end
|
146
166
|
|
147
|
-
it "
|
167
|
+
it "sets attribute if method call is a setter" do
|
148
168
|
stringProxy = described_class.new @string
|
149
169
|
stringProxy.letters = AString
|
150
170
|
stringProxy.letters.rubify.should == AString
|
151
171
|
end
|
152
172
|
|
153
|
-
it "
|
173
|
+
it "creates nonexistent attirubte if method call is a setter" do
|
154
174
|
stringProxy = described_class.new @string
|
155
175
|
stringProxy.nonExistent = 1
|
156
176
|
stringProxy.nonExistent.rubify.should == 1
|
157
177
|
end
|
158
178
|
|
159
|
-
it "
|
179
|
+
it "returns a class as a RubyPyClass" do
|
160
180
|
urllib2 = RubyPython.import('urllib2')
|
161
181
|
urllib2.Request.should be_a(RubyPython::RubyPyClass)
|
162
182
|
end
|
183
|
+
|
163
184
|
end
|
164
185
|
|
165
186
|
describe "when used with an operator" do
|
@@ -168,7 +189,7 @@ describe RubyPython::RubyPyProxy do
|
|
168
189
|
'+', '-', '/', '*', '&', '^', '%', '**',
|
169
190
|
'>>', '<<', '<=>', '|'
|
170
191
|
].each do |op|
|
171
|
-
it "
|
192
|
+
it "delegates #{op}" do
|
172
193
|
@six.__send__(op, @two).rubify.should == 6.__send__(op, 2)
|
173
194
|
end
|
174
195
|
end
|
@@ -176,49 +197,49 @@ describe RubyPython::RubyPyProxy do
|
|
176
197
|
[
|
177
198
|
'~', '-@', '+@'
|
178
199
|
].each do |op|
|
179
|
-
it "
|
200
|
+
it "delegates #{op}" do
|
180
201
|
@six.__send__(op).rubify.should == 6.__send__(op)
|
181
202
|
end
|
182
203
|
end
|
183
204
|
|
184
205
|
['==', '<', '>', '<=', '>='].each do |op|
|
185
|
-
it "
|
206
|
+
it "delegates #{op}" do
|
186
207
|
@six.__send__(op, @two).should == 6.__send__(op, 2)
|
187
208
|
end
|
188
209
|
end
|
189
210
|
|
190
211
|
describe "#equal?" do
|
191
|
-
it "
|
212
|
+
it "is true for proxies representing the same object" do
|
192
213
|
obj1 = @objects.RubyPythonMockObject
|
193
214
|
obj2 = @objects.RubyPythonMockObject
|
194
215
|
obj1.should equal(obj2)
|
195
216
|
end
|
196
217
|
|
197
|
-
it "
|
218
|
+
it "is false for objects which are different" do
|
198
219
|
@two.should_not equal(@six)
|
199
220
|
end
|
200
221
|
|
201
222
|
end
|
202
223
|
|
203
|
-
it "
|
224
|
+
it "allows list indexing" do
|
204
225
|
array = described_class.new(AnArray)
|
205
226
|
array[1].rubify.should == AnArray[1]
|
206
227
|
end
|
207
228
|
|
208
|
-
it "
|
229
|
+
it "allows dict access" do
|
209
230
|
dict = described_class.new(AHash)
|
210
231
|
key = AConvertedHash.keys[0]
|
211
232
|
dict[key].rubify.should == AConvertedHash[key]
|
212
233
|
end
|
213
234
|
|
214
|
-
it "
|
235
|
+
it "allows list index assignment" do
|
215
236
|
array = described_class.new(AnArray)
|
216
237
|
val = AString*2
|
217
238
|
array[1] = val
|
218
239
|
array[1].rubify.should == val
|
219
240
|
end
|
220
241
|
|
221
|
-
it "
|
242
|
+
it "allows dict value modification" do
|
222
243
|
dict = described_class.new(AHash)
|
223
244
|
key = AConvertedHash.keys[0]
|
224
245
|
val = AString*2
|
@@ -226,21 +247,21 @@ describe RubyPython::RubyPyProxy do
|
|
226
247
|
dict[key].rubify.should == val
|
227
248
|
end
|
228
249
|
|
229
|
-
it "
|
250
|
+
it "allows creation of new dict key-val pair" do
|
230
251
|
dict = described_class.new(AHash)
|
231
252
|
key = AString*2
|
232
253
|
dict[key] = AString
|
233
254
|
dict[key].rubify.should == AString
|
234
255
|
end
|
235
256
|
|
236
|
-
it "
|
257
|
+
it "allows membership tests with include?" do
|
237
258
|
list = described_class.new(AnArray)
|
238
259
|
list.include?(AnArray[0]).should be_true
|
239
260
|
end
|
240
261
|
end
|
241
262
|
|
242
263
|
|
243
|
-
it "
|
264
|
+
it "delegates object equality" do
|
244
265
|
urllib_a = RubyPython.import('urllib')
|
245
266
|
urllib_b = RubyPython.import('urllib')
|
246
267
|
urllib_a.should == urllib_b
|
data/spec/rubypython_spec.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe RubyPython do
|
4
|
-
|
4
|
+
|
5
|
+
before do
|
6
|
+
RubyPython.start
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
RubyPython.start
|
11
|
+
end
|
5
12
|
|
6
13
|
describe "#import" do
|
7
|
-
it "
|
14
|
+
it "handles multiple imports" do
|
8
15
|
lambda do
|
9
16
|
RubyPython.import 'cPickle'
|
10
17
|
RubyPython.import 'urllib'
|
11
18
|
end.should_not raise_exception
|
12
19
|
end
|
13
20
|
|
14
|
-
it "
|
21
|
+
it "propagates Python errors" do
|
15
22
|
lambda do
|
16
23
|
RubyPython.import 'nonExistentModule'
|
17
24
|
end.should raise_exception(RubyPython::PythonError)
|
18
25
|
end
|
19
26
|
|
20
|
-
it "
|
27
|
+
it "returns a RubyPyModule" do
|
21
28
|
RubyPython.import('urllib2').should be_a(RubyPython::RubyPyModule)
|
22
29
|
end
|
23
30
|
end
|
@@ -26,14 +33,14 @@ end
|
|
26
33
|
|
27
34
|
describe RubyPython, "#session" do
|
28
35
|
|
29
|
-
it "
|
36
|
+
it "starts interpreter" do
|
30
37
|
RubyPython.session do
|
31
38
|
cPickle = RubyPython.import "cPickle"
|
32
39
|
cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.").rubify.should == {"a"=>"n", [1, "2"]=>4}
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
36
|
-
it "
|
43
|
+
it "stops the interpreter" do
|
37
44
|
RubyPython.session do
|
38
45
|
cPickle = RubyPython.import "cPickle"
|
39
46
|
end
|
@@ -44,14 +51,14 @@ end
|
|
44
51
|
|
45
52
|
describe RubyPython, "#run" do
|
46
53
|
|
47
|
-
it "
|
54
|
+
it "starts interpreter" do
|
48
55
|
RubyPython.run do
|
49
56
|
cPickle = import "cPickle"
|
50
57
|
cPickle.loads("(dp1\nS'a'\nS'n'\ns(I1\nS'2'\ntp2\nI4\ns.").rubify.should == {"a"=>"n", [1, "2"]=>4}
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
|
-
it "
|
61
|
+
it "stops the interpreter" do
|
55
62
|
RubyPython.run do
|
56
63
|
cPickle = import "cPickle"
|
57
64
|
end
|
@@ -60,3 +67,29 @@ describe RubyPython, "#run" do
|
|
60
67
|
end
|
61
68
|
|
62
69
|
end
|
70
|
+
|
71
|
+
describe RubyPython, '#reload_library', :slow => true do
|
72
|
+
it 'leaves RubyPython in a stable state' do
|
73
|
+
lambda do
|
74
|
+
RubyPython.instance_eval { reload_library }
|
75
|
+
RubyPython.run {}
|
76
|
+
end.should_not raise_exception
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe RubyPython, '.configure', :slow => true do
|
82
|
+
it 'allows python executable to be specified', :unless => `which python2.6`.empty? do
|
83
|
+
RubyPython.configure :python_exe => 'python2.6'
|
84
|
+
RubyPython.run do
|
85
|
+
sys = RubyPython.import 'sys'
|
86
|
+
sys.version.rubify.to_f.should == 2.6
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
after(:all) do
|
92
|
+
RubyPython.clear_options
|
93
|
+
RubyPython.instance_eval { reload_library }
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'rspec'
|
3
3
|
require 'ffi'
|
4
4
|
rescue LoadError
|
5
5
|
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
6
6
|
gem 'rspec'
|
7
|
-
require '
|
7
|
+
require 'rspec'
|
8
8
|
require 'ffi'
|
9
9
|
end
|
10
10
|
|
@@ -29,6 +29,15 @@ module TestConstants
|
|
29
29
|
key = k.is_a?(Symbol)? k.to_s : k
|
30
30
|
[key,v]
|
31
31
|
end.flatten]
|
32
|
+
|
33
|
+
AProc = Proc.new { |a1, a2| a1 + a2 }
|
34
|
+
|
35
|
+
def self.a_method(a1, a2)
|
36
|
+
a1 + a2
|
37
|
+
end
|
38
|
+
|
39
|
+
AMethod = method(:a_method)
|
40
|
+
|
32
41
|
end
|
33
42
|
|
34
43
|
def run_python_command(cmd)
|
@@ -38,14 +47,3 @@ end
|
|
38
47
|
class RubyPython::RubyPyProxy
|
39
48
|
[:should, :should_not, :class].each { |m| reveal(m) }
|
40
49
|
end
|
41
|
-
|
42
|
-
share_as :RubyPythonStartStop do
|
43
|
-
before do
|
44
|
-
RubyPython.start
|
45
|
-
end
|
46
|
-
|
47
|
-
after do
|
48
|
-
RubyPython.stop
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubypython
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zach Raines
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
cguJMiQCSOlUPZxCWWMkjfZbXvtS5VdzJevSqQ==
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2011-
|
39
|
+
date: 2011-02-02 00:00:00 -05:00
|
40
40
|
default_executable:
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
@@ -72,6 +72,21 @@ dependencies:
|
|
72
72
|
version: 2.1.2.3
|
73
73
|
type: :runtime
|
74
74
|
version_requirements: *id002
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 2
|
86
|
+
- 0
|
87
|
+
version: "2.0"
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id003
|
75
90
|
description: A bridge between ruby and python
|
76
91
|
email:
|
77
92
|
- raineszm+rubypython@gmail.com
|
@@ -91,30 +106,33 @@ files:
|
|
91
106
|
- PostInstall.txt
|
92
107
|
- README.markdown
|
93
108
|
- Rakefile
|
109
|
+
- .rspec
|
94
110
|
- lib/rubypython.rb
|
95
111
|
- lib/rubypython/blankobject.rb
|
112
|
+
- lib/rubypython/conversion.rb
|
96
113
|
- lib/rubypython/core_ext/string.rb
|
97
|
-
- lib/rubypython/
|
114
|
+
- lib/rubypython/legacy.rb
|
98
115
|
- lib/rubypython/macros.rb
|
99
|
-
- lib/rubypython/conversion.rb
|
100
116
|
- lib/rubypython/operators.rb
|
101
|
-
- lib/rubypython/
|
117
|
+
- lib/rubypython/options.rb
|
102
118
|
- lib/rubypython/pymainclass.rb
|
119
|
+
- lib/rubypython/pyobject.rb
|
103
120
|
- lib/rubypython/python.rb
|
121
|
+
- lib/rubypython/pythonerror.rb
|
104
122
|
- lib/rubypython/rubypyproxy.rb
|
105
123
|
- lib/rubypython/version.rb
|
106
|
-
-
|
124
|
+
- spec/callback_spec.rb
|
125
|
+
- spec/conversion_spec.rb
|
126
|
+
- spec/legacy_spec.rb
|
107
127
|
- spec/pymainclass_spec.rb
|
108
128
|
- spec/pyobject_spec.rb
|
109
129
|
- spec/python_helpers/objects.py
|
130
|
+
- spec/python_helpers/objects.pyc
|
110
131
|
- spec/pythonerror_spec.rb
|
132
|
+
- spec/refcnt_spec.rb
|
111
133
|
- spec/rubypyclass_spec.rb
|
112
134
|
- spec/rubypyproxy_spec.rb
|
113
135
|
- spec/rubypython_spec.rb
|
114
|
-
- spec/refcnt_spec.rb
|
115
|
-
- spec/conversion_spec.rb
|
116
|
-
- spec/legacy_spec.rb
|
117
|
-
- spec/spec.opts
|
118
136
|
- spec/spec_helper.rb
|
119
137
|
has_rdoc: yard
|
120
138
|
homepage: http://bitbucket.org/raineszm/rubypython/
|
metadata.gz.sig
CHANGED
Binary file
|
data/spec/spec.opts
DELETED