From b9471799720bea4c96e388cc314ca8f68b9ac68f Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 3 Mar 2014 21:54:35 +0200 Subject: [PATCH] Test pickle and cpickle on User object. Seems to work, so going to close #83 and can re-open if more specific info is given. --- .gitignore | 2 ++ test_pylast.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.gitignore b/.gitignore index d547e2c..e7288ae 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,6 @@ coverage.xml # Sphinx documentation docs/_build/ +# Test files test_pylast.yaml +lastfm.txt.pkl diff --git a/test_pylast.py b/test_pylast.py index bbb133d..cbc859b 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -662,6 +662,34 @@ class TestPyLast(unittest.TestCase): self.helper_upcoming_events_have_valid_ids(venue) + def helper_test_pickle(self, pickle): + # Arrange + lastfm_user = self.network.get_user(self.username) + + # Act + pickle.dump(lastfm_user, open("lastfm.txt.pkl", "wb")) + loaded_user = pickle.load(open("lastfm.txt.pkl", "rb")) + + # Assert + self.assertEqual(lastfm_user, loaded_user) + + + def test_pickle(self): + # Arrange + import pickle + + # Act/Assert + self.helper_test_pickle(pickle) + + + def test_cpickle(self): + # Arrange + import cPickle as pickle + + # Act/Assert + self.helper_test_pickle(pickle) + + if __name__ == '__main__': # For quick testing of a single case (eg. test = "test_scrobble")