Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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')
Example #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)
Example #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')
Example #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')
Example #11
0
 def test_should_open_twice(self):
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '')
     fileobj = file.open('r')
     fileobj.close()
     file.open('w')
Example #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')
Example #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)
Example #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()
Example #15
0
 def test_should_getvalue(self):
     content = "something"
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content)
     self.assertEqual(file.getvalue(), content)