uber / doubles

Test doubles for Python.
MIT License
164 stars 17 forks source link

expect/allow not working for object with __slots__ #93

Open ximyu opened 9 years ago

ximyu commented 9 years ago

I have a class with __slots__ like below:

class TripsQueryResult(object):
    __slots__ = [
        'trip_entities', 'num_trip_rows', 'count',
    ]

    def to_thrift_trips(self, field_options):
        pass

    def to_thrift_paging_result(self, paging_info):
        pass

And my test code looks like:

        (
            expect(self.trips_query_result)
            .to_thrift_trips
            .with_args(self.field_options)
            .once()
        )
        (
            expect(self.trips_query_result)
            .to_thrift_paging_result
            .with_args(self.paging_info)
            .once()
        )

I'm running into the following error:

tests/entities/test_trips_query.py:34: in test_to_thrift
    expect(self.trips_query_result)
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/targets/expectation_target.py:67: in __getattribute__
    return self._proxy.add_expectation(attr_name, caller)
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/proxy.py:37: in add_expectation
    return self.method_double_for(method_name).add_expectation(caller)
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/proxy.py:67: in method_double_for
    self._method_doubles[method_name] = MethodDouble(method_name, self._target)
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/method_double.py:29: in __init__
    lambda args, kwargs: self._find_matching_double(args, kwargs)
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/proxy_method.py:60: in __init__
    self._hijack_target()
../../.virtualenvs/trident/lib/python2.7/site-packages/doubles/proxy_method.py:138: in _hijack_target
    self._target.obj.__dict__[self._method_name] = self
E   AttributeError: 'TripsQueryResult' object has no attribute '__dict__'