Mercurial > hg > orthanc-tests
annotate PerfsDb/Test.py @ 158:df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 11:58:26 +0200 |
parents | f1a75985caa8 |
children | 27b3b0df5f90 |
rev | line source |
---|---|
156 | 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 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
20 def beforeAll(self): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
21 """ |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
22 Code to execute before the execution of all repetitions of a test; i.e: upload a file. |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
23 This code is not included in timings |
156 | 24 """ |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
25 pass |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
26 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
27 def beforeEach(self): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
28 """ |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
29 Code to execute before the execution of each repetition of a test. |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
30 This code is not included in timings |
156 | 31 """ |
32 pass | |
33 | |
34 def test(self): | |
35 """ | |
36 Code whose execution time will be measured | |
37 """ | |
38 pass | |
39 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
40 def afterEach(self): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
41 """ |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
42 Code to execute after the execution of each repetition of a test. |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
43 This code is not included in timings |
156 | 44 """ |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
45 pass |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
46 |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
47 def afterAll(self): |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
48 """ |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
49 Code to execute after the execution of all repetitions of a test. |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
50 This code is not included in timings |
156 | 51 """ |
52 pass | |
53 | |
54 def run(self) -> TestResult: | |
55 result = TestResult(self.name) | |
56 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
57 self.beforeAll() |
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
58 |
156 | 59 for i in range(0, self.repeatCount): |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
60 self.beforeEach() |
156 | 61 startTime = time.time() |
62 self.test() | |
63 endTime = time.time() | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
64 self.afterEach() |
156 | 65 |
66 result.add((endTime - startTime) * 1000) | |
67 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
68 self.afterAll() |
156 | 69 result.compute() |
70 return result | |
71 | |
72 def __str__(self): | |
73 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format( | |
74 name=self.name, | |
75 avg = self.averageTimeInMs, | |
76 min=self.minTimeInMs, | |
77 max=self.maxTimeInMs | |
78 ) |