Example #1
0
 def test_raises_on_wrong_param_bytes(self):
     with self.assertRaises(ValueError):
         with mock_open(on_read_bytes=123):
             pass
Example #2
0
 def test_work_readlines(self):
     with mock_open(on_read_text='123\n456'):
         answer = read_lines()
     self.assertEqual(['123\n', '456'], answer)
Example #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])
Example #4
0
 def test_no_raises_on_wrong_param_but_raises_arg(self):
     with mock_open(None, raises=ValueError()):
         pass
Example #5
0
 def test_write_bytes(self):
     with mock_open() as a_list:
         write_bytes()
     self.assertEqual(b'test', a_list[0])
Example #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'])
Example #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)
Example #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])
Example #9
0
 def test_work_read(self):
     with mock_open('123\n456'):
         answer = read()
     self.assertEqual('1', answer)