Fix test failure under Python 3

In Python 3 r.write() returns the number of characters written.