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
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12 self.repeatCount = 10
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()
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
61 startTime = time.time()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
62 self.test()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
65
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
66 result.add((endTime - startTime) * 1000)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
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
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
69 result.compute()
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
70 return result
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
71
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
72 def __str__(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
73 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
74 name=self.name,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
75 avg = self.averageTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
76 min=self.minTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
77 max=self.maxTimeInMs
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
78 )