]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
hold counts in a Counter
authorKevin McCarthy <me@kevinmccarthy.org>
Thu, 8 Aug 2013 05:35:04 +0000 (19:35 -1000)
committerKevin McCarthy <me@kevinmccarthy.org>
Mon, 12 Aug 2013 01:05:40 +0000 (15:05 -1000)
vcr/cassette.py
vcr/request.py

index 0daaa50a2bf6b22434d356956599009797c35d41..e5c237f014f3aa2637e306fd7d413c7d5856b3f3 100644 (file)
@@ -2,13 +2,13 @@
 
 import os
 import tempfile
+from collections import Counter
 
 # Internal imports
 from .patch import install, reset
 from .files import load_cassette, save_cassette
 from .request import Request
 
-
 class Cassette(object):
     '''A container for recorded requests and responses'''
     @classmethod
@@ -22,7 +22,7 @@ class Cassette(object):
     def __init__(self, path, data=None):
         self._path = path
         self.requests = {}
-        self.play_count = 0
+        self.play_counts = Counter()
         if data:
             self.deserialize(data)
 
@@ -42,16 +42,24 @@ class Cassette(object):
         for r in source:
             self.requests[r['request']] = r['response']
 
+    @property
+    def play_count(self):
+        return sum(self.play_counts.values())
+
     def mark_played(self, request=None):
         '''
         Alert the cassette of a request that's been played
         '''
-        self.play_count += 1
+        self.play_counts[request] += 1
 
     def append(self, request, response):
         '''Add a pair of request, response to this cassette'''
         self.requests[request] = response
 
+    def response(self, request):
+        '''Find the response corresponding to a request'''
+        return self.requests[request]
+
     def __len__(self):
         '''Return the number of request / response pairs stored in here'''
         return len(self.requests)
@@ -60,10 +68,6 @@ class Cassette(object):
         '''Return whether or not a request has been stored'''
         return request in self.requests
 
-    def response(self, request):
-        '''Find the response corresponding to a request'''
-        return self.requests[request]
-
     def __enter__(self):
         '''Patch the fetching libraries we know about'''
         install(self)
index 632c8b2e27192109afc023f173a79efac25e8439..dc486923cf6cb01cfa058e3c9a6de52730b75969 100644 (file)
@@ -16,3 +16,6 @@ class Request(object):
 
     def __eq__(self, other):
         return hash(self) == hash(other)
+
+    def __str__(self):
+        return "<Request ({0}) {1}>".format(self.method, self.body)