예제 #1
0
 def test_raises_on_wrong_param_bytes(self):
     with self.assertRaises(ValueError):
         with mock_open(on_read_bytes=123):
             pass
예제 #2
0
 def test_work_readlines(self):
     with mock_open(on_read_text='123\n456'):
         answer = read_lines()
     self.assertEqual(['123\n', '456'], answer)
예제 #3
0
 def test_mode_and_flush(self):
     with mock_open() as a_list:
         write_bytes_mode_and_flush()
     self.assertEqual(b'test', a_list[0])
예제 #4
0
 def test_no_raises_on_wrong_param_but_raises_arg(self):
     with mock_open(None, raises=ValueError()):
         pass
예제 #5
0
 def test_write_bytes(self):
     with mock_open() as a_list:
         write_bytes()
     self.assertEqual(b'test', a_list[0])
예제 #6
0
 def test_both_contexts(self):
     with mock_open(on_read_text='123\n456') as a_l:
         both_context()
     self.assertEqual(a_l, ['1'])
예제 #7
0
 def test_work_read_bytes(self):
     with mock_open(on_read_bytes=b'123\n456'):
         answer = read_bytes()
     self.assertEqual(b'1', answer)
예제 #8
0
    def test_raises_on_param(self):
        with self.assertRaises(IOError) as e:
            with mock_open("None", raises=IOError("File not found!")):
                read_lines()

        self.assertEqual('File not found!', e.exception.args[0])
예제 #9
0
 def test_work_read(self):
     with mock_open('123\n456'):
         answer = read()
     self.assertEqual('1', answer)