-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
140 lines (112 loc) · 4.11 KB
/
debug.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from nasse.timer import Timer
from pymongo import MongoClient
from mongo_secret import URI
from yuno.client import YunoClient
from yuno.objects import YunoDict
from yuno.database import YunoDatabase
from yuno.collection import YunoCollection
class CustomObject(YunoDict):
def __init__(self, _id, collection, field, data=None) -> None:
print("Initializing CustomObject")
super().__init__(_id, collection, field, data)
hello: str = "world"
do_not_exist: str = "this does not exist"
class CustomDocument(YunoDict):
def __init__(self, _id, collection, field, data=None) -> None:
print("Initializing CustomDocument")
super().__init__(_id, collection, field, data)
__lazy__ = ["hello"]
hello: str
world: str = "heyhey"
a: CustomObject
class CustomCollection(YunoCollection):
a: CustomDocument
def __init__(self, database, name: str = "__yuno_test__") -> None:
print("Initializing CustomCollection")
super().__init__(database, name)
class CustomDatabase(YunoDatabase):
__yuno_test__: CustomCollection
def __init__(self, client: MongoClient, name: str = "__yunot_test__") -> None:
print("Initializing CustomDatabase")
super().__init__(client, name)
class CustomClient(YunoClient):
test_database: CustomDatabase
def __init__(self, uri: str):
print("Initializing CustomClient")
super().__init__(uri)
with Timer() as t:
test_client = CustomClient(URI)
print(test_client)
test_database = test_client.test_database
test_collection = test_database.__yuno_test__
test_document = test_collection.a
test_object = test_document.a
print("test_collection.count():", test_collection.count())
print('"a" in test_collection:', "a" in test_collection)
print('"n/a" in test_collection:', "n/a" in test_collection)
print("test_collection.find():", test_collection.find())
print("test_collection.find(defered=True):", test_collection.find(defered=True))
print("list(test_collection.find(defered=True))", list(test_collection.find(defered=True)))
print("test_document:", test_document)
print("test_document.hello:", test_document.hello)
print("test_document.world:", test_document.world)
print("test_document.a:", test_document.a)
print("test_document.a.hello:", test_document.a.hello)
print("test_document.a.do_not_exist:", test_document.a.do_not_exist)
print("It took", t.time, "sec. to execute")
# print(CustomDatabase(client, "test_database").__yuno_test__.a.world)
# test_collection = CustomDatabase(client, "test_database").__yuno_test__
# test_collection = database.__yuno_test__
# print(test_collection.find())
"""
with Timer() as timer:
class Account(YunoDocument):
username: str = "default_username"
password: str = "default_password"
list_test: list[int] = []
dict_test: dict
class TestCollection(YunoCollection):
a: Account
test_collection = TestCollection(database, "account")
print(test_collection.find())
print(test_collection.find(username="test"))
print(test_collection.find(username="hello"))
a = Account(collection, _id="a")
# print(a.username)
a.username = "hello"
# print(a)
# print(a.username)
# print(a.list_test)
a.list_test.extend([1, 2, 3, 4, 5, 6])
# print(a.list_test)
a.list_test.pop(2)
# print(a.list_test)
a.list_test.remove(1)
# print(a.list_test)
a.list_test.reverse()
# print(a.list_test)
a.list_test.sort()
# print(a.list_test)
a.list_test[2] = 4
# print(a.list_test)
a.list_test.clear()
# print(a.list_test)
# print(a.dict_test)
a.dict_test.update({"a": 1, "b": 2, "c": 3})
# print(a.dict_test)
a.dict_test.pop("a")
# print(a.dict_test)
a.dict_test.popitem()
# print(a.dict_test)
# print(a.dict_test.b)
# print(a.dict_test["b"])
a.dict_test.a = 1
# print(a.dict_test)
a.dict_test["c"] = 3
# print(a.dict_test)
# print(a.dict_test.items())
# print(a.dict_test.keys())
# print("c" in a.dict_test)
# print(a.dict_test.__contains__("c"))
print(timer.time)
"""