Reputation: 8533
I have a function like this:
def save_data(self):
nx.write_gpickle(self.graph, "popitgraph.pickle")
f = open("node_color.pickle", "w")
pickle.dump(self.colors, f)
f.close()
f = open("node_label.pickle", "w")
pickle.dump(self.labels, f)
f.close()
In my test I did this:
@patch("popit_to_networkx.nx.write_gpickle")
@patch("pickle.dump")
def test_networkx_save_data(self, mock_dump, mock_write_gpickle):
# Just assign graph a value to make sure it's passed in
from mock import mock_open
m_file = mock_open()
with patch("__builtin__.open", m_file):
self.popit2networkx.graph = "hulahoop"
self.popit2networkx.colors = {'color1', 'color2'}
self.popit2networkx.labels = {'label1', 'label2'}
self.popit2networkx.save_data()
self.assertEqual(mock_write_gpickle.call_args,
call('hulahoop', 'popitgraph.pickle'))
self.assertTrue(m_file.called)
self.assertEqual(m_file.call_args,
call('node_label.pickle', 'w'))
When I try to look at mock_dump.call_args
I always get the contents of the latest call, how do I get the contents of the previous call ?
Upvotes: 1
Views: 458