~abentley/ci-director/building-trumps-result

« back to all changes in this revision

Viewing changes to cidirector/tests/test_utility.py

  • Committer: Aaron Bentley
  • Date: 2016-08-29 15:01:47 UTC
  • mfrom: (179.1.4 log-exceptions)
  • Revision ID: aaron.bentley@canonical.com-20160829150147-547c84wu7unvrao2
Add exception logging to start-builds, update-outcome.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
from mock import patch
6
6
 
 
7
from cidirector.tests.test_cidirector import test_logger
7
8
from cidirector.utility import (
8
9
    from_jenkins_timestamp,
9
10
    locked_open_rw,
 
11
    log_exceptions,
10
12
    open_rw,
11
13
    parse_iso_date,
12
14
    S3Storage,
21
23
 
22
24
    def test_from_jenkins_timestamp(self):
23
25
        self.assertEqual(datetime(2013, 12, 11, 10, 9, 8, 7000),
24
 
            from_jenkins_timestamp(1386756548007))
 
26
                         from_jenkins_timestamp(1386756548007))
25
27
 
26
28
 
27
29
class TestParseISODate(TestCase):
103
105
            with locked_open_rw(filename) as f:
104
106
                f.seek(0)
105
107
                self.assertEqual(f.read(), 'foo')
 
108
 
 
109
 
 
110
class TestLogExceptions(TestCase):
 
111
 
 
112
    def test_log_exceptions(self):
 
113
        with test_logger() as (log, log_stream):
 
114
            with log_exceptions(log):
 
115
                raise ValueError('mishap')
 
116
        log_pattern = (
 
117
            "(?s)\\Aexception during build revision:\n"
 
118
            "Traceback \\(most recent call last\\):\n"
 
119
            ".*\n"
 
120
            "ValueError: mishap\n\\Z"
 
121
        )
 
122
        self.assertRegexpMatches(log_stream.getvalue(), log_pattern)