Skip to content

Commit

Permalink
Add a non-regression test for issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 16, 2013
1 parent 657001d commit 42f3fd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cairocffi/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def _make_read_func(file_obj):
"""Return a CFFI callback that reads from a file-like object."""
@ffi.callback("cairo_read_func_t", error=constants.STATUS_READ_ERROR)
def read_func(closure, data, length):
def read_func(_closure, data, length):
string = file_obj.read(length)
if len(string) < length: # EOF too early
return constants.STATUS_READ_ERROR
Expand All @@ -40,10 +40,10 @@ def _make_write_func(file_obj):
return ffi.NULL

@ffi.callback("cairo_write_func_t", error=constants.STATUS_WRITE_ERROR)
def read_func(_closure, data, length):
def write_func(_closure, data, length):
file_obj.write(ffi.buffer(data, length))
return constants.STATUS_SUCCESS
return read_func
return write_func


def _encode_filename(filename):
Expand Down
19 changes: 19 additions & 0 deletions cairocffi/test_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,25 @@ def test_surface():
assert_raise_finished(surface.set_fallback_resolution, 3, 4)


def test_target_lifetime():
# Test our work around for
# Related CFFI bug: https://bitbucket.org/cffi/cffi/issue/92/
if not hasattr(sys, 'getrefcount'):
pytest.xfail() # PyPy
gc.collect() # Clean up stuff from other tests
target = io.BytesIO()
initial_refcount = sys.getrefcount(target)
assert len(cairocffi.surfaces.KeepAlive.instances) == 0
surface = PDFSurface(target, 100, 100)
# The target is in a KeepAlive object
assert len(cairocffi.surfaces.KeepAlive.instances) == 1
assert sys.getrefcount(target) == initial_refcount + 1
del surface
gc.collect() # Make sure surface is collected
assert len(cairocffi.surfaces.KeepAlive.instances) == 0
assert sys.getrefcount(target) == initial_refcount


def test_mime_data():
if cairo_version() < 11000:
pytest.xfail()
Expand Down

0 comments on commit 42f3fd5

Please sign in to comment.