mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 03:02:52 +01:00
utils.str.format: Add support for sets for %L + add test case. Closes GH-1104
This commit is contained in:
parent
2008956968
commit
3f9118a1a6
@ -478,15 +478,14 @@ def format(s, *args, **kwargs):
|
||||
return has(args.pop())
|
||||
elif char == 'L':
|
||||
t = args.pop()
|
||||
if isinstance(t, list) or (sys.version_info[0] >= 3 and
|
||||
(isinstance(t, map) or isinstance(t, filter))):
|
||||
return commaAndify(t)
|
||||
elif isinstance(t, tuple) and len(t) == 2:
|
||||
if isinstance(t, tuple) and len(t) == 2:
|
||||
if not isinstance(t[0], list):
|
||||
raise ValueError('Invalid list for %%L in format: %s' % t)
|
||||
if not isinstance(t[1], basestring):
|
||||
raise ValueError('Invalid string for %%L in format: %s' % t)
|
||||
return commaAndify(t[0], And=t[1])
|
||||
elif hasattr(t, '__iter__'):
|
||||
return commaAndify(t)
|
||||
else:
|
||||
raise ValueError('Invalid value for %%L in format: %s' % t)
|
||||
elif char == 'p':
|
||||
|
@ -539,6 +539,18 @@ class FormatTestCase(SupyTestCase):
|
||||
'I have 3 kinds of fruit: '
|
||||
'apples, oranges, and watermelon.')
|
||||
|
||||
def testPercentL(self):
|
||||
self.assertIn(format('%L', {'apples', 'oranges', 'watermelon'}), {
|
||||
'apples, oranges, and watermelon',
|
||||
'oranges, apples, and watermelon',
|
||||
'apples, watermelon, and oranges',
|
||||
'oranges, watermelon, and apples',
|
||||
'watermelon, apples, and oranges',
|
||||
'watermelon, oranges, and apples'})
|
||||
|
||||
self.assertEqual(format('%L',
|
||||
(['apples', 'oranges', 'watermelon'], 'or')),
|
||||
'apples, oranges, or watermelon')
|
||||
class RingBufferTestCase(SupyTestCase):
|
||||
def testInit(self):
|
||||
self.assertRaises(ValueError, RingBuffer, -1)
|
||||
|
Loading…
Reference in New Issue
Block a user