python.py (1654:fc7d0578e124) python.py (1670:099c23b00eaf)
1import os
2import shutil
3from urllib.parse import quote
4
5import pytest
6from conftest import option
7from unit.applications.proto import TestApplicationProto
8
9
10class TestApplicationPython(TestApplicationProto):
11 application_type = "python"
12 load_module = "wsgi"
13
14 def load(self, script, name=None, module=None, **kwargs):
15 if name is None:
16 name = script
17
18 if module is None:
19 module = self.load_module
20
21 if script[0] == '/':
22 script_path = script
23 else:
24 script_path = option.test_dir + '/python/' + script
25
26 if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
27 rootfs = kwargs['isolation']['rootfs']
28
29 if not os.path.exists(rootfs + '/app/python/'):
30 os.makedirs(rootfs + '/app/python/')
31
32 if not os.path.exists(rootfs + '/app/python/' + name):
33 shutil.copytree(script_path, rootfs + '/app/python/' + name)
34
35 script_path = '/app/python/' + name
36
1import os
2import shutil
3from urllib.parse import quote
4
5import pytest
6from conftest import option
7from unit.applications.proto import TestApplicationProto
8
9
10class TestApplicationPython(TestApplicationProto):
11 application_type = "python"
12 load_module = "wsgi"
13
14 def load(self, script, name=None, module=None, **kwargs):
15 if name is None:
16 name = script
17
18 if module is None:
19 module = self.load_module
20
21 if script[0] == '/':
22 script_path = script
23 else:
24 script_path = option.test_dir + '/python/' + script
25
26 if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
27 rootfs = kwargs['isolation']['rootfs']
28
29 if not os.path.exists(rootfs + '/app/python/'):
30 os.makedirs(rootfs + '/app/python/')
31
32 if not os.path.exists(rootfs + '/app/python/' + name):
33 shutil.copytree(script_path, rootfs + '/app/python/' + name)
34
35 script_path = '/app/python/' + name
36
37 appication_type = self.get_appication_type()
38
39 if appication_type is None:
40 appication_type = self.application_type
41
42 self._load_conf(
43 {
44 "listeners": {
45 "*:7080": {"pass": "applications/" + quote(name, '')}
46 },
47 "applications": {
48 name: {
37 self._load_conf(
38 {
39 "listeners": {
40 "*:7080": {"pass": "applications/" + quote(name, '')}
41 },
42 "applications": {
43 name: {
49 "type": appication_type,
44 "type": self.get_application_type(),
50 "processes": {"spare": 0},
51 "path": script_path,
52 "working_directory": script_path,
53 "module": module,
54 }
55 },
56 },
57 **kwargs
58 )
45 "processes": {"spare": 0},
46 "path": script_path,
47 "working_directory": script_path,
48 "module": module,
49 }
50 },
51 },
52 **kwargs
53 )