230
229
def parse_pre_1_6_1_interval(interval):
231
"""Parse an interval string as documented by Mandos before 1.6.1, and
232
return a datetime.timedelta
230
"""Parse an interval string as documented by Mandos before 1.6.1,
231
and return a datetime.timedelta
233
233
>>> parse_pre_1_6_1_interval('7d')
234
234
datetime.timedelta(7)
235
235
>>> parse_pre_1_6_1_interval('60s')
318
318
"Format string used to format table rows"
319
319
return " ".join("{{{key}:{width}}}".format(
320
320
width=max(len(self.tablewords[key]),
321
max(len(self.string_from_client(client, key))
322
for client in self.clients)),
321
*(len(self.string_from_client(client, key))
322
for client in self.clients)),
324
for key in self.keywords)
324
for key in self.keywords)
326
326
def string_from_client(self, client, key):
327
327
return self.valuetostring(client[key], key)
649
649
def test_short_header(self):
650
rows = TableOfClients(self.clients, self.keywords,
651
self.tablewords).rows()
656
self.assertEqual(rows, expected_rows)
650
text = str(TableOfClients(self.clients, self.keywords,
657
self.assertEqual(text, expected_text)
657
658
def test_booleans(self):
658
659
keywords = ["Bool", "NonDbusBoolean"]
659
rows = TableOfClients(self.clients, keywords,
660
self.tablewords).rows()
662
"A D-BUS Boolean A Non-D-BUS Boolean",
666
self.assertEqual(rows, expected_rows)
660
text = str(TableOfClients(self.clients, keywords,
663
A D-BUS Boolean A Non-D-BUS Boolean
667
self.assertEqual(text, expected_text)
667
668
def test_milliseconds_detection(self):
668
669
keywords = ["Integer", "Timeout", "Interval", "ApprovalDelay",
669
670
"ApprovalDuration", "ExtendedTimeout"]
670
rows = TableOfClients(self.clients, keywords,
671
self.tablewords).rows()
671
text = str(TableOfClients(self.clients, keywords,
673
674
An Integer Timedelta 1 Timedelta 2 Timedelta 3 Timedelta 4 Timedelta 5
674
675
0 00:00:00 00:00:01 00:00:02 00:00:03 00:00:04
675
676
1 1T02:03:05 1T02:03:06 1T02:03:07 1T02:03:08 1T02:03:09
678
self.assertEqual(rows, expected_rows)
678
self.assertEqual(text, expected_text)
679
679
def test_empty_and_long_string_values(self):
680
680
keywords = ["String"]
681
rows = TableOfClients(self.clients, keywords,
682
self.tablewords).rows()
681
text = str(TableOfClients(self.clients, keywords,
686
686
A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,
689
self.assertEqual(rows, expected_rows)
688
self.assertEqual(text, expected_text)