Mercurial > hg > orthanc-tests
annotate PerfsDb/Test.py @ 188:7d585263808b
new test: test_queries_hierarchy
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 08 Dec 2018 18:17:10 +0100 |
parents | ff939d07989f |
children | f42c10dab862 |
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 | |
164 | 12 self.repeatCount = 20 |
156 | 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() |
161 | 61 |
156 | 62 startTime = time.time() |
63 self.test() | |
64 endTime = time.time() | |
161 | 65 |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
66 self.afterEach() |
156 | 67 |
68 result.add((endTime - startTime) * 1000) | |
69 | |
158
df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents:
156
diff
changeset
|
70 self.afterAll() |
156 | 71 result.compute() |
72 return result | |
73 | |
74 def __str__(self): | |
75 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format( | |
76 name=self.name, | |
77 avg = self.averageTimeInMs, | |
78 min=self.minTimeInMs, | |
79 max=self.maxTimeInMs | |
80 ) |