summaryrefslogtreecommitdiff
path: root/python/subunit/tests
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2021-06-10 13:47:44 -0400
committerGitHub <noreply@github.com>2021-06-10 13:47:44 -0400
commit0dd0bec5fa4b5a6ff32b76224cfe46e2e86ac482 (patch)
tree22799c84bef57eeb6a565a27697ddfc17d35d343 /python/subunit/tests
parentbbaeb704a3e7f6a4cc78cecc44f12f6077b33fc7 (diff)
parent1dafb884e47f5fc26232672b01c2a9574577e7be (diff)
downloadsubunit-git-0dd0bec5fa4b5a6ff32b76224cfe46e2e86ac482.tar.gz
Merge branch 'master' into fix-filter-entrypoints
Diffstat (limited to 'python/subunit/tests')
-rw-r--r--python/subunit/tests/test_output_filter.py63
-rw-r--r--python/subunit/tests/test_subunit_tags.py2
-rw-r--r--python/subunit/tests/test_test_protocol.py42
3 files changed, 92 insertions, 15 deletions
diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py
index 0f61ac5..587fd06 100644
--- a/python/subunit/tests/test_output_filter.py
+++ b/python/subunit/tests/test_output_filter.py
@@ -472,6 +472,69 @@ class StatusStreamResultTests(TestCase):
])
)
+class TimeStampTests(TestCase):
+ scenarios = [
+ (s, dict(status=s, option='--' + s)) for s in _FINAL_ACTIONS
+ ]
+
+ _dummy_timestamp = datetime.datetime(1914, 6, 28, 10, 45, 2, 0, UTC)
+
+ def setUp(self):
+ super(TimeStampTests, self).setUp()
+ self.patch(_o, 'create_timestamp', lambda: self._dummy_timestamp)
+ self.test_id = self.getUniqueString()
+
+ def test_no_timestamps(self):
+ result = get_result_for([self.option, self.test_id, f.name])
+ self.assertThat(
+ result._events,
+ MatchesListwise([
+ MatchesStatusCall(call='startTestRun'),
+ MatchesStatusCall(test_id=self.test_id, timestamp=self._dummy_timestamp),
+ MatchesStatusCall(test_id=self.test_id, timestamp=None),
+ MatchesStatusCall(call='stopTestRun'),
+ ]))
+
+ def test_only_start_timestamp(self):
+ timestamp = datetime.datetime.utcnow()
+ result = get_result_for([self.option, self.test_id, f.name,
+ '--start-time', timestamp.isoformat()])
+ self.assertThat(
+ result._events,
+ MatchesListwise([
+ MatchesStatusCall(call='startTestRun'),
+ MatchesStatusCall(test_id=self.test_id, timestamp=timestamp),
+ MatchesStatusCall(test_id=self.test_id, timestamp=None),
+ MatchesStatusCall(call='stopTestRun'),
+ ]))
+
+ def test_only_stop_timestamp(self):
+ timestamp = datetime.datetime.utcnow()
+ result = get_result_for([self.option, self.test_id, f.name,
+ '--stop-time', timestamp.isoformat()])
+ self.assertThat(
+ result._events,
+ MatchesListwise([
+ MatchesStatusCall(call='startTestRun'),
+ MatchesStatusCall(test_id=self.test_id, timestamp=self._dummy_timestamp),
+ MatchesStatusCall(test_id=self.test_id, timestamp=timestamp),
+ MatchesStatusCall(call='stopTestRun'),
+ ]))
+
+ def test_start_and_stop_timestamp(self):
+ timestamp_start = datetime.datetime.utcnow()
+ timestamp_stop = timestamp_start + datetime.timedelta(minutes=5)
+ result = get_result_for([self.option, self.test_id, f.name,
+ '--start-time', timestamp_start.isoformat(),
+ '--stop-time', timestamp_stop.isoformat()])
+ self.assertThat(
+ result._events,
+ MatchesListwise([
+ MatchesStatusCall(call='startTestRun'),
+ MatchesStatusCall(test_id=self.test_id, timestamp=timestamp_start),
+ MatchesStatusCall(test_id=self.test_id, timestamp=timestamp_stop),
+ MatchesStatusCall(call='stopTestRun'),
+ ]))
class FileDataTests(TestCase):
diff --git a/python/subunit/tests/test_subunit_tags.py b/python/subunit/tests/test_subunit_tags.py
index a16edc1..3722eb2 100644
--- a/python/subunit/tests/test_subunit_tags.py
+++ b/python/subunit/tests/test_subunit_tags.py
@@ -56,6 +56,8 @@ class TestSubUnitTags(testtools.TestCase):
b'\x83\x1b\x04test\x03\x03bar\x03foo\x04quux\xd2\x18\x1bC',
b'\xb3)\x82\x17\x04test\x02\x03foo\x04quux\xa6\xe1\xde\xec\xb3)'
b'\x83\x1b\x04test\x03\x03foo\x03bar\x04quux:\x05e\x80',
+ b'\xb3)\x82\x17\x04test\x02\x03foo\x04quux\xa6\xe1\xde\xec\xb3)'
+ b'\x83\x1b\x04test\x03\x04quux\x03foo\x03bar\xaf\xbd\x9d\xd6',
]
stream = subunit.StreamResultToBytes(self.original)
stream.status(
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index 7427b12..86aa4a6 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -16,10 +16,9 @@
import datetime
import io
-import unittest2 as unittest
import os
-import sys
import tempfile
+import unittest
from testtools import PlaceHolder, skipIf, TestCase, TestResult
from testtools.compat import _b, _u, BytesIO
@@ -38,6 +37,7 @@ except ImportError:
ExtendedTestResult,
)
from testtools.matchers import Contains
+from testtools.testcase import six
import subunit
from subunit.tests import (
@@ -48,7 +48,7 @@ from subunit.tests import (
import subunit.iso8601 as iso8601
-tb_prelude = "Traceback (most recent call last):\n"
+tb_prelude = "Traceback (most recent call last):\n"
def details_to_str(details):
@@ -60,7 +60,7 @@ class TestHelpers(TestCase):
fd, file_path = tempfile.mkstemp()
self.addCleanup(os.remove, file_path)
fake_file = os.fdopen(fd, 'r')
- if sys.version_info > (3, 0):
+ if six.PY3:
self.assertEqual(fake_file.buffer,
subunit._unwrap_text(fake_file))
else:
@@ -70,7 +70,7 @@ class TestHelpers(TestCase):
fd, file_path = tempfile.mkstemp()
self.addCleanup(os.remove, file_path)
fake_file = os.fdopen(fd, 'w')
- if sys.version_info > (3, 0):
+ if six.PY3:
self.assertEqual(fake_file.buffer,
subunit._unwrap_text(fake_file))
else:
@@ -152,13 +152,20 @@ class TestTestProtocolServerPipe(unittest.TestCase):
protocol.readFrom(pipe)
bing = subunit.RemotedTestCase("bing crosby")
an_error = subunit.RemotedTestCase("an error")
- self.assertEqual(
- client.errors,
- [(an_error, tb_prelude + _remote_exception_repr + '\n')])
- self.assertEqual(
- client.failures,
- [(bing, tb_prelude + _remote_exception_repr + ": "
- + details_to_str({'traceback': text_content(traceback)}) + "\n")])
+ if six.PY3:
+ self.assertEqual(client.errors,
+ [(an_error, _remote_exception_repr + '\n')])
+ self.assertEqual(
+ client.failures,
+ [(bing, _remote_exception_repr + ": "
+ + details_to_str({'traceback': text_content(traceback)}) + "\n")])
+ else:
+ self.assertEqual(client.errors,
+ [(an_error, '_StringException\n')])
+ self.assertEqual(
+ client.failures,
+ [(bing, "_StringException: "
+ + details_to_str({'traceback': text_content(traceback)}) + "\n")])
self.assertEqual(client.testsRun, 3)
def test_non_test_characters_forwarded_immediately(self):
@@ -1012,9 +1019,14 @@ class TestRemotedTestCase(unittest.TestCase):
"'A test description'>", "%r" % test)
result = unittest.TestResult()
test.run(result)
- self.assertEqual([(test, tb_prelude + _remote_exception_repr + ": "
- "Cannot run RemotedTestCases.\n\n")],
- result.errors)
+ if six.PY3:
+ self.assertEqual([(test, _remote_exception_repr + ': ' +
+ "Cannot run RemotedTestCases.\n\n")],
+ result.errors)
+ else:
+ self.assertEqual([(test, "_StringException: " +
+ "Cannot run RemotedTestCases.\n\n")],
+ result.errors)
self.assertEqual(1, result.testsRun)
another_test = subunit.RemotedTestCase("A test description")
self.assertEqual(test, another_test)