コード例 #1
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #2
0
ファイル: open.py プロジェクト: draftcode/fakeio
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)
コード例 #3
0
ファイル: open.py プロジェクト: draftcode/fakeio
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)
コード例 #4
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #5
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #6
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #7
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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')
コード例 #8
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #9
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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')
コード例 #10
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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')
コード例 #11
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 def test_should_open_twice(self):
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '')
     fileobj = file.open('r')
     fileobj.close()
     file.open('w')
コード例 #12
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 def test_should_open_only_one(self):
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", '')
     file.open('r')
     with self.assertRaises(IOError):
         file.open('r')
コード例 #13
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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)
コード例 #14
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 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()
コード例 #15
0
ファイル: test___init__.py プロジェクト: draftcode/fakeio
 def test_should_getvalue(self):
     content = "something"
     file = fakeio.FakeIOFile("/memfile/something.txt", "rw", content)
     self.assertEqual(file.getvalue(), content)