Merge lp:~veebers/autopilot/logging-binary-attachments-1336109 into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 499
Merged at revision: 497
Proposed branch: lp:~veebers/autopilot/logging-binary-attachments-1336109
Merge into: lp:autopilot
Diff against target: 73 lines (+36/-3)
2 files modified
autopilot/testresult.py (+9/-1)
autopilot/tests/unit/test_testresults.py (+27/-2)
To merge this branch: bzr merge lp:~veebers/autopilot/logging-binary-attachments-1336109
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomi Richards (community) Approve
Review via email: mp+225098@code.launchpad.net

Commit message

Fixes bug where attempting to attach/addDetail a binary type to a test result raises an exception.

Description of the change

Fixes bug where attempting to attach/addDetail a binary type to a test result raises an exception.

To post a comment you must log in.
499. By Christopher Lee

Removed un-needed use of Mock

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:499
http://jenkins.qa.ubuntu.com/job/autopilot-ci/752/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/26
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/26/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/26
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/26/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/26
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/26/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-autopilot/152
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-touch/174/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic-autopilot/239
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1460
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1460/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2486
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2486/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/6821/console
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9221

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/autopilot-ci/752/rebuild

review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:499
http://jenkins.qa.ubuntu.com/job/autopilot-ci/753/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/27
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/27/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/27
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/27/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/27
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/27/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-autopilot/154
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-touch/176/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic-autopilot/241
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1462
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1462/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2489
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/2489/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/6823/console
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/9226

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/autopilot-ci/753/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/testresult.py'
2--- autopilot/testresult.py 2014-04-01 01:29:19 +0000
3+++ autopilot/testresult.py 2014-07-01 00:36:55 +0000
4@@ -47,11 +47,19 @@
5
6 def _log_details(self, level, details):
7 """Log the relavent test details."""
8+
9 for detail in details:
10 # Skip the test-log as it was logged while the test executed
11 if detail == "test-log":
12 continue
13- text = "%s: {{{\n%s}}}" % (detail, details[detail].as_text())
14+ detail_content = details[detail]
15+ if detail_content.content_type.type == "text":
16+ text = "%s: {{{\n%s}}}" % (detail, detail_content.as_text())
17+ else:
18+ text = "Binary attachment: \"%s\" (%s)" % (
19+ detail,
20+ detail_content.content_type
21+ )
22 self._log(level, text)
23
24 def addSuccess(self, test, details=None):
25
26=== modified file 'autopilot/tests/unit/test_testresults.py'
27--- autopilot/tests/unit/test_testresults.py 2014-05-20 08:53:21 +0000
28+++ autopilot/tests/unit/test_testresults.py 2014-07-01 00:36:55 +0000
29@@ -18,11 +18,11 @@
30 #
31
32 import codecs
33-from unittest.mock import Mock
34+from unittest.mock import Mock, patch
35 import os
36 import tempfile
37 from testtools import TestCase, PlaceHolder
38-from testtools.content import text_content
39+from testtools.content import Content, ContentType, text_content
40 from testtools.matchers import Contains, raises, NotEquals
41 from testscenarios import WithScenarios
42 import unittest
43@@ -82,6 +82,31 @@
44 details=fake_details
45 )
46
47+ def test_log_details_handles_binary_data(self):
48+ fake_details = dict(
49+ TestBinary=Content(ContentType('image', 'png'), lambda: b'')
50+ )
51+
52+ result = testresult.LoggedTestResultDecorator(None)
53+ result._log_details(0, fake_details)
54+
55+ def test_log_details_logs_binary_attachment_details(self):
56+ fake_details = dict(
57+ TestBinary=Content(ContentType('image', 'png'), lambda: b'')
58+ )
59+
60+ result = testresult.LoggedTestResultDecorator(None)
61+ with patch.object(result, '_log') as p_log:
62+ result._log_details(0, fake_details)
63+
64+ p_log.assert_called_once_with(
65+ 0,
66+ "Binary attachment: \"{name}\" ({type})".format(
67+ name="TestBinary",
68+ type="image/png"
69+ )
70+ )
71+
72
73 class OutputFormatFactoryTests(TestCase):
74

Subscribers

People subscribed via source and target branches