diff options
Diffstat (limited to '')
-rw-r--r-- | test/unit/applications/lang/go.py | 32 | ||||
-rw-r--r-- | test/unit/applications/lang/java.py | 36 | ||||
-rw-r--r-- | test/unit/applications/lang/node.py | 14 | ||||
-rw-r--r-- | test/unit/applications/lang/perl.py | 8 | ||||
-rw-r--r-- | test/unit/applications/lang/php.py | 16 | ||||
-rw-r--r-- | test/unit/applications/lang/python.py | 16 | ||||
-rw-r--r-- | test/unit/applications/lang/ruby.py | 14 |
7 files changed, 66 insertions, 70 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 14e76362..557753a4 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -14,23 +14,21 @@ class TestApplicationGo(TestApplicationProto): except subprocess.CalledProcessError: return None - temp_dir = option.temp_dir + '/go/' + temp_dir = f'{option.temp_dir}/go/' if not os.path.exists(temp_dir): os.mkdir(temp_dir) - cache_dir = option.cache_dir + '/go-build' + cache_dir = f'{option.cache_dir}/go-build' if not os.path.exists(cache_dir): os.mkdir(cache_dir) env = os.environ.copy() - env['GOPATH'] = option.current_dir + '/build/go' + env['GOPATH'] = f'{option.current_dir}/build/go' env['GOCACHE'] = cache_dir - shutil.copy2( - option.test_dir + '/go/' + script + '/' + name + '.go', temp_dir - ) + shutil.copy2(f'{option.test_dir}/go/{script}/{name}.go', temp_dir) if static: args = [ @@ -41,21 +39,21 @@ class TestApplicationGo(TestApplicationProto): '-ldflags', '-extldflags "-static"', '-o', - temp_dir + name, - temp_dir + name + '.go', + f'{temp_dir}{name}', + f'{temp_dir}{name}.go', ] else: args = [ 'go', 'build', '-o', - temp_dir + name, - temp_dir + name + '.go', + f'{temp_dir}{name}', + f'{temp_dir}{name}.go', ] - replace_path = option.current_dir + '/build/go/src/unit.nginx.org/go' + replace_path = f'{option.current_dir}/build/go/src/unit.nginx.org/go' - with open(temp_dir + 'go.mod', 'w') as f: + with open(f'{temp_dir}go.mod', 'w') as f: f.write( f"""module test/app require unit.nginx.org/go v0.0.0 @@ -64,7 +62,7 @@ replace unit.nginx.org/go => {replace_path} ) if option.detailed: - print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args)) + print(f'\n$ GOPATH={env["GOPATH"]} {" ".join(args)}') try: output = subprocess.check_output( @@ -82,18 +80,18 @@ replace unit.nginx.org/go => {replace_path} def load(self, script, name='app', **kwargs): static_build = False - wdir = option.test_dir + "/go/" + script - executable = option.temp_dir + "/go/" + name + wdir = f'{option.test_dir}/go/{script}' + executable = f'{option.temp_dir}/go/{name}' if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']: wdir = "/go/" - executable = "/go/" + name + executable = f"/go/{name}" static_build = True TestApplicationGo.prepare_env(script, name, static=static_build) conf = { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": {"*:7080": {"pass": f"applications/{script}"}}, "applications": { script: { "type": "external", diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index c8936274..cd955974 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -12,10 +12,10 @@ class TestApplicationJava(TestApplicationProto): application_type = "java" def prepare_env(self, script): - app_path = option.temp_dir + '/java' - web_inf_path = app_path + '/WEB-INF/' - classes_path = web_inf_path + 'classes/' - script_path = option.test_dir + '/java/' + script + '/' + app_path = f'{option.temp_dir}/java' + web_inf_path = f'{app_path}/WEB-INF/' + classes_path = f'{web_inf_path}classes/' + script_path = f'{option.test_dir}/java/{script}/' if not os.path.isdir(app_path): os.makedirs(app_path) @@ -23,7 +23,7 @@ class TestApplicationJava(TestApplicationProto): src = [] for f in os.listdir(script_path): - file_path = script_path + f + file_path = f'{script_path}{f}' if f.endswith('.java'): src.append(file_path) @@ -36,7 +36,7 @@ class TestApplicationJava(TestApplicationProto): if f == 'WEB-INF': continue - shutil.copytree(file_path, app_path + '/' + f) + shutil.copytree(file_path, f'{app_path}/{f}') continue if f == 'web.xml': @@ -52,11 +52,11 @@ class TestApplicationJava(TestApplicationProto): os.makedirs(classes_path) classpath = ( - option.current_dir + '/build/tomcat-servlet-api-9.0.70.jar' + f'{option.current_dir}/build/tomcat-servlet-api-9.0.70.jar' ) ws_jars = glob.glob( - option.current_dir + '/build/websocket-api-java-*.jar' + f'{option.current_dir}/build/websocket-api-java-*.jar' ) if not ws_jars: @@ -74,12 +74,12 @@ class TestApplicationJava(TestApplicationProto): '-d', classes_path, '-classpath', - classpath + ':' + ws_jars[0], + f'{classpath}:{ws_jars[0]}', ] javac.extend(src) if option.detailed: - print("\n$ " + " ".join(javac)) + print(f'\n$ {" ".join(javac)}') try: subprocess.check_output(javac, stderr=subprocess.STDOUT) @@ -88,26 +88,24 @@ class TestApplicationJava(TestApplicationProto): raise except subprocess.CalledProcessError: - pytest.fail('Can\'t run javac process.') + pytest.fail("Can't run javac process.") def load(self, script, **kwargs): self.prepare_env(script) + script_path = f'{option.test_dir}/java/{script}/' self._load_conf( { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": {"*:7080": {"pass": f"applications/{script}"}}, "applications": { script: { - "unit_jars": option.current_dir + '/build', + "unit_jars": f'{option.current_dir}/build', "type": self.get_application_type(), "processes": {"spare": 0}, - "working_directory": option.test_dir - + '/java/' - + script - + '/', - "webapp": option.temp_dir + '/java', + "working_directory": script_path, + "webapp": f'{option.temp_dir}/java', } }, }, - **kwargs + **kwargs, ) diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 5d05c70c..87d5a19c 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -13,16 +13,16 @@ class TestApplicationNode(TestApplicationProto): def prepare_env(self, script): # copy application shutil.copytree( - option.test_dir + '/node/' + script, option.temp_dir + '/node' + f'{option.test_dir}/node/{script}', f'{option.temp_dir}/node' ) # copy modules shutil.copytree( - option.current_dir + '/node/node_modules', - option.temp_dir + '/node/node_modules', + f'{option.current_dir}/node/node_modules', + f'{option.temp_dir}/node/node_modules', ) - public_dir(option.temp_dir + '/node') + public_dir(f'{option.temp_dir}/node') def load(self, script, name='app.js', **kwargs): self.prepare_env(script) @@ -43,17 +43,17 @@ class TestApplicationNode(TestApplicationProto): self._load_conf( { "listeners": { - "*:7080": {"pass": "applications/" + quote(script, '')} + "*:7080": {"pass": f"applications/{quote(script, '')}"} }, "applications": { script: { "type": "external", "processes": {"spare": 0}, - "working_directory": option.temp_dir + '/node', + "working_directory": f'{option.temp_dir}/node', "executable": '/usr/bin/env', "arguments": arguments, } }, }, - **kwargs + **kwargs, ) diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py index 58b867f0..19852363 100644 --- a/test/unit/applications/lang/perl.py +++ b/test/unit/applications/lang/perl.py @@ -6,19 +6,19 @@ class TestApplicationPerl(TestApplicationProto): application_type = "perl" def load(self, script, name='psgi.pl', **kwargs): - script_path = option.test_dir + '/perl/' + script + script_path = f'{option.test_dir}/perl/{script}' self._load_conf( { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": {"*:7080": {"pass": f"applications/{script}"}}, "applications": { script: { "type": self.get_application_type(), "processes": {"spare": 0}, "working_directory": script_path, - "script": script_path + '/' + name, + "script": f'{script_path}/{name}', } }, }, - **kwargs + **kwargs, ) diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 5319d2ca..1b94c3ae 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -9,18 +9,18 @@ class TestApplicationPHP(TestApplicationProto): application_type = "php" def load(self, script, index='index.php', **kwargs): - script_path = option.test_dir + '/php/' + script + script_path = f'{option.test_dir}/php/{script}' if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'): rootfs = kwargs['isolation']['rootfs'] - if not os.path.exists(rootfs + '/app/php/'): - os.makedirs(rootfs + '/app/php/') + if not os.path.exists(f'{rootfs}/app/php/'): + os.makedirs(f'{rootfs}/app/php/') - if not os.path.exists(rootfs + '/app/php/' + script): - shutil.copytree(script_path, rootfs + '/app/php/' + script) + if not os.path.exists(f'{rootfs}/app/php/{script}'): + shutil.copytree(script_path, f'{rootfs}/app/php/{script}') - script_path = '/app/php/' + script + script_path = f'/app/php/{script}' app = { "type": self.get_application_type(), @@ -41,8 +41,8 @@ class TestApplicationPHP(TestApplicationProto): self._load_conf( { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": {"*:7080": {"pass": f"applications/{script}"}}, "applications": {script: app}, }, - **kwargs + **kwargs, ) diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 3768cf07..0bb69992 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -20,18 +20,18 @@ class TestApplicationPython(TestApplicationProto): if script[0] == '/': script_path = script else: - script_path = option.test_dir + '/python/' + script + script_path = f'{option.test_dir}/python/{script}' if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'): rootfs = kwargs['isolation']['rootfs'] - if not os.path.exists(rootfs + '/app/python/'): - os.makedirs(rootfs + '/app/python/') + if not os.path.exists(f'{rootfs}/app/python/'): + os.makedirs(f'{rootfs}/app/python/') - if not os.path.exists(rootfs + '/app/python/' + name): - shutil.copytree(script_path, rootfs + '/app/python/' + name) + if not os.path.exists(f'{rootfs}/app/python/{name}'): + shutil.copytree(script_path, f'{rootfs}/app/python/{name}') - script_path = '/app/python/' + name + script_path = f'/app/python/{name}' app = { "type": self.get_application_type(), @@ -58,9 +58,9 @@ class TestApplicationPython(TestApplicationProto): self._load_conf( { "listeners": { - "*:7080": {"pass": "applications/" + quote(name, '')} + "*:7080": {"pass": f"applications/{quote(name, '')}"} }, "applications": {name: app}, }, - **kwargs + **kwargs, ) diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py index 824bfe7f..e0712fc6 100644 --- a/test/unit/applications/lang/ruby.py +++ b/test/unit/applications/lang/ruby.py @@ -10,22 +10,22 @@ class TestApplicationRuby(TestApplicationProto): def prepare_env(self, script): shutil.copytree( - option.test_dir + '/ruby/' + script, - option.temp_dir + '/ruby/' + script, + f'{option.test_dir}/ruby/{script}', + f'{option.temp_dir}/ruby/{script}', ) - public_dir(option.temp_dir + '/ruby/' + script) + public_dir(f'{option.temp_dir}/ruby/{script}') def load(self, script, name='config.ru', **kwargs): self.prepare_env(script) - script_path = option.temp_dir + '/ruby/' + script + script_path = f'{option.temp_dir}/ruby/{script}' app = { "type": self.get_application_type(), "processes": {"spare": 0}, "working_directory": script_path, - "script": script_path + '/' + name, + "script": f'{script_path}/{name}', } for key in [ @@ -36,8 +36,8 @@ class TestApplicationRuby(TestApplicationProto): self._load_conf( { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": {"*:7080": {"pass": f"applications/{script}"}}, "applications": {script: app}, }, - **kwargs + **kwargs, ) |