Fix handling '%d' in exception message

QubesOS/qubes-issues#853
This commit is contained in:
Marek Marczykowski-Górecki 2017-02-27 20:18:29 +01:00
parent 45ab24ce12
commit 851ba6aedb
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 4 additions and 3 deletions

View File

@ -25,4 +25,6 @@ class QubesException(Exception):
'''Base exception for all Qubes-related errors.''' '''Base exception for all Qubes-related errors.'''
def __init__(self, message_format, *args, **kwargs): def __init__(self, message_format, *args, **kwargs):
# TODO: handle translations # TODO: handle translations
super(QubesException, self).__init__(message_format % args, **kwargs) super(QubesException, self).__init__(
message_format % tuple(int(d) if d.isdigit() else d for d in args),
**kwargs)

View File

@ -39,7 +39,6 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase):
self.assertEqual(str(context.exception), self.assertEqual(str(context.exception),
'An error occurred: string, other') 'An error occurred: string, other')
@unittest.expectedFailure
def test_002_exception_with_numbers(self): def test_002_exception_with_numbers(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'2\x00QubesException\x00\x00' \ b'2\x00QubesException\x00\x00' \
@ -49,7 +48,7 @@ class TC_00_Errors(qubesmgmt.tests.QubesTestCase):
vms = list(self.app.domains) vms = list(self.app.domains)
except TypeError as e: except TypeError as e:
self.fail('TypeError: {!s}'.format(e)) self.fail('TypeError: {!s}'.format(e))
self.assertEqual(str(context.exception), 'An error occurred: 1 2') self.assertEqual(str(context.exception), 'An error occurred: 1, 2')
def test_010_empty(self): def test_010_empty(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''\ self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = b''\