has207/flexmock — Issue #67: tuple and namedtuple arguments aren't properly formatted
Author: kriomant
Created: 2012-02-29 03:05:38+00:00
State: open

Argument formatting method:

def _arg_to_str(arg):
arg = '%s' % arg # ensure unicode conversion

It works incorrectly if `arg` is tuple or namedtuple:

>>> '%s' % (1)
'1'
>>> '%s' % (1, 2)
Traceback (most recent call last):
File "", line 1, in
TypeError: not all arguments converted during string formatting
>>> from collections import namedtuple
>>> '%s' % namedtuple('NT', ('a',))(1)
'1'
>>> '%s' % namedtuple('NT', ('a', 'b'))(1, 2)
Traceback (most recent call last):
File "", line 1, in
TypeError: not all arguments converted during string formatting

Correct way is:

'%s' % (arg,)

>>> '%s' % ((1,2),)
'(1, 2)'