Naming issue with CallList __call__ emulation

flzz avatarflzz created an issue

The call operation in question is here:

from dingus import DingusTestCase, Dingus
import nose
import sys

class MockedClass(object):

class Class(object):
    def __init__(self):
        self.mocked_class = MockedClass(name='foo')

class ClassTest(DingusTestCase(Class)):

    def setup(self):
        super(ClassTest, self).setup()
        self.object = Class()

class WhenInstantiatingClass(ClassTest):
    def should_be_a_class(self):
        assert isinstance(self.object, Class)
    def should_create_mocked_class(self):
        assert MockedClass.calls('()', name='foo').once()

if __name__ == '__main__':
    nose_args = sys.argv + [r'-vsx',

As the test illustrates, the way call is defined, the name arg will conflict with any key word args that may be defined as 'name'. A simple solution for my use was to use a double under in front of definition.

def __call__(self, __name=NoArgument, *args, **kwargs):
    return CallList([call for call in self
                     if (__name is NoArgument or __name ==
                     and self._match_args(call, args)
                     and self._match_kwargs(call, kwargs)])

Comments (2)

  1. Anonymous

    I've fixed this in 28db58980063 . I didn't bother adding a test to the suite, though, as it's only a naming change. I'd like to remove the name argument altogether, switching the syntax from

    assert a.calls('some_method', some_arg)


    assert a.some_method.calls(some_arg)

    (This makes the unfortunate name "calls" stick out a bit more, but that's another problem and I don't know what name would be better. I think that the library uses called_with, which is nice but wordy.)

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.