/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-02 19:59:16 UTC
  • Revision ID: teddy@recompile.se-20190302195916-mya36qr865qqujnz
mandos-ctl: White space changes only

* mandos-ctl: Fix some white space, wrapping, and indentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
 
217
217
 
218
218
def string_to_delta(interval):
219
 
    """Parse a string and return a datetime.timedelta
220
 
    """
 
219
    """Parse a string and return a datetime.timedelta"""
221
220
 
222
221
    try:
223
222
        return rfc3339_duration_to_delta(interval)
228
227
 
229
228
 
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
 
232
 
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)),
323
323
            key=key)
324
 
                                 for key in self.keywords)
 
324
                        for key in self.keywords)
325
325
 
326
326
    def string_from_client(self, client, key):
327
327
        return self.valuetostring(client[key], key)
647
647
            },
648
648
        ]
649
649
    def test_short_header(self):
650
 
        rows = TableOfClients(self.clients, self.keywords,
651
 
                              self.tablewords).rows()
652
 
        expected_rows = [
653
 
            "X  Yy",
654
 
            "x1 y1",
655
 
            "x2 y2"]
656
 
        self.assertEqual(rows, expected_rows)
 
650
        text = str(TableOfClients(self.clients, self.keywords,
 
651
                                  self.tablewords))
 
652
        expected_text = """
 
653
X  Yy
 
654
x1 y1
 
655
x2 y2
 
656
"""[1:-1]
 
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()
661
 
        expected_rows = [
662
 
            "A D-BUS Boolean A Non-D-BUS Boolean",
663
 
            "No              False              ",
664
 
            "Yes             True               ",
665
 
        ]
666
 
        self.assertEqual(rows, expected_rows)
 
660
        text = str(TableOfClients(self.clients, keywords,
 
661
                                  self.tablewords))
 
662
        expected_text = """
 
663
A D-BUS Boolean A Non-D-BUS Boolean
 
664
No              False              
 
665
Yes             True               
 
666
"""[1:-1]
 
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()
672
 
        expected_rows = ("""
 
671
        text = str(TableOfClients(self.clients, keywords,
 
672
                                  self.tablewords))
 
673
        expected_text = """
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 
676
 
"""
677
 
        ).splitlines()[1:]
678
 
        self.assertEqual(rows, expected_rows)
 
677
"""[1:-1]
 
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()
683
 
        expected_rows = ("""
 
681
        text = str(TableOfClients(self.clients, keywords,
 
682
                                  self.tablewords))
 
683
        expected_text = """
684
684
A String                                                                                                                                                                                                                                                                                                                                  
685
685
                                                                                                                                                                                                                                                                                                                                          
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,
687
 
"""
688
 
        ).splitlines()[1:]
689
 
        self.assertEqual(rows, expected_rows)
 
687
"""[1:-1]
 
688
        self.assertEqual(text, expected_text)
690
689
 
691
690
 
692
691