summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-01-10 20:35:22 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-01-10 20:35:22 +0300
commit470948a0d65fb65ff58fc185af12e5ece8e1ae4c (patch)
tree3f5f84d9e5b561f0ed6128eb2ff2377914540ab5
parent8546d6d499b9700364bb23b923d022fca10fe00e (diff)
downloadunit-470948a0d65fb65ff58fc185af12e5ece8e1ae4c.tar.gz
unit-470948a0d65fb65ff58fc185af12e5ece8e1ae4c.tar.bz2
Tests: style.
-rw-r--r--test/test_configuration.py7
-rw-r--r--test/test_php_basic.py7
-rw-r--r--test/test_python_basic.py7
-rw-r--r--test/unit.py12
4 files changed, 11 insertions, 22 deletions
diff --git a/test/test_configuration.py b/test/test_configuration.py
index b710e145..b9aad8a4 100644
--- a/test/test_configuration.py
+++ b/test/test_configuration.py
@@ -1,13 +1,10 @@
-import unit
import unittest
+import unit
class TestUnitConfiguration(unit.TestUnitControl):
def setUpClass():
- u = unit.TestUnit()
- module_missed = u.check_modules('python')
- if module_missed:
- raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
+ unit.TestUnit().check_modules('python')
def test_json_applications(self):
self.assertIn('error', self.put('/applications', '"{}"'),
diff --git a/test/test_php_basic.py b/test/test_php_basic.py
index d4617ee6..fa1484a3 100644
--- a/test/test_php_basic.py
+++ b/test/test_php_basic.py
@@ -1,13 +1,10 @@
-import unit
import unittest
+import unit
class TestUnitBasic(unit.TestUnitControl):
def setUpClass():
- u = unit.TestUnit()
- module_missed = u.check_modules('php')
- if module_missed:
- raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
+ unit.TestUnit().check_modules('php')
def test_php_get(self):
resp = self.get()
diff --git a/test/test_python_basic.py b/test/test_python_basic.py
index 659c53ff..a68f1bad 100644
--- a/test/test_python_basic.py
+++ b/test/test_python_basic.py
@@ -1,13 +1,10 @@
-import unit
import unittest
+import unit
class TestUnitBasic(unit.TestUnitControl):
def setUpClass():
- u = unit.TestUnit()
- module_missed = u.check_modules('python')
- if module_missed:
- raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
+ unit.TestUnit().check_modules('python')
def test_python_get(self):
resp = self.get()
diff --git a/test/unit.py b/test/unit.py
index 3d331b46..9b3f76ef 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -41,16 +41,18 @@ class TestUnit(unittest.TestCase):
if m is None:
exit("Unit is writing log too long")
- ret = ''
+ missed_module = ''
for module in modules:
m = re.search('module: ' + module, log, re.M | re.S)
if m is None:
- ret = module
+ missed_module = module
+ break
self._stop()
shutil.rmtree(self.testdir)
- return ret
+ if missed_module:
+ raise unittest.SkipTest('Unit has no ' + missed_module + ' module')
def _run(self):
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
@@ -131,7 +133,6 @@ class TestUnitControl(TestUnit):
# TODO http client
def http(self, req):
-
with self._control_sock() as sock:
sock.sendall(req)
@@ -146,21 +147,18 @@ class TestUnitControl(TestUnit):
return resp
def get(self, path='/'):
-
resp = self.http(('GET ' + path
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
return self._body_json(resp)
def delete(self, path='/'):
-
resp = self.http(('DELETE ' + path
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
return self._body_json(resp)
def put(self, path='/', data=''):
-
if isinstance(data, str):
data = data.encode()