Esempio n. 1
0
 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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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')
Esempio n. 8
0
 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)
Esempio n. 9
0
 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')
Esempio n. 10
0
 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')
Esempio n. 11
0
 def test_should_open_twice(self):
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '')
     fileobj = file.open('r')
     fileobj.close()
     file.open('w')
Esempio n. 12
0
 def test_should_open_only_one(self):
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '')
     file.open('r')
     with self.assertRaises(IOError):
         file.open('r')
Esempio n. 13
0
 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)
Esempio n. 14
0
 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()
Esempio n. 15
0
 def test_should_getvalue(self):
     content = "something"
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content)
     self.assertEqual(file.getvalue(), content)