]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Random tweaks.
authorIvan Malison <IvanMalison@gmail.com>
Mon, 6 Oct 2014 01:37:01 +0000 (18:37 -0700)
committerIvan Malison <IvanMalison@gmail.com>
Mon, 6 Oct 2014 01:37:01 +0000 (18:37 -0700)
vcr/cassette.py
vcr/patch.py
vcr/stubs/__init__.py

index e2b1d91d03e3d278bc28ae45fec93db8012d6232..099253f71132ab07a863e559ec4b58ffd286cd99 100644 (file)
@@ -1,4 +1,4 @@
-'''The container for recorded requests and responses'''
+"""The container for recorded requests and responses"""
 import logging
 
 import contextlib2
@@ -24,7 +24,7 @@ class CassetteContextDecorator(object):
     removing cassettes.
 
     This class defers the creation of a new cassette instance until the point at
-    which it is installned by context manager or decorator. The fact that a new
+    which it is installed by context manager or decorator. The fact that a new
     cassette is used with each application prevents the state of any cassette
     from interfering with another.
     """
@@ -45,7 +45,8 @@ class CassetteContextDecorator(object):
             log.debug('Entered context for cassette at {0}.'.format(cassette._path))
             yield cassette
             log.debug('Exiting context for cassette at {0}.'.format(cassette._path))
-             # TODO(@IvanMalison): Hmmm. it kind of feels like this should be somewhere else.
+            # TODO(@IvanMalison): Hmmm. it kind of feels like this should be
+            # somewhere else.
             cassette._save()
 
     def __enter__(self):
@@ -65,11 +66,11 @@ class CassetteContextDecorator(object):
 
 
 class Cassette(object):
-    '''A container for recorded requests and responses'''
+    """A container for recorded requests and responses"""
 
     @classmethod
     def load(cls, path, **kwargs):
-        '''Instantiate and load the cassette stored at the specified path.'''
+        """Instantiate and load the cassette stored at the specified path."""
         new_cassette = cls(path, **kwargs)
         new_cassette._load()
         return new_cassette
@@ -85,7 +86,8 @@ class Cassette(object):
     def __init__(self, path, serializer=yamlserializer, record_mode='once',
                  match_on=(uri, method), filter_headers=(),
                  filter_query_parameters=(), before_record_request=None,
-                 before_record_response=None, ignore_hosts=(), ignore_localhost=()):
+                 before_record_response=None, ignore_hosts=(),
+                 ignore_localhost=()):
         self._path = path
         self._serializer = serializer
         self._match_on = match_on
@@ -105,9 +107,7 @@ class Cassette(object):
 
     @property
     def all_played(self):
-        """
-        Returns True if all responses have been played, False otherwise.
-        """
+        """Returns True if all responses have been played, False otherwise."""
         return self.play_count == len(self)
 
     @property
@@ -124,7 +124,7 @@ class Cassette(object):
             self.record_mode == 'none'
 
     def append(self, request, response):
-        '''Add a request, response pair to this cassette'''
+        """Add a request, response pair to this cassette"""
         request = self._before_record_request(request)
         if not request:
             return
@@ -153,10 +153,10 @@ class Cassette(object):
             self.rewound
 
     def play_response(self, request):
-        '''
+        """
         Get the response corresponding to a request, but only if it
         hasn't been played back before, and mark it as played
-        '''
+        """
         for index, response in self._responses(request):
             if self.play_counts[index] == 0:
                 self.play_counts[index] += 1
@@ -168,11 +168,11 @@ class Cassette(object):
         )
 
     def responses_of(self, request):
-        '''
+        """
         Find the responses corresponding to a request.
         This function isn't actually used by VCR internally, but is
         provided as an external API.
-        '''
+        """
         responses = [response for index, response in self._responses(request)]
 
         if responses:
@@ -214,11 +214,11 @@ class Cassette(object):
         )
 
     def __len__(self):
-        '''Return the number of request,response pairs stored in here'''
+        """Return the number of request,response pairs stored in here"""
         return len(self.data)
 
     def __contains__(self, request):
-        '''Return whether or not a request has been stored'''
+        """Return whether or not a request has been stored"""
         for response in self._responses(request):
             return True
         return False
index df14cc08bfcfa568a1ef2f937dfc46a36d22b477..aeabf1d9e4474cdd4ac9fb9dd0e7e16c5fd65813 100644 (file)
@@ -59,7 +59,9 @@ class CassettePatcherBuilder(object):
     def _build_patchers_from_mock_triples_decorator(function):
         @functools.wraps(function)
         def wrapped(self, *args, **kwargs):
-            return self._build_patchers_from_mock_triples(function(self, *args, **kwargs))
+            return self._build_patchers_from_mock_triples(
+                function(self, *args, **kwargs)
+            )
         return wrapped
 
     def __init__(self, cassette):
index 6ffe4b4ad451673b7f53a1247ceb416c8b82b1d5..4e534f4790589dfe0b5713492672a002fbf1285b 100644 (file)
@@ -217,11 +217,15 @@ class VCRConnection(object):
             response = self.cassette.play_response(self._vcr_request)
             return VCRHTTPResponse(response)
         else:
-            if self.cassette.write_protected and self.cassette.filter_request(self._vcr_request):
+            if self.cassette.write_protected and self.cassette.filter_request(
+                self._vcr_request
+            ):
                 raise CannotOverwriteExistingCassetteException(
+                    "No match for the request (%r) was found. "
                     "Can't overwrite existing cassette (%r) in "
                     "your current record mode (%r)."
-                    % (self.cassette._path, self.cassette.record_mode)
+                    % (self._vcr_request, self.cassette._path,
+                       self.cassette.record_mode)
                 )
 
             # Otherwise, we should send the request, then get the response