def test_clean_file_opened(self): """Tests utils.clean_file() with a stringIO object.""" string_io = io.StringIO(u'Mary had a little lamb') f, opened = utils.clean_file(string_io) assert hasattr(f, 'read') assert not opened # Closing stringIO after test assertions. f.close()
def test_clean_file_unopened(self): """Tests utils.clean_file() with a filepath. This test relies on the openability of the file 'fsdfgh' located in 'test/functional/fake_dir'. """ path = os.path.join(os.path.dirname(__file__), "..", "functional", "fake_dir", "fsdfgh") f, opened = utils.clean_file(path) assert hasattr(f, 'read') assert opened # Closing file after test assertions. f.close()
def test_clean_file_unopened_binarypath(self): """Tests utils.clean_file() with a binary string filepath. This test relies on the openability of the file 'fsdfgh' located in 'test/functional/fake_dir'. """ path = os.fsencode(os.path.dirname(__file__)) path = os.path.join(path, b"..", b"functional", b"fake_dir", b"fsdfgh") f, opened = utils.clean_file(path) assert hasattr(f, 'read') assert opened # Closing file after test assertions. f.close()
def test_clean_file_unopened_textpath(self): """Tests utils.clean_file() with a text string filepath. This test relies on the openability of the file 'fsdfgh' located in 'test/functional/fake_dir'. """ path = os.path.dirname(__file__) if isinstance(path, six.binary_type): #PY2 path = path.decode(sys.getfilesystemencoding()) path = os.path.join(path, u"..", u"functional", u"fake_dir", u"fsdfgh") f, opened = utils.clean_file(path) assert hasattr(f, 'read') assert opened # Closing file after test assertions. f.close()