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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import time
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 import statistics
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
3 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
4
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5 from TestResult import TestResult
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7 class Test:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 def __init__(self, name: str):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 self.name = name
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 self._orthanc = None
164
ff939d07989f saving results
am@osimis.io
parents: 161
diff changeset
12 self.repeatCount = 20
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 def setOrthancClient(self, orthanc: OrthancClient):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 self._orthanc = orthanc
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
17 def setRepeatCount(self, repeatCount: int):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18 self.repeatCount = repeatCount
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
31 """
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
32 pass
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
33
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
34 def test(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35 """
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
36 Code whose execution time will be measured
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37 """
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38 pass
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
51 """
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
52 pass
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
53
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
54 def run(self) -> TestResult:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
55 result = TestResult(self.name)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
61
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
62 startTime = time.time()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
63 self.test()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
64 endTime = time.time()
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
67
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
68 result.add((endTime - startTime) * 1000)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71 result.compute()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72 return result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
73
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
74 def __str__(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
75 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format(
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
76 name=self.name,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
77 avg = self.averageTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
78 min=self.minTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
79 max=self.maxTimeInMs
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
80 )