Created
October 30, 2012 00:50
-
-
Save igorsobreira/3977650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assert_file_like_object(self, obj): | |
interface = set(('open', 'close', 'encoding', 'fileno', 'flush', 'isatty', | |
'newlines', 'read', 'readinto', 'readline', 'readlines', | |
'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', | |
'xreadlines', 'name')) | |
methods = set(dir(obj)) | |
has_valid_api = interface.issubset(methods) | |
missing_methods = ', '.join(interface.difference(methods)) | |
self.assertTrue(has_valid_api, | |
"{0} should be file-like object. Missing methods/attributes: {1}" | |
.format(obj, missing_methods)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment