]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Added checkfor old cassette on load cassete to persist module
authorMax Shytikov <mshytikov@gmail.com>
Thu, 24 Apr 2014 00:03:56 +0000 (02:03 +0200)
committerMax Shytikov <mshytikov@gmail.com>
Wed, 30 Apr 2014 00:36:26 +0000 (02:36 +0200)
vcr/persist.py

index 1f270d8e696553a5b7f8d3526e47f2227a36860d..8c00b3258f9bdb65871ada436173fe7a7b96c3d0 100644 (file)
@@ -1,9 +1,31 @@
+import tempfile
+
 from .persisters.filesystem import FilesystemPersister
+from . import migration
+
+
+def _check_for_old_cassette(cassette_content):
+    # crate tmp with cassete content and try to migrate it
+    with tempfile.NamedTemporaryFile(mode='w+') as f:
+        f.write(cassette_content)
+        f.seek(0)
+        if migration.try_migrate(f.name):
+            raise ValueError(
+                "Your cassette files were generated in an older version "
+                "of VCR. Delete your cassettes or run the migration script."
+                "See http://git.io/mHhLBg for more details."
+            )
 
 
 def load_cassette(cassette_path, serializer):
     with open(cassette_path) as f:
-        return serializer.deserialize(f.read())
+        cassette_content = f.read()
+        try:
+            cassette = serializer.deserialize(cassette_content)
+        except TypeError:
+            _check_for_old_cassette(cassette_content)
+            raise
+        return cassette
 
 
 def save_cassette(cassette_path, cassette_dict, serializer):