File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ ::RSpec . describe 'A subclass of the wrapper class of a Python class' do
4
+ let ( :subclass_test ) do
5
+ PyCall . import_module ( 'pycall.subclass_test' )
6
+ end
7
+
8
+ let ( :superclass_wrapper ) do
9
+ subclass_test . SuperClass
10
+ end
11
+
12
+ let ( :subclass ) do
13
+ Class . new ( superclass_wrapper )
14
+ end
15
+
16
+ it 'calls __init__ of superclass' do
17
+ a = subclass . new ( 1 , 2 , 3 )
18
+ expect ( a . init_args . to_a ) . to eq ( [ 1 , 2 , 3 ] )
19
+ end
20
+
21
+ it 'calls initialize' do
22
+ subclass . class_eval do
23
+ def initialize ( *args , &b )
24
+ super ( )
25
+ b . call
26
+ end
27
+ end
28
+ expect { |b | a = subclass . new ( &b ) } . to yield_control
29
+ end
30
+
31
+ it 'calls __init__ of superclass via super' do
32
+ subclass . class_eval do
33
+ def initialize
34
+ super ( 10 , 20 , 30 )
35
+ end
36
+ end
37
+ a = subclass . new
38
+ expect ( a . init_args . to_a ) . to eq ( [ 10 , 20 , 30 ] )
39
+ end
40
+
41
+ it 'calls an instance methods of the superclass' do
42
+ a = subclass . new
43
+ expect ( a . dbl ( 21 ) ) . to eq ( 42 )
44
+ expect ( subclass_test . call_dbl ( a , 30 ) ) . to eq ( 60 )
45
+ end
46
+ end
Original file line number Diff line number Diff line change
1
+ class SuperClass (object ):
2
+ def __init__ (self , * args ):
3
+ self .init_args = args
4
+
5
+ def dbl (self , x ):
6
+ return 2 * x
7
+
8
+ def call_dbl (obj , x ):
9
+ return obj .dbl (x )
You can’t perform that action at this time.
0 commit comments