def test_export_pickle_with_path_uses_open(mock_open, exists, pickle_dump): exists.return_value = False fake_path = str(_norm_path('fake.pkl.gz')) mock_open_enter = MagicMock() # Make sure the name attribute returns the path mock_open_enter.__enter__.return_value.configure_mock(name=fake_path) mock_open.return_value = mock_open_enter mio.export_pickle(test_lg, fake_path) assert pickle_dump.call_count == 1 mock_open.assert_called_with(fake_path, 'wb')
def test_export_pickle_with_path_uses_open(mock_open, exists, pickle_dump): exists.return_value = False fake_path = _norm_path("fake.pkl.gz") mock_open_enter = MagicMock() # Make sure the name attribute returns the path mock_open_enter.__enter__.return_value.configure_mock(name=fake_path) mock_open.return_value = mock_open_enter mio.export_pickle(test_lg, fake_path) pickle_dump.assert_called_once() mock_open.assert_called_once_with(fake_path, "wb")