-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
97 lines (72 loc) · 1.93 KB
/
test.py
File metadata and controls
97 lines (72 loc) · 1.93 KB
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
from WebScriptsTools import __all__
from WebScriptsTools import *
from os.path import join
from os import environ
import WebScriptsTools
namespace = {}
namespace.update(locals())
namespace.update(globals())
__all__.remove("main")
__all__.remove("module2to3")
environ["WEBSCRIPTS_PATH"] = "/"
environ["SCRIPT_CONFIG"] = '{"name": "script"}'
environ["LOG_PATH"] = "/"
environ["USER"] = "{}"
class Mock:
configuration = None
class Mock2:
class loader:
def exec_module(test):
assert test == "upload"
def mock_spec_from_file_location(uploads, path):
assert uploads == "uploads"
assert path.endswith(
join(
"scripts",
"uploads",
"modules",
"uploads_management.py",
)
)
return Mock2()
def mock_module_from_spec(spec):
assert isinstance(spec, Mock2)
return "upload"
WebScriptsTools.spec_from_file_location = mock_spec_from_file_location
WebScriptsTools.module_from_spec = mock_module_from_spec
class Module:
@module2to3
def method(
self,
environ,
user,
configuration,
filename,
commande,
inputs,
csrf_token: str = None,
):
return configuration
@module2to3
def function(
environ,
user,
configuration,
filename,
commande,
inputs,
csrf_token: str = None,
):
return configuration
server = Mock()
module = Module()
assert Module.function("test", "test", server, "test", "test", "test") is None
assert module.method("test", "test", server, "test", "test", "test") is None
for function in __all__:
print(function, namespace[function]())
def tests():
try:
a
except Exception as e:
raise NameError("test") from e
tests() # exit with code 127 (cause: NameError in test())