-
Notifications
You must be signed in to change notification settings - Fork 0
/
testlib.py
122 lines (89 loc) · 2.94 KB
/
testlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Classes for mock testing"""
import tkinter
import datetime
import pandas as pd
import docker
# exceptions
class RootDestroyedException(BaseException):
pass
# mock tkinter
class mockFrame(tkinter.Frame):
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.master = master
self.grid = None
self.schedule = pd.DataFrame()
self.credentials = None
self.container = None
self.status = tkinter.StringVar()
self.lbl_StreamSpeed = tkinter.Label(self)
self.streamSpeed = tkinter.StringVar()
self.nowDT = datetime.datetime(year=1900, month=12, day=5)
self.streamActive = False
self.imageName = "asdf"
self.pathMap = None
def after(*args):
"""Override after method to avoid repeated calling"""
pass
class mockRoot:
def destroy(self):
raise RootDestroyedException
# mock docker
class mockContainer:
def __init__(self, log=None, status="created", name="asdf"):
self.log = log
self.index = None
self.engine = None
self.status = status
self.image = name
def logs(self, tail=1):
return self.log
def stop(self):
self.engine.containers.containerList.pop(self.index)
class mockContainers:
def __init__(self, name="asdf"):
self.containerList = []
self.engine = None
self.image = name
def list(self):
return self.containerList
def run(self, *args, **kwargs):
newCont = mockContainer(
b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s"
b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s"
b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s"
b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s"
)
self.containerList.append(newCont)
newCont.index = self.containerList.index(newCont)
newCont.engine = self.engine
return newCont
def __len__(self):
return len(self.containerList)
class mockImages:
def __init__(self, good=True, imageList=None) -> None:
self.good = good
self.imageList = None
def get(self, imageName):
if not self.good:
raise docker.errors.ImageNotFound("asdf")
else:
return self.imageList
class mockEngine:
def __init__(self, images="Good", version="Good", containers=None) -> None:
self.containers = mockContainers()
if containers is not None:
self.containers.containerList = containers
self.containers.engine = self
self.imagesInst = images
self.versionInt = version
def version(self):
"""Dummy call for version"""
if self.versionInt != "Good":
raise AssertionError
@property
def images(self):
return self.imagesInst
# misc functions
def raiseAssertion(*args, **kwargs):
raise AssertionError