def test_raises_on_wrong_param_bytes(self): with self.assertRaises(ValueError): with mock_open(on_read_bytes=123): pass
def test_work_readlines(self): with mock_open(on_read_text='123\n456'): answer = read_lines() self.assertEqual(['123\n', '456'], answer)
def test_mode_and_flush(self): with mock_open() as a_list: write_bytes_mode_and_flush() self.assertEqual(b'test', a_list[0])
def test_no_raises_on_wrong_param_but_raises_arg(self): with mock_open(None, raises=ValueError()): pass
def test_write_bytes(self): with mock_open() as a_list: write_bytes() self.assertEqual(b'test', a_list[0])
def test_both_contexts(self): with mock_open(on_read_text='123\n456') as a_l: both_context() self.assertEqual(a_l, ['1'])
def test_work_read_bytes(self): with mock_open(on_read_bytes=b'123\n456'): answer = read_bytes() self.assertEqual(b'1', answer)
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])
def test_work_read(self): with mock_open('123\n456'): answer = read() self.assertEqual('1', answer)