From d5e915934066c77a59d211efafca10c117b73d05 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 16 Sep 2020 21:31:15 +0100 Subject: Tests: migrated to the pytest. --- test/unit/applications/lang/go.py | 23 ++++++++++++----------- test/unit/applications/lang/java.py | 10 ++++++---- test/unit/applications/lang/node.py | 13 +++++++------ test/unit/applications/lang/perl.py | 3 ++- test/unit/applications/lang/php.py | 3 ++- test/unit/applications/lang/python.py | 12 ++++++++++-- test/unit/applications/lang/ruby.py | 3 ++- 7 files changed, 41 insertions(+), 26 deletions(-) (limited to 'test/unit/applications/lang') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 83bde4d8..069bdecb 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -2,17 +2,18 @@ import os import subprocess from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationGo(TestApplicationProto): @classmethod - def setUpClass(cls, complete_check=True): - unit = super().setUpClass(complete_check=False) + def setup_class(cls, complete_check=True): + unit = super().setup_class(complete_check=False) # check go module go_app = TestApplicationGo() - go_app.testdir = unit.testdir + go_app.temp_dir = unit.temp_dir proc = go_app.prepare_env('empty', 'app') if proc and proc.returncode == 0: cls.available['modules']['go'] = [] @@ -20,8 +21,8 @@ class TestApplicationGo(TestApplicationProto): return unit if not complete_check else unit.complete() def prepare_env(self, script, name, static=False): - if not os.path.exists(self.testdir + '/go'): - os.mkdir(self.testdir + '/go') + if not os.path.exists(self.temp_dir + '/go'): + os.mkdir(self.temp_dir + '/go') env = os.environ.copy() env['GOPATH'] = self.pardir + '/build/go' @@ -35,16 +36,16 @@ class TestApplicationGo(TestApplicationProto): '-ldflags', '-extldflags "-static"', '-o', - self.testdir + '/go/' + name, - self.current_dir + '/go/' + script + '/' + name + '.go', + self.temp_dir + '/go/' + name, + option.test_dir + '/go/' + script + '/' + name + '.go', ] else: args = [ 'go', 'build', '-o', - self.testdir + '/go/' + name, - self.current_dir + '/go/' + script + '/' + name + '.go', + self.temp_dir + '/go/' + name, + option.test_dir + '/go/' + script + '/' + name + '.go', ] try: @@ -59,8 +60,8 @@ class TestApplicationGo(TestApplicationProto): def load(self, script, name='app', **kwargs): static_build = False - wdir = self.current_dir + "/go/" + script - executable = self.testdir + "/go/" + name + wdir = option.test_dir + "/go/" + script + executable = self.temp_dir + "/go/" + name if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']: wdir = "/go/" diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index c2c6dc51..b5511883 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -1,17 +1,19 @@ import glob import os +import pytest import shutil import subprocess from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationJava(TestApplicationProto): def load(self, script, name='app', **kwargs): - app_path = self.testdir + '/java' + app_path = self.temp_dir + '/java' web_inf_path = app_path + '/WEB-INF/' classes_path = web_inf_path + 'classes/' - script_path = self.current_dir + '/java/' + script + '/' + script_path = option.test_dir + '/java/' + script + '/' if not os.path.isdir(app_path): os.makedirs(app_path) @@ -54,7 +56,7 @@ class TestApplicationJava(TestApplicationProto): ) if not ws_jars: - self.fail('websocket api jar not found.') + pytest.fail('websocket api jar not found.') javac = [ 'javac', @@ -69,7 +71,7 @@ class TestApplicationJava(TestApplicationProto): process.communicate() except: - self.fail('Cann\'t run javac process.') + pytest.fail('Cann\'t run javac process.') self._load_conf( { diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index cf2a99f6..f510acce 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -3,12 +3,13 @@ import shutil from urllib.parse import quote from unit.applications.proto import TestApplicationProto +from conftest import option, public_dir class TestApplicationNode(TestApplicationProto): @classmethod - def setUpClass(cls, complete_check=True): - unit = super().setUpClass(complete_check=False) + def setup_class(cls, complete_check=True): + unit = super().setup_class(complete_check=False) # check node module @@ -21,17 +22,17 @@ class TestApplicationNode(TestApplicationProto): # copy application shutil.copytree( - self.current_dir + '/node/' + script, self.testdir + '/node' + option.test_dir + '/node/' + script, self.temp_dir + '/node' ) # copy modules shutil.copytree( self.pardir + '/node/node_modules', - self.testdir + '/node/node_modules', + self.temp_dir + '/node/node_modules', ) - self.public_dir(self.testdir + '/node') + public_dir(self.temp_dir + '/node') self._load_conf( { @@ -42,7 +43,7 @@ class TestApplicationNode(TestApplicationProto): script: { "type": "external", "processes": {"spare": 0}, - "working_directory": self.testdir + '/node', + "working_directory": self.temp_dir + '/node', "executable": name, } }, diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py index d32aca33..92939d88 100644 --- a/test/unit/applications/lang/perl.py +++ b/test/unit/applications/lang/perl.py @@ -1,11 +1,12 @@ from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationPerl(TestApplicationProto): application_type = "perl" def load(self, script, name='psgi.pl', **kwargs): - script_path = self.current_dir + '/perl/' + script + script_path = option.test_dir + '/perl/' + script self._load_conf( { diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index e8c70c62..350eb29b 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -1,11 +1,12 @@ from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationPHP(TestApplicationProto): application_type = "php" def load(self, script, index='index.php', **kwargs): - script_path = self.current_dir + '/php/' + script + script_path = option.test_dir + '/php/' + script self._load_conf( { diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 91559f4b..dcdd2ffe 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -1,20 +1,23 @@ import os import shutil +import pytest from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationPython(TestApplicationProto): application_type = "python" def load(self, script, name=None, **kwargs): + print() if name is None: name = script if script[0] == '/': script_path = script else: - script_path = self.current_dir + '/python/' + script + script_path = option.test_dir + '/python/' + script if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'): rootfs = kwargs['isolation']['rootfs'] @@ -27,12 +30,17 @@ class TestApplicationPython(TestApplicationProto): script_path = '/app/python/' + name + appication_type = self.get_appication_type() + + if appication_type is None: + appication_type = self.application_type + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + name}}, "applications": { name: { - "type": self.application_type, + "type": appication_type, "processes": {"spare": 0}, "path": script_path, "working_directory": script_path, diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py index 8c8acecc..534227bd 100644 --- a/test/unit/applications/lang/ruby.py +++ b/test/unit/applications/lang/ruby.py @@ -1,11 +1,12 @@ from unit.applications.proto import TestApplicationProto +from conftest import option class TestApplicationRuby(TestApplicationProto): application_type = "ruby" def load(self, script, name='config.ru', **kwargs): - script_path = self.current_dir + '/ruby/' + script + script_path = option.test_dir + '/ruby/' + script self._load_conf( { -- cgit