Skip to content

Commit

Permalink
Define keyword init and repr for the Errors class
Browse files Browse the repository at this point in the history
  • Loading branch information
richardbuckle committed Aug 27, 2017
1 parent 408c366 commit 2afc411
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
24 changes: 23 additions & 1 deletion test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,34 @@ def testRepr(self):

class ErrorTests(unittest.TestCase):

def testInitsWithBlankData(self):
def testInitWithBlankData(self):
errors = bindings.Errors()
self.assertEqual(errors.unhandledDevicesWarnings, '')
self.assertEqual(errors.deviceWarnings, '')
self.assertEqual(errors.misconfigurationWarnings, '')
self.assertEqual(errors.errors, '')

def testInitWithData(self):
errors = bindings.Errors(
unhandledDevicesWarnings='spam',
deviceWarnings='eggs',
misconfigurationWarnings='my hovercraft is full of eels',
errors='the larch'
)
self.assertEqual(errors.unhandledDevicesWarnings, 'spam')
self.assertEqual(errors.deviceWarnings, 'eggs')
self.assertEqual(errors.misconfigurationWarnings, 'my hovercraft is full of eels')
self.assertEqual(errors.errors, 'the larch')

def testRepr(self):
errors = bindings.Errors(
unhandledDevicesWarnings='spam',
deviceWarnings='eggs',
misconfigurationWarnings='my hovercraft is full of eels',
errors='the larch'
)
expectedRepr = "Errors(unhandledDevicesWarnings='spam', deviceWarnings='eggs', misconfigurationWarnings='my hovercraft is full of eels', errors='the larch')"
self.assertEqual(repr(errors), expectedRepr)


class testTransKey(unittest.TestCase):
Expand Down
21 changes: 15 additions & 6 deletions www/scripts/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,21 @@ class Mode(Enum):

class Errors:

def __init__(self):
self.unhandledDevicesWarnings = ''
self.deviceWarnings = ''
self.misconfigurationWarnings = ''
self.errors = ''

def __init__(
self,
unhandledDevicesWarnings = '',
deviceWarnings = '',
misconfigurationWarnings = '',
errors = ''
):
self.unhandledDevicesWarnings = unhandledDevicesWarnings
self.deviceWarnings = deviceWarnings
self.misconfigurationWarnings = misconfigurationWarnings
self.errors = errors

def __repr__(self):
return ("Errors(unhandledDevicesWarnings='%s', deviceWarnings='%s', misconfigurationWarnings='%s', errors='%s')"
% (self.unhandledDevicesWarnings, self.deviceWarnings, self.misconfigurationWarnings, self.errors))

# Utility section

Expand Down

0 comments on commit 2afc411

Please sign in to comment.