~benji/testrepository/buildoutified

« back to all changes in this revision

Viewing changes to testrepository/repository/file.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:
33
33
    AbstractTestRun,
34
34
    RepositoryNotFound,
35
35
    )
 
36
from testrepository.utils import timedelta_to_seconds
36
37
 
37
38
 
38
39
def atomicish_rename(source, target):
120
121
                run_subunit_content = ''
121
122
            else:
122
123
                raise
123
 
        return _DiskRun(run_subunit_content)
 
124
        return _DiskRun(None, run_subunit_content)
124
125
 
125
126
    def get_test_run(self, run_id):
126
127
        run_subunit_content = file(
127
128
            os.path.join(self.base, str(run_id)), 'rb').read()
128
 
        return _DiskRun(run_subunit_content)
 
129
        return _DiskRun(run_id, run_subunit_content)
129
130
 
130
131
    def _get_inserter(self, partial):
131
132
        return _Inserter(self, partial)
164
165
class _DiskRun(AbstractTestRun):
165
166
    """A test run that was inserted into the repository."""
166
167
 
167
 
    def __init__(self, subunit_content):
 
168
    def __init__(self, run_id, subunit_content):
168
169
        """Create a _DiskRun with the content subunit_content."""
 
170
        self._run_id = run_id
169
171
        self._content = subunit_content
170
172
 
 
173
    def get_id(self):
 
174
        return self._run_id
 
175
 
171
176
    def get_subunit_stream(self):
172
177
        return StringIO(self._content)
173
178
 
228
233
        result = TestProtocolClient.stopTest(self, test)
229
234
        if None in (self._test_start, self._time):
230
235
            return result
231
 
        duration_delta = self._time - self._test_start
232
 
        duration_seconds = ((duration_delta.microseconds +
233
 
            (duration_delta.seconds + duration_delta.days * 24 * 3600)
234
 
            * 10**6) / float(10**6))
 
236
        duration_seconds = timedelta_to_seconds(self._time - self._test_start)
235
237
        self._times[test.id()] = str(duration_seconds)
236
238
        return result
237
239