49 Function in charge of testing the add_variable function.
52 assert VI.add_variable(
"test1", 1, int, scope=SCOPE) == SUCCESS
53 with pytest.raises(TypeError):
54 VI.add_variable(
"test2", 1, str, scope=SCOPE)
55 assert VI.add_variable(
"test3",
"1", str, scope=SCOPE) == SUCCESS
56 assert SCOPE
in VI.variables
57 assert VI.variables[SCOPE][
"test1"] == {
"data": 1,
"type": int}
58 assert "test2" not in VI.variables[SCOPE]
59 assert VI.variables[SCOPE][
"test3"] == {
"data":
"1",
"type": str}
64 Function in charge of testing the update_variable function.
66 node1 = {
"data": 1,
"type": int}
67 node2 = {
"data":
"1",
"type": str}
68 node3 = {
"data":
"1",
"type": str}
76 with pytest.raises(ScopeError):
77 VI.update_variable(
"not_present", 1, int)
78 with pytest.raises(VariableNotFoundError):
79 VI.update_variable(
"not_present", 1, int, scope=SCOPE)
80 with pytest.raises(ScopeError):
81 VI.update_variable(
"test1", 1, int)
82 with pytest.raises(ScopeError):
83 VI.update_variable(
"test2", 1, str)
84 with pytest.raises(ScopeError):
85 VI.update_variable(
"test3",
"1", str)
86 assert VI.update_variable(
"test1", 1, int, scope=SCOPE) == SUCCESS
87 with pytest.raises(TypeError):
88 VI.update_variable(
"test2", 1, str, scope=SCOPE)
89 assert VI.update_variable(
"test3",
"1", str, scope=SCOPE) == SUCCESS
90 assert SCOPE
in VI.variables
91 assert "not_present" not in VI.variables[SCOPE]
92 assert VI.variables[SCOPE][
"test1"] == node1
93 assert VI.variables[SCOPE][
"test2"] == node2
94 assert VI.variables[SCOPE][
"test3"] == node3
99 Function in charge of testing the insert_or_update function.
103 "test4": {
"data":
"1",
"type": str},
104 "test5": {
"data":
"1",
"type": str}
107 assert VI.insert_or_update(
"test1", 1, int) == SUCCESS
108 with pytest.raises(TypeError):
109 VI.insert_or_update(
"test2", 1, str)
110 assert VI.insert_or_update(
"test3",
"1", str) == SUCCESS
111 assert VI.insert_or_update(
"test4",
"1", str) == SUCCESS
112 assert VI.insert_or_update(
"test5", 1.0, float) == SUCCESS
113 with pytest.raises(TypeError):
114 VI.insert_or_update(
"test5",
"1", int)
115 assert VI.insert_or_update(
"test1", 1, int, scope=SCOPE) == SUCCESS
116 with pytest.raises(TypeError):
117 VI.insert_or_update(
"test2", 1, str, scope=SCOPE)
118 assert VI.insert_or_update(
"test3",
"1", str, scope=SCOPE) == SUCCESS
119 assert VI.insert_or_update(
"test4",
"1", str, scope=SCOPE) == SUCCESS
120 with pytest.raises(TypeError):
121 VI.insert_or_update(
"test5",
"1", int, scope=SCOPE)
122 assert SCOPE
in VI.variables
123 assert VI.variables[SCOPE][
"test1"] == {
"data": 1,
"type": int}
124 assert "test2" not in VI.variables[SCOPE]
125 assert VI.variables[SCOPE][
"test3"] == {
"data":
"1",
"type": str}
126 assert VI.variables[SCOPE][
"test4"] == {
"data":
"1",
"type": str}
127 assert VI.variables[SCOPE][
"test5"] == {
"data":
"1",
"type": str}
128 assert "default_scope" in VI.variables
129 assert VI.variables[
"default_scope"][
"test1"] == {
"data": 1,
"type": int}
130 assert "test2" not in VI.variables[
"default_scope"]
131 assert VI.variables[
"default_scope"][
"test3"] == {
"data":
"1",
"type": str}
132 assert VI.variables[
"default_scope"][
"test4"] == {
"data":
"1",
"type": str}
133 assert VI.variables[
"default_scope"][
"test5"] == {
134 "data": 1.0,
"type": float
214 Function in charge of testing the remove_variable function.
218 "test": {
"data":
"1",
"type": str}
221 assert SCOPE
in VI.variables
222 with pytest.raises(ScopeError):
223 VI.remove_variable(
"test")
224 with pytest.raises(ScopeError):
225 VI.remove_variable(
"test")
226 with pytest.raises(ScopeError):
227 VI.remove_variable(
"test2")
228 assert VI.remove_variable(
"test", scope=SCOPE) == SUCCESS
229 with pytest.raises(VariableNotFoundError):
230 VI.remove_variable(
"test", scope=SCOPE)
231 with pytest.raises(VariableNotFoundError):
232 VI.remove_variable(
"test2", scope=SCOPE)
233 assert not VI.variables[SCOPE]
404 Function in charge of testing the sanitize_for_json function.
409 class SampleEmptyClass:
412 class SampleFuncClass:
416 class SampleMultyFuncClass:
420 def dummy(self) -> str:
429 "classes_initialised",
439 "test": {
"data":
"1",
"type": str},
440 "test2": {
"data": 1,
"type": int},
441 "test3": {
"data": 1.0,
"type": float}
444 "test": {
"data":
"1",
"type": str},
445 "test2": {
"data": 1,
"type": int},
446 "test3": {
"data": 1.0,
"type": float}
449 "test": {
"data":
"1",
"type": str},
450 "test2": {
"data": 1,
"type": int},
451 "test3": {
"data": 1.0,
"type": float}
455 "test2":
lambda x: x,
456 "test3":
lambda x: x,
460 "test": SampleEmptyClass,
461 "test2": SampleFuncClass,
462 "test3": SampleMultyFuncClass
465 "test": SampleEmptyClass(),
466 "test2": SampleFuncClass(),
467 "test3": SampleMultyFuncClass()
470 "test": open(
"test.tmp.txt",
"w", encoding=
'utf-8'),
471 "test2": open(
"test2.tmp.txt",
"w", encoding=
'utf-8'),
472 "test3": open(
"test3.tmp.txt",
"w", encoding=
'utf-8')
475 "test": complex(1, 1),
476 "test2": complex(1, 1),
477 "test3": complex(1, 1)
490 "test": (x
for x
in range(10)),
491 "test2": (x
for x
in range(10)),
492 "test3": (x
for x
in range(10))
495 VI.variables = scopes.copy()
496 scopes_cleaned = scopes.copy()
498 for i
in scopes_cleaned[node]:
499 for b
in scopes_cleaned[node][i]:
501 scopes_cleaned[node][i][b] = str(
502 scopes_cleaned[node][i][b])
504 for i
in scopes_cleaned[node]:
505 for b
in scopes_cleaned[node][i]:
507 scopes_cleaned[node][i][b] = str(
508 scopes_cleaned[node][i][b]
511 for i
in scopes_cleaned[node]:
512 scopes_cleaned[node][i] = str(
513 scopes_cleaned[node][i]
516 for i
in scopes_cleaned[node]:
517 scopes_cleaned[node][i] = str(
518 scopes_cleaned[node][i]
521 for i
in scopes_cleaned[node]:
522 scopes_cleaned[node][i] = str(
523 scopes_cleaned[node][i]
526 for i
in scopes_cleaned[node]:
527 scopes_cleaned[node][i] = str(
528 scopes_cleaned[node][i]
531 for i
in scopes_cleaned[node]:
532 scopes_cleaned[node][i] = str(
533 scopes_cleaned[node][i]
536 for i
in scopes_cleaned[node]:
537 scopes_cleaned[node][i] = list(
538 scopes_cleaned[node][i]
541 for i
in scopes_cleaned[node]:
542 scopes_cleaned[node][i] = base64.b64encode(
543 scopes_cleaned[node][i]
545 node = scope_list[10]
546 for i
in scopes_cleaned[node]:
547 scopes_cleaned[node][i] = str(
548 scopes_cleaned[node][i]
551 assert VI.sanitize_for_json(scopes) == scopes_cleaned
552 with pytest.raises(ScopeError):
553 VI.sanitize_for_json(data_or_scope=
"ThisIsNotAScope", use_scope=
True)
555 assert VI.sanitize_for_json(
556 data_or_scope=i, use_scope=
True
557 ) == scopes_cleaned[i]