This repository was archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWeTestObj.py
63 lines (48 loc) · 1.62 KB
/
WeTestObj.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
"""
Author: Litian Liang, Tong Liu
Oct 26 10:57 AM
Documentation:
class AnyObject(WeTestObj): to create more classes
1: __init__(dummy = False)
use super().__init__() to construct any object
use super().__init__(True) to create dummy object
2: AnyObject must implement dum() method which calls
the dummy=True constructor to create a object with all
field variables. Give them any values, this method is
used for database type checking!
3: AnyObject().mangoSave() to save this object
4: Use AnyObject.mangoLoad(serial: int) to load a object back
"""
# project module
import Global
import WeTestExceptions
# import WeTestExceptions
# database module
from DataBase import DataBase
class WeTestObj:
'''
Base class for WeTest objects.
'''
mangodb = DataBase()
def __init__(self, dummy=False):
""" create a new wetest obj """
# version var
self._version = Global.CURR_VERSION
if not dummy:
# database var
self.serial = Global.NEXT_SERIAL
Global.NEXT_SERIAL += 1
else:
self.serial = -1
def checkVersion(self):
if self._version != Global.CURR_VERSION:
missedAttributes = self.__attributes - set(self.__dict__.keys())
raise WeTestExceptions.UpdateNeededException(missedAttributes)
def mangoUpdate(self):
return self.mangodb.update(self)
def mangoSave(self):
return self.mangodb.save(self)
@classmethod
def mangoLoad(cls, serial):
""" load obj from database """
return cls.mangodb.load(serial)