Skip to content

Commit

Permalink
Merge pull request #86 from kragniz/directory-not-existing-error-message
Browse files Browse the repository at this point in the history
Improve error message if cassettes dir does not exist
  • Loading branch information
sigmavirus24 committed Dec 22, 2015
2 parents a3e5583 + 2f8a974 commit ad2aebe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions betamax/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ def __init__(self, message):

def __repr__(self):
return 'BetamaxError("%s")' % self.message


class MissingDirectoryError(BetamaxError):
pass
7 changes: 7 additions & 0 deletions betamax/serializers/proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from .base import BaseSerializer
from betamax.exceptions import MissingDirectoryError

import os

Expand Down Expand Up @@ -27,6 +28,12 @@ def __init__(self, serializer, cassette_path, allow_serialization=False):
self.cassette_path = cassette_path

def _ensure_path_exists(self):
directory, _ = os.path.split(self.cassette_path)
if not (directory == '' or os.path.isdir(directory)):
raise MissingDirectoryError(
'Configured cassette directory \'{0}\' does not exist - try '
'creating it'.format(directory)
)
if not os.path.exists(self.cassette_path):
open(self.cassette_path, 'w+').close()

Expand Down

0 comments on commit ad2aebe

Please sign in to comment.