Exemple #1
0
 def test_calling_time_None_enables_automatic_time(self):
     time = datetime.datetime(2009, 10, 11, 12, 13, 14, 15, iso8601.Utc())
     self.result.time(time)
     self.assertEqual(1, len(self.decorated._calls))
     self.assertEqual(time, self.decorated._calls[0])
     # Calling None passes the None through, in case other results care.
     self.result.time(None)
     self.assertEqual(2, len(self.decorated._calls))
     self.assertEqual(None, self.decorated._calls[1])
     # Calling other methods doesn't generate an automatic time event.
     self.result.startTest(self)
     self.assertEqual(3, len(self.decorated._calls))
     self.assertNotEqual(None, self.decorated._calls[2])
def run_timed(id, duration, result, enumeration=False):
    """Make and run a test taking duration seconds.
    
    :param enumeration: If True, don't run, just enumerate.
    """
    start = datetime.now(tz=iso8601.Utc())
    if enumeration:
        result.status(test_id=id, test_status='exists', timestamp=start)
    else:
        result.status(test_id=id, test_status='inprogress', timestamp=start)
        result.status(test_id=id,
                      test_status='success',
                      timestamp=start + timedelta(seconds=duration))
Exemple #3
0
 def run(self, result):
     time = datetime.datetime.utcnow().replace(tzinfo=iso8601.Utc())
     result.time(time)
     result.startTest(self)
     try:
         outcome = self._get_outcome()
         details = self._get_details()
         # Only provide a duration IFF outcome == 'addSuccess' - the main
         # parser claims bogus results otherwise: in that case emit time as
         # zero perhaps.
         if outcome == 'addSuccess':
             duration = float(node_as_text(self._case, 'duration'))
             duration = duration * 1000000
             timedelta = datetime.timedelta(0, 0, duration)
             time = time + timedelta
             result.time(time)
         getattr(result, outcome)(self, details=details)
     finally:
         result.stopTest(self)
 def test_load_timed_run(self):
     buffer = BytesIO()
     stream = subunit.StreamResultToBytes(buffer)
     time = datetime(2011, 1, 1, 0, 0, 1, tzinfo=iso8601.Utc())
     stream.status(test_id='foo', test_status='inprogress', timestamp=time)
     stream.status(test_id='foo',
                   test_status='success',
                   timestamp=time + timedelta(seconds=2))
     timed_bytes = buffer.getvalue()
     ui = UI([('subunit', timed_bytes)])
     cmd = load.load(ui)
     ui.set_command(cmd)
     cmd.repository_factory = memory.RepositoryFactory()
     cmd.repository_factory.initialise(ui.here)
     self.assertEqual(0, cmd.execute())
     # Note that the time here is 2.0, the difference between first and
     # second time: directives. That's because 'load' uses a
     # ThreadsafeForwardingResult (via ConcurrentTestSuite) that suppresses
     # time information not involved in the start or stop of a test.
     self.assertEqual(
         [('summary', True, 1, None, 2.0, None, [('id', 0, None)])],
         ui.outputs[1:])
Exemple #5
0
 def _before_event(self):
     time = self._time
     if time is not None:
         return
     time = datetime.datetime.utcnow().replace(tzinfo=iso8601.Utc())
     self.decorated.time(time)
SIGNATURE = b'\xb3'
FMT_8 = '>B'
FMT_16 = '>H'
FMT_24 = '>HB'
FMT_32 = '>I'
FMT_TIMESTAMP = '>II'
FLAG_TEST_ID = 0x0800
FLAG_ROUTE_CODE = 0x0400
FLAG_TIMESTAMP = 0x0200
FLAG_RUNNABLE = 0x0100
FLAG_TAGS = 0x0080
FLAG_MIME_TYPE = 0x0020
FLAG_EOF = 0x0010
FLAG_FILE_CONTENT = 0x0040
EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=iso8601.Utc())
NUL_ELEMENT = b'\0'[0]
# Contains True for types for which 'nul in thing' falsely returns false.
_nul_test_broken = {}
_PY3 = (sys.version_info >= (3, ))


def has_nul(buffer_or_bytes):
    """Return True if a null byte is present in buffer_or_bytes."""
    # Simple "if NUL_ELEMENT in utf8_bytes:" fails on Python 3.1 and 3.2 with
    # memoryviews. See https://bugs.launchpad.net/subunit/+bug/1216246
    buffer_type = type(buffer_or_bytes)
    broken = _nul_test_broken.get(buffer_type)
    if broken is None:
        reference = buffer_type(b'\0')
        broken = not NUL_ELEMENT in reference
 def test_load_second_run(self):
     # If there's a previous run in the database, then show information
     # about the high level differences in the test run: how many more
     # tests, how many more failures, how much longer it takes.
     if v2_avail:
         buffer = BytesIO()
         stream = subunit.StreamResultToBytes(buffer)
         time = datetime(2011, 1, 2, 0, 0, 1, tzinfo=iso8601.Utc())
         stream.status(test_id='foo',
                       test_status='inprogress',
                       timestamp=time)
         stream.status(test_id='foo',
                       test_status='fail',
                       timestamp=time + timedelta(seconds=2))
         stream.status(test_id='bar',
                       test_status='inprogress',
                       timestamp=time + timedelta(seconds=4))
         stream.status(test_id='bar',
                       test_status='fail',
                       timestamp=time + timedelta(seconds=6))
         timed_bytes = buffer.getvalue()
     else:
         timed_bytes = _b('time: 2011-01-02 00:00:01.000000Z\n'
                          'test: foo\n'
                          'time: 2011-01-02 00:00:03.000000Z\n'
                          'error: foo\n'
                          'time: 2011-01-02 00:00:05.000000Z\n'
                          'test: bar\n'
                          'time: 2011-01-02 00:00:07.000000Z\n'
                          'error: bar\n')
     ui = UI([('subunit', timed_bytes)])
     cmd = load.load(ui)
     ui.set_command(cmd)
     cmd.repository_factory = memory.RepositoryFactory()
     repo = cmd.repository_factory.initialise(ui.here)
     # XXX: Circumvent the AutoTimingTestResultDecorator so we can get
     # predictable times, rather than ones based on the system
     # clock. (Would normally expect to use repo.get_inserter())
     inserter = repo._get_inserter(False)
     # Insert a run with different results.
     inserter.startTestRun()
     inserter.status(test_id=self.id(),
                     test_status='inprogress',
                     timestamp=datetime(2011,
                                        1,
                                        1,
                                        0,
                                        0,
                                        1,
                                        tzinfo=iso8601.Utc()))
     inserter.status(test_id=self.id(),
                     test_status='fail',
                     timestamp=datetime(2011,
                                        1,
                                        1,
                                        0,
                                        0,
                                        10,
                                        tzinfo=iso8601.Utc()))
     inserter.stopTestRun()
     self.assertEqual(1, cmd.execute())
     self.assertEqual(
         [('summary', False, 2, 1, 6.0, -3.0, [('id', 1, None),
                                               ('failures', 2, 1)])],
         ui.outputs[1:])
Exemple #8
0
 def test_time(self):
     # Calling time() outputs a time signal immediately.
     self.protocol.time(
         datetime.datetime(2009, 10, 11, 12, 13, 14, 15, iso8601.Utc()))
     self.assertEqual(_b("time: 2009-10-11 12:13:14.000015Z\n"),
                      self.io.getvalue())