Mercurial > hg > orthanc-tests
comparison PerfsDb/Test.py @ 156:f1a75985caa8
first Db test framework - work in progress
author | am@osimis.io |
---|---|
date | Thu, 16 Aug 2018 17:13:32 +0200 |
parents | |
children | df1f9946571c |
comparison
equal
deleted
inserted
replaced
155:e0996602b306 | 156:f1a75985caa8 |
---|---|
1 import time | |
2 import statistics | |
3 from orthancRestApi import OrthancClient | |
4 | |
5 from TestResult import TestResult | |
6 | |
7 class Test: | |
8 | |
9 def __init__(self, name: str): | |
10 self.name = name | |
11 self._orthanc = None | |
12 self.repeatCount = 10 | |
13 | |
14 def setOrthancClient(self, orthanc: OrthancClient): | |
15 self._orthanc = orthanc | |
16 | |
17 def setRepeatCount(self, repeatCount: int): | |
18 self.repeatCount = repeatCount | |
19 | |
20 def prepare(self): | |
21 """ | |
22 Code to execute before the execution of a test; i.e: upload a file (not including in timings) | |
23 """ | |
24 pass | |
25 | |
26 def test(self): | |
27 """ | |
28 Code whose execution time will be measured | |
29 """ | |
30 pass | |
31 | |
32 def cleanup(self): | |
33 """ | |
34 Code to execute after the execution of a test; i.e: remove an instance (not including in timings) | |
35 """ | |
36 pass | |
37 | |
38 def run(self) -> TestResult: | |
39 result = TestResult(self.name) | |
40 | |
41 for i in range(0, self.repeatCount): | |
42 self.prepare() | |
43 startTime = time.time() | |
44 self.test() | |
45 endTime = time.time() | |
46 self.cleanup() | |
47 | |
48 result.add((endTime - startTime) * 1000) | |
49 | |
50 result.compute() | |
51 return result | |
52 | |
53 def __str__(self): | |
54 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format( | |
55 name=self.name, | |
56 avg = self.averageTimeInMs, | |
57 min=self.minTimeInMs, | |
58 max=self.maxTimeInMs | |
59 ) |