rubypython 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,14 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
 
4
4
  include TestConstants
5
5
  describe RubyPython::RubyPyProxy do
6
- include RubyPythonStartStop
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 "should accept a PyObject instance" do
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 "should convert #{type} to wrapped pObject" do
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 "should faithfully unwrap #{title}" do
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 "should return 'repr' of wrapped object" do
73
+ it "returns 'repr' of wrapped object" do
67
74
  @six.inspect.should == '6'
68
75
  end
69
76
 
70
- it "should gracefully handle lack of defined __repr__" do
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 "should return 'str' of wrapped object" do
88
+ it "returns 'str' of wrapped object" do
78
89
  @six.to_s.should == '6'
79
90
  end
80
91
 
81
- it "should gracefully handle lack of defined __str__" do
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 "should convert a list to an array of its entries" do
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 "should convert a tuple to an array of its entries" do
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 "should convert a dict to an array of keys" do
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 "should return true for getters" do
119
+ it "is true for getters" do
105
120
  @objects.should respond_to(:RubyPythonMockObject)
106
121
  end
107
122
 
108
- it "should return false for undefined methods" do
123
+ it "is false for undefined methods" do
109
124
  @objects.should_not respond_to(:undefined_attr)
110
125
  end
111
126
 
112
- it "should return true for any setter" do
127
+ it "is true for any setter" do
113
128
  @objects.should respond_to(:any_variable=)
114
129
  end
115
130
 
116
- it "should return true for methods on RubyPyProxy instance" do
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 "should refer method calls to wrapped object" do
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 "should raise NoMethodError when method is undefined" do
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 "should allow methods to be called with no arguments" do
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 "should fetch attributes when method name is an attribute" do
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 "should set attribute if method call is a setter" do
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 "should create nonexistent attirubte if method call is a setter" do
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 "should return a class as a RubyPyClass" do
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 "should delegate #{op}" do
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 "should delegate #{op}" do
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 "should delegate #{op}" do
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 "be true for proxies representing the same object" do
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 "should be false for objects which are different" do
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 "should allow list indexing" do
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 "should allow dict access" do
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 "should allow list index assignment" do
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 "should allow dict value modification" do
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 "should allow creation of new dict key-val pair" do
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 "should allow membership tests with include?" do
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 "should delegate object equality" do
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
@@ -1,23 +1,30 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe RubyPython do
4
- include RubyPythonStartStop
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 "should handle multiple imports" do
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 "should propagate Python errors" do
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 "should return a RubyPyModule" do
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 "should start interpreter" do
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 "should stop the interpreter" do
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 "should start interpreter" do
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 "should stop the interpreter" do
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 'spec'
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 'spec'
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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
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-01-19 00:00:00 -05:00
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/pythonerror.rb
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/pyobject.rb
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
- - lib/rubypython/legacy.rb
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
@@ -1,2 +0,0 @@
1
- --colour
2
- --format specdoc