Commits

infrared  committed d6e7f22

Changed 'as' method to 'extract' ('as' is a keyword in Python 2.5).
Changed name of 'Pretender' into 'Copycat'.

  • Participants
  • Parent commits 819bb3b

Comments (0)

Files changed (1)

File tests/test_store.py

         assert call.name == method, "Expected call to '%s', got %s" % (method, call)
         assert predicate(*call.params, **call.kwparams), "Expectation failed for method '%s': got %s" % (method, call)
 
-class Pretender(object):
-    def as(self, klass, method):
-        """Pretend we're object of given `klass` which can receive a `method`.
+class Copycat(object):
+    def extract(self, klass, method):
+        """Extract a `method` from given `klass` so it can be used on this object.
 
         >>> class A(object):
         ...    def inc(self, n):
         ...        return n + 1
-        >>> p = Pretender()
-        >>> p.as(A, 'inc')(5)
+        >>> p = Copycat()
+        >>> p.extract(A, 'inc')(5)
         6
         """
         return lambda *args, **kwds: klass.__dict__[method](self, *args, **kwds)
         >>> class A(object):
         ...     def inc(self, n):
         ...         return n + 1
-        >>> p = Pretender()
+        >>> p = Copycat()
         >>> p.inc(11)
         Traceback (most recent call last):
           ...
-        AttributeError: 'Pretender' object has no attribute 'inc'
+        AttributeError: 'Copycat' object has no attribute 'inc'
         >>> p.copy_method(A, 'inc')
         >>> p.inc(11)
         12
         """
-        self.__dict__[method] = self.as(klass, method)
+        self.__dict__[method] = self.extract(klass, method)
 
     def copy_methods(self, klass, *methods):
         """Copy methods from `klass` into this object.
         for method in methods:
             self.copy_method(klass, method)
 
-class PretenderMock(Mock, Pretender): pass
+class CopycatMock(Mock, Copycat): pass
 
 def make_store_mock(mock_values={}, cursor={}, db={}):
-    mock = PretenderMock(mock_values, Store)
+    mock = CopycatMock(mock_values, Store)
 
     mock.directory = '/log_directory'
     mock.timestamp_file = 'timestamp_file'
         os.listdir = returning([])
 
         store_mock = make_store_mock()
-        store_mock.as(Store, '_read_cheesecake_runs')()
+        store_mock.extract(Store, '_read_cheesecake_runs')()
 
         check_calls_count(store_mock, 'save_run', exactly=0)
 
                                 '4-setuptools==0.6c1-success-42.log'])
 
         store_mock = make_store_mock()
-        store_mock.as(Store, '_read_cheesecake_runs')()
+        store_mock.extract(Store, '_read_cheesecake_runs')()
 
         check_calls_count(store_mock, 'save_run', exactly=4)
 
                                 '101-chimera==0.4.4-failure-42.log'])
 
         store_mock = make_store_mock()
-        store_mock.as(Store, '_read_cheesecake_runs')()
+        store_mock.extract(Store, '_read_cheesecake_runs')()
 
         check_calls_count(store_mock, 'save_run', exactly=3)
 
                                 'different.log'])
 
         store_mock = make_store_mock()
-        store_mock.as(Store, '_read_cheesecake_runs')()
+        store_mock.extract(Store, '_read_cheesecake_runs')()
 
         check_calls_count(store_mock, 'save_run', exactly=1)
 
 
         store_mock = make_store_mock()
 
-        store_mock.as(Store, '_read_cheesecake_runs')()
+        store_mock.extract(Store, '_read_cheesecake_runs')()
 
         check_calls(store_mock, [('save_run', check_run)])
 
 
     def test_is_empty_when_database_table_is_empty(self):
         store_mock = make_store_mock(cursor={'fetchall': []})
-        store_mock.as(Store, '_read_releases_to_score')()
+        store_mock.extract(Store, '_read_releases_to_score')()
 
         self.assertEqual(store_mock.releases_to_score, [])
 
             ('twill', '0.8.5'),
         ]
 
-        store_mock.as(Store, '_save_releases_to_score')()
+        store_mock.extract(Store, '_save_releases_to_score')()
 
         check_calls(store_mock.cursor, [
             # Table should be cleaned first...
         store_mock = make_store_mock(cursor={'fetchall': list_of_releases[:]})
 
         # Call method we're interested in.
-        store_mock.as(Store, '_read_releases_to_score')()
+        store_mock.extract(Store, '_read_releases_to_score')()
 
         check_calls(store_mock.cursor, [
             ('execute', args_are('SELECT * FROM releases_to_score', ())),
         durus_score = CheesecakeScore(cheesecake_run_output)
 
         # Pretend our mock is a Store class object.
-        store_mock.as(Store, 'save_score')('Durus', '3.4.1', durus_score)
+        store_mock.extract(Store, 'save_score')('Durus', '3.4.1', durus_score)
 
         check_calls(store_mock, [
             # Should save main indexes first...
 
         durus_score = CheesecakeScore(cheesecake_run_output)
 
-        store_mock.as(Store, 'save_score')('Durus', '3.4.1', durus_score)
+        store_mock.extract(Store, 'save_score')('Durus', '3.4.1', durus_score)
 
         check_calls(store_mock, [
             # Should save main indexes first...