def test_file_write_data_with_handle(): """Tests writing to a File with a handle passed in.""" the_file = File(DEFAULT_ARGS) mock_handle = MockHandle() data = 'Some mock data...' the_file.write(data=data, handle=mock_handle) assert mock_handle.called_once_with(data)
def test_file_write_data_without_handle(): """Tests writing to a file without a handle.""" m_open = mock_open() with patch(BUILTINS + '.open', m_open, create=True): the_file = File(DEFAULT_ARGS) data = 'Some mock data...' assert the_file.write(data, False) m_open.assert_called_once_with(DEFAULT_ARGS['path'], 'w') m_open().write.assert_called_once_with(data) m_open().close.assert_called_once_with()
def test_file_write_no_data(): """Tests writing to a File with no data passed in.""" the_file = File(DEFAULT_ARGS) with pytest.raises(UnboundLocalError): the_file.write()