Fix tests. Fix duping StringIO for writing