Fix fileno method. Fixed test code too.