~yellow/testrepository/integrate_worker_tagging

« back to all changes in this revision

Viewing changes to testrepository/tests/test_repository.py

  • Committer: Jonathan Lange
  • Date: 2011-11-17 15:45:10 UTC
  • mfrom: (138.2.38 delta-in-summary)
  • Revision ID: jml@canonical.com-20111117154510-wc1yrozx3jy9lqlu
Show a delta between the last run and the run before it on 'testr load',
'testr run' and 'testr last'.

Mostly achieved by extending the UI interface such that make_result now
accepts an optional previous test run.

Known Issues
============

 * AutoTimingTestResultDecorator inserts current clock data into the
   stream, which makes predictable testing of times hard. So in a couple
   of places I circumvented it.

 * AutoTimingTestResultDecorator causes 'testr last' to report a
   different time to 'testr load' for the same run (generally ~0.1s
   longer). This means that the time delta is a bit useless. Removing
   the AutoTimingTestResultDecorator fixes this. Haven't dug into
   exactly why.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
"""Tests for Repository support logic and the Repository contract."""
16
16
 
17
 
import datetime
 
17
from datetime import (
 
18
    datetime,
 
19
    timedelta,
 
20
    )
18
21
import doctest
19
22
 
20
23
from subunit import iso8601
25
28
    PlaceHolder,
26
29
    TestResult,
27
30
    )
 
31
from testtools.testresult.doubles import ExtendedTestResult
28
32
from testtools.matchers import DocTestMatches, raises
29
33
 
30
34
from testrepository import repository
31
35
from testrepository.repository import file, memory
32
 
from testrepository.tests import ResourcedTestCase
 
36
from testrepository.tests import (
 
37
    ResourcedTestCase,
 
38
    Wildcard,
 
39
    )
33
40
from testrepository.tests.stubpackage import (
34
41
    TempDirResource,
35
42
    )
107
114
 
108
115
def run_timed(id, duration, result):
109
116
    """Make and run a test taking duration seconds."""
110
 
    start = datetime.datetime.now(tz=iso8601.Utc())
 
117
    start = datetime.now(tz=iso8601.Utc())
111
118
    result.time(start)
112
119
    test = make_test(id, True)
113
120
    result.startTest(test)
114
 
    result.time(start + datetime.timedelta(seconds=duration))
 
121
    result.time(start + timedelta(seconds=duration))
115
122
    result.addSuccess(test)
116
123
    result.stopTest(test)
117
124
 
287
294
        run = repo.get_test_run(inserted)
288
295
        self.assertNotEqual(None, run)
289
296
 
 
297
    def test_get_latest_run(self):
 
298
        repo = self.repo_impl.initialise(self.sample_url)
 
299
        result = repo.get_inserter()
 
300
        result.startTestRun()
 
301
        inserted = result.stopTestRun()
 
302
        run = repo.get_latest_run()
 
303
        self.assertEqual(inserted, run.get_id())
 
304
 
 
305
    def test_get_latest_run_empty_repo(self):
 
306
        repo = self.repo_impl.initialise(self.sample_url)
 
307
        self.assertRaises(KeyError, repo.get_latest_run)
 
308
 
 
309
    def test_get_test_run_get_id(self):
 
310
        repo = self.repo_impl.initialise(self.sample_url)
 
311
        result = repo.get_inserter()
 
312
        result.startTestRun()
 
313
        inserted = result.stopTestRun()
 
314
        run = repo.get_test_run(inserted)
 
315
        self.assertEqual(inserted, run.get_id())
 
316
 
 
317
    def test_get_test_run_preserves_time(self):
 
318
        # The test run outputs the time events that it received.
 
319
        now = datetime(2001, 1, 1, 0, 0, 0, tzinfo=iso8601.Utc())
 
320
        second = timedelta(seconds=1)
 
321
        repo = self.repo_impl.initialise(self.sample_url)
 
322
        test = make_test(self.getUniqueString(), True)
 
323
        result = repo.get_inserter()
 
324
        result.startTestRun()
 
325
        result.time(now)
 
326
        result.startTest(test)
 
327
        result.time(now + 1 * second)
 
328
        result.addSuccess(test)
 
329
        result.stopTest(test)
 
330
        inserted = result.stopTestRun()
 
331
        run = repo.get_test_run(inserted)
 
332
        result = ExtendedTestResult()
 
333
        run.get_test().run(result)
 
334
        self.assertEqual(
 
335
            result._events,
 
336
            [('time', Wildcard), # XXX: Auto-timer inserts clock time
 
337
             ('time', now),
 
338
             ('startTest', Wildcard),
 
339
             ('time', now + 1 * second),
 
340
             ('addSuccess', Wildcard),
 
341
             ('stopTest', Wildcard),
 
342
             ])
 
343
 
 
344
    def test_get_failing_get_id(self):
 
345
        repo = self.repo_impl.initialise(self.sample_url)
 
346
        result = repo.get_inserter()
 
347
        result.startTestRun()
 
348
        result.stopTestRun()
 
349
        run = repo.get_failing()
 
350
        self.assertEqual(None, run.get_id())
 
351
 
290
352
    def test_get_subunit_from_test_run(self):
291
353
        repo = self.repo_impl.initialise(self.sample_url)
292
354
        result = repo.get_inserter()