Add tests for timestamps, and add support for 'exists'.
authorThomi Richards <thomi.richards@canonical.com>
Mon, 18 Nov 2013 20:34:26 +0000 (09:34 +1300)
committerThomi Richards <thomi.richards@canonical.com>
Mon, 18 Nov 2013 20:34:26 +0000 (09:34 +1300)
python/subunit/_output.py
python/subunit/tests/test_output_filter.py

index 9b467c11231e8079f20ae85ac0c507397e7886fb..4889e6fe0a60a4f23e5367d519b0bca30ab75aa7 100644 (file)
@@ -43,17 +43,38 @@ def parse_arguments(args=None):
         identifies this test.""")
     sub_parsers = parser.add_subparsers(dest="action")
 
-    parser_start = sub_parsers.add_parser("start", help="Start a test.",
-        parents=[common_args])
+    final_state = "This is a final action: No more actions may be generated " \
+        "for this test id after this one."
 
-    parser_pass = sub_parsers.add_parser("pass", help="Pass a test.",
-        parents=[common_args])
+    parser_start = sub_parsers.add_parser(
+        "start",
+        help="Start a test.",
+        parents=[common_args]
+    )
+
+    parser_pass = sub_parsers.add_parser(
+        "pass",
+        help="Pass a test. " + final_state,
+        parents=[common_args]
+    )
 
-    parser_fail = sub_parsers.add_parser("fail", help="Fail a test.",
-        parents=[common_args])
+    parser_fail = sub_parsers.add_parser(
+        "fail",
+        help="Fail a test. " + final_state,
+        parents=[common_args]
+    )
 
-    parser_skip = sub_parsers.add_parser("skip", help="Skip a test.",
-        parents=[common_args])
+    parser_skip = sub_parsers.add_parser(
+        "skip",
+        help="Skip a test. " + final_state,
+        parents=[common_args]
+    )
+
+    parser_exists = sub_parsers.add_parser(
+        "exists",
+        help="Marks a test as existing. " + final_state,
+        parents=[common_args]
+    )
 
     return parser.parse_args(args)
 
index fb56057ed3ecc4a8ddd378bc1a21a9431d3bbe0c..40314498e9fb42de07614bdae7079df538fd452d 100644 (file)
@@ -18,6 +18,7 @@
 from io import BytesIO
 
 from collections import namedtuple
+import datetime
 from testtools import TestCase
 from testtools.matchers import (
     Equals,
@@ -31,7 +32,9 @@ from subunit._output import (
     generate_bytestream,
     parse_arguments,
     translate_command_name,
+    utc,
 )
+import subunit._output as _o
 
 class OutputFilterArgumentTests(TestCase):
 
@@ -55,6 +58,9 @@ class OutputFilterArgumentTests(TestCase):
     def test_can_parse_skip_test(self):
         self._test_command('skip', self.getUniqueString())
 
+    def test_can_parse_exists(self):
+        self._test_command('exists', self.getUniqueString())
+
     def test_command_translation(self):
         self.assertThat(translate_command_name('start'), Equals('inprogress'))
         self.assertThat(translate_command_name('pass'), Equals('success'))
@@ -64,6 +70,12 @@ class OutputFilterArgumentTests(TestCase):
 
 class ByteStreamCompatibilityTests(TestCase):
 
+    _dummy_timestamp = datetime.datetime(2013, 1, 1, 0, 0, 0, 0, utc)
+
+    def setUp(self):
+        super(ByteStreamCompatibilityTests, self).setUp()
+        self.patch(_o, 'create_timestamp', lambda: self._dummy_timestamp)
+
     def _get_result_for(self, *commands):
         """Get a result object from *commands.
 
@@ -94,7 +106,12 @@ class ByteStreamCompatibilityTests(TestCase):
 
         self.assertThat(
             result._events[0],
-            MatchesCall(call='status', test_id='foo', test_status='inprogress')
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_status='inprogress',
+                timestamp=self._dummy_timestamp,
+            )
         )
 
     def test_pass_generates_success(self):
@@ -104,7 +121,12 @@ class ByteStreamCompatibilityTests(TestCase):
 
         self.assertThat(
             result._events[0],
-            MatchesCall(call='status', test_id='foo', test_status='success')
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_status='success',
+                timestamp=self._dummy_timestamp,
+            )
         )
 
     def test_fail_generates_fail(self):
@@ -114,7 +136,12 @@ class ByteStreamCompatibilityTests(TestCase):
 
         self.assertThat(
             result._events[0],
-            MatchesCall(call='status', test_id='foo', test_status='fail')
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_status='fail',
+                timestamp=self._dummy_timestamp,
+            )
         )
 
     def test_skip_generates_skip(self):
@@ -124,7 +151,27 @@ class ByteStreamCompatibilityTests(TestCase):
 
         self.assertThat(
             result._events[0],
-            MatchesCall(call='status', test_id='foo', test_status='skip')
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_status='skip',
+                timestamp=self._dummy_timestamp,
+            )
+        )
+
+    def test_exists_generates_exists(self):
+        result = self._get_result_for(
+            ['exists', 'foo'],
+        )
+
+        self.assertThat(
+            result._events[0],
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_status='exists',
+                timestamp=self._dummy_timestamp,
+            )
         )