def test_should_open_with_mode_w(self): content = "something" file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '') fileobj = file.open("w") fileobj.write(content) fileobj.close() self.assertEqual(file.getvalue(), content)
def given_i_make_a_file_with_byte_string_group1_encoded_with_group2_and_specify_no_encoding( step, content, encoding): world.mock_file = fakeio.FakeIOFile("/somepath", "r", content.encode(encoding), None)
def given_i_make_a_file_with_unicode_string_group1_and_specify_group2_encoding( step, content, encoding): world.mock_file = fakeio.FakeIOFile("/somepath", "r", content, encoding)
def test_io_open_opens_file_in_text_mode(self): content = "あいうえお" file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content, 'utf8') fileobj = file.io_open("r", 'utf8') self.assertIsInstance(fileobj.read(), unicode)
def test_is_constructed_with_unicode(self): content = "あいうえお" file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content, 'utf8') fileobj = file.open("r") self.assertIsInstance(fileobj.read(), str)
def test_is_constructed_with_string(self): content = "あいうえお".encode('cp932') file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content) fileobj = file.open("r") self.assertIsInstance(fileobj.read(), str)
def test_should_iteratable(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", 'abc') fileobj = file.open('r') for line in fileobj: self.assertEqual(line, 'abc')
def test_should_close_when_exit(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '') fileobj = file.open('r') with fileobj as fileobj: pass self.assertTrue(fileobj.closed)
def test_should_not_open_readonly_file_with_mode_w(self): file = fakeio.FakeIOFile("/memfile/something.txt", "r", '') with self.assertRaises(ValueError): file.open('w')
def test_should_open_with_mode_a(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", 'some') fileobj = file.open('a') fileobj.write('thing') fileobj.close() self.assertEqual(file.getvalue(), 'something')
def test_should_open_twice(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '') fileobj = file.open('r') fileobj.close() file.open('w')
def test_should_open_only_one(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '') file.open('r') with self.assertRaises(IOError): file.open('r')
def test_should_open_with_mode_r(self): content = "something" file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content) fileobj = file.open("r") self.assertEqual(fileobj.read(), content)
def test_should_not_getvalue_if_file_opened(self): file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '') file.open('r') with self.assertRaises(IOError): file.getvalue()
def test_should_getvalue(self): content = "something" file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content) self.assertEqual(file.getvalue(), content)