Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
fixes an error where it is possible for a test suite date_created to …
Browse files Browse the repository at this point in the history
…be None when that test suite is empty

Summary: This fixes an issue where if a test suite has no test cases, it might have a None value for date_created.

Test Plan: unit tests

Reviewers: anupc, kylec

Reviewed By: kylec

Subscribers: changesbot, kylec

Differential Revision: https://tails.corp.dropbox.com/D225465
  • Loading branch information
Naphat Sanguansin committed Sep 1, 2016
1 parent 6e097c3 commit 597880e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changes/artifacts/xunit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, division

import logging
from datetime import datetime
from operator import add
from xml.parsers import expat
from xml.sax import saxutils
Expand Down Expand Up @@ -263,6 +264,9 @@ def end(self, tag):

if self.test_suites[-1].date_created is None:
self.test_suites[-1].date_created = min([t.date_created for t in self.test_suites[-1].test_results])
else:
if self.test_suites[-1].date_created is None:
self.test_suites[-1].date_created = datetime.utcnow()
elif tag == 'testcase':
if self._current_result.result == Result.unknown:
# Default result is passing
Expand Down
6 changes: 6 additions & 0 deletions tests/changes/artifacts/test_xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_get_test_single_suite(xml, suite_name, duration):
assert suites[0].name == suite_name
assert suites[0].duration == duration
assert suites[0].result == Result.failed
assert suites[0].date_created is not None

# test the equivalence of get_tests and get_test_suites in the case where
# there is only one test suite, so that we can call get_tests directly
Expand Down Expand Up @@ -79,16 +80,19 @@ def test_get_test_suite_multiple():
assert suites[0].name is None
assert suites[0].duration is None
assert suites[0].result == Result.failed
assert suites[0].date_created is not None
assert len(suites[0].test_results) == 3

assert suites[1].name == 'suite2'
assert suites[1].duration == 77
assert suites[1].result == Result.failed
assert suites[1].date_created is not None
assert len(suites[1].test_results) == 3

assert suites[2].name == ''
assert suites[2].duration is None
assert suites[2].result == Result.failed
assert suites[2].date_created is not None
assert len(suites[2].test_results) == 3

tests = handler.aggregate_tests_from_suites(suites)
Expand Down Expand Up @@ -117,11 +121,13 @@ def test_get_test_suite_multiple_empty(xml, result):
assert suites[0].name == 'suite-name'
assert suites[0].duration is None
assert suites[0].result is result
assert suites[0].date_created is not None
assert len(suites[0].test_results) == 0

assert suites[1].name == 'null'
assert suites[1].duration is None
assert suites[1].result == Result.passed
assert suites[1].date_created is not None
assert len(suites[1].test_results) == 1


Expand Down

0 comments on commit 597880e

Please sign in to comment.