spec/refcnt_spec.rb in rubypython-0.6.2 vs spec/refcnt_spec.rb in rubypython-0.6.3

- old
+ new

@@ -6,12 +6,11 @@ if pobject.kind_of? RubyPython::RubyPyProxy pobject = pobject.pObject.pointer elsif pobject.kind_of? RubyPython::PyObject pobject = pobject.pointer end - struct = RubyPython::Python::PyObjectStruct.new pobject - struct[:ob_refcnt] + RubyPython::Macros.Py_REFCNT pobject end include TestConstants describe 'Reference Counting' do @@ -54,9 +53,46 @@ pyObj.pObject.xIncref refcnt = get_refcnt(pyObj) pointer = pyObj.pObject.pointer pyObj.pObject.xDecref get_refcnt(pointer).should == refcnt - 1 + end + end + end + + describe RubyPython::Conversion do + describe ".rtopArrayToList" do + it "should incref any wrapped objects in the array" do + int = RubyPython::PyObject.new AnInt + refcnt = get_refcnt(int) + arr = [int] + pyArr = subject.rtopArrayToList(arr) + get_refcnt(int).should == refcnt + 1 + end + + end + + describe ".rtopObject" do + [ + ["string", AString], + ["float", AFloat], + ["array", AnArray], + #["symbol", ASym], + ["hash", AHash] + ].each do |arr| + type, input = arr + + it "should return a refcnt of 1 for newly created #{type}" do + pyObj = subject.rtopObject(input) + get_refcnt(pyObj).should == 1 + end + + it "should increment the refcnt each time the same #{type} is passed in" do + pyObj = RubyPython::PyObject.new subject.rtopObject(input) + refcnt = get_refcnt(pyObj) + pyObj2 = subject.rtopObject(pyObj) + get_refcnt(pyObj2).should == refcnt + 1 + end end end end end