Naming issue with CallList __call__ emulation

Issue #13 resolved
created an issue

The call operation in question is here:

{{{ from dingus import DingusTestCase, Dingus import nose import sys

class MockedClass(object): pass

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', r'-m', r'((?:^|[b_.-])(:?[Tt]est|When|should|[Dd]escribe))'] nose.runmodule(argv=nose_args) }}}

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