mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
substiture IOError with more appropriate ValueError
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
'''Tests for cassettes with overriden persistence'''
|
'''Tests for cassettes with custom persistence'''
|
||||||
|
|
||||||
# External imports
|
# External imports
|
||||||
import os
|
import os
|
||||||
@@ -11,7 +11,7 @@ from vcr.persisters.filesystem import FilesystemPersister
|
|||||||
|
|
||||||
|
|
||||||
def test_save_cassette_with_custom_persister(tmpdir, httpbin):
|
def test_save_cassette_with_custom_persister(tmpdir, httpbin):
|
||||||
'''Ensure you can save a cassette using save_callback'''
|
'''Ensure you can save a cassette using custom persister'''
|
||||||
my_vcr = vcr.VCR()
|
my_vcr = vcr.VCR()
|
||||||
my_vcr.register_persister(FilesystemPersister)
|
my_vcr.register_persister(FilesystemPersister)
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ def test_save_cassette_with_custom_persister(tmpdir, httpbin):
|
|||||||
|
|
||||||
def test_load_cassette_with_custom_persister(tmpdir, httpbin):
|
def test_load_cassette_with_custom_persister(tmpdir, httpbin):
|
||||||
'''
|
'''
|
||||||
Ensure you can load a cassette using load_callback
|
Ensure you can load a cassette using custom persister
|
||||||
'''
|
'''
|
||||||
my_vcr = vcr.VCR()
|
my_vcr = vcr.VCR()
|
||||||
my_vcr.register_persister(FilesystemPersister)
|
my_vcr.register_persister(FilesystemPersister)
|
||||||
@@ -288,7 +288,7 @@ class Cassette(object):
|
|||||||
self.append(request, response)
|
self.append(request, response)
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
self.rewound = True
|
self.rewound = True
|
||||||
except IOError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# .. _persister_example:
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from ..serialize import serialize, deserialize
|
from ..serialize import serialize, deserialize
|
||||||
|
|
||||||
@@ -6,8 +8,11 @@ class FilesystemPersister(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_cassette(cls, cassette_path, serializer):
|
def load_cassette(cls, cassette_path, serializer):
|
||||||
with open(cassette_path) as f:
|
try:
|
||||||
cassette_content = f.read()
|
with open(cassette_path) as f:
|
||||||
|
cassette_content = f.read()
|
||||||
|
except IOError:
|
||||||
|
raise ValueError('Cassette not found.')
|
||||||
cassette = deserialize(cassette_content, serializer)
|
cassette = deserialize(cassette_content, serializer)
|
||||||
return cassette
|
return cassette
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user