Tests: style.
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
import unit
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import unit
|
||||||
|
|
||||||
class TestUnitConfiguration(unit.TestUnitControl):
|
class TestUnitConfiguration(unit.TestUnitControl):
|
||||||
|
|
||||||
def setUpClass():
|
def setUpClass():
|
||||||
u = unit.TestUnit()
|
unit.TestUnit().check_modules('python')
|
||||||
module_missed = u.check_modules('python')
|
|
||||||
if module_missed:
|
|
||||||
raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
|
|
||||||
|
|
||||||
def test_json_applications(self):
|
def test_json_applications(self):
|
||||||
self.assertIn('error', self.put('/applications', '"{}"'),
|
self.assertIn('error', self.put('/applications', '"{}"'),
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import unit
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import unit
|
||||||
|
|
||||||
class TestUnitBasic(unit.TestUnitControl):
|
class TestUnitBasic(unit.TestUnitControl):
|
||||||
|
|
||||||
def setUpClass():
|
def setUpClass():
|
||||||
u = unit.TestUnit()
|
unit.TestUnit().check_modules('php')
|
||||||
module_missed = u.check_modules('php')
|
|
||||||
if module_missed:
|
|
||||||
raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
|
|
||||||
|
|
||||||
def test_php_get(self):
|
def test_php_get(self):
|
||||||
resp = self.get()
|
resp = self.get()
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import unit
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import unit
|
||||||
|
|
||||||
class TestUnitBasic(unit.TestUnitControl):
|
class TestUnitBasic(unit.TestUnitControl):
|
||||||
|
|
||||||
def setUpClass():
|
def setUpClass():
|
||||||
u = unit.TestUnit()
|
unit.TestUnit().check_modules('python')
|
||||||
module_missed = u.check_modules('python')
|
|
||||||
if module_missed:
|
|
||||||
raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
|
|
||||||
|
|
||||||
def test_python_get(self):
|
def test_python_get(self):
|
||||||
resp = self.get()
|
resp = self.get()
|
||||||
|
|||||||
12
test/unit.py
12
test/unit.py
@@ -41,16 +41,18 @@ class TestUnit(unittest.TestCase):
|
|||||||
if m is None:
|
if m is None:
|
||||||
exit("Unit is writing log too long")
|
exit("Unit is writing log too long")
|
||||||
|
|
||||||
ret = ''
|
missed_module = ''
|
||||||
for module in modules:
|
for module in modules:
|
||||||
m = re.search('module: ' + module, log, re.M | re.S)
|
m = re.search('module: ' + module, log, re.M | re.S)
|
||||||
if m is None:
|
if m is None:
|
||||||
ret = module
|
missed_module = module
|
||||||
|
break
|
||||||
|
|
||||||
self._stop()
|
self._stop()
|
||||||
shutil.rmtree(self.testdir)
|
shutil.rmtree(self.testdir)
|
||||||
|
|
||||||
return ret
|
if missed_module:
|
||||||
|
raise unittest.SkipTest('Unit has no ' + missed_module + ' module')
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
|
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
|
||||||
@@ -131,7 +133,6 @@ class TestUnitControl(TestUnit):
|
|||||||
# TODO http client
|
# TODO http client
|
||||||
|
|
||||||
def http(self, req):
|
def http(self, req):
|
||||||
|
|
||||||
with self._control_sock() as sock:
|
with self._control_sock() as sock:
|
||||||
sock.sendall(req)
|
sock.sendall(req)
|
||||||
|
|
||||||
@@ -146,21 +147,18 @@ class TestUnitControl(TestUnit):
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
def get(self, path='/'):
|
def get(self, path='/'):
|
||||||
|
|
||||||
resp = self.http(('GET ' + path
|
resp = self.http(('GET ' + path
|
||||||
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
||||||
|
|
||||||
return self._body_json(resp)
|
return self._body_json(resp)
|
||||||
|
|
||||||
def delete(self, path='/'):
|
def delete(self, path='/'):
|
||||||
|
|
||||||
resp = self.http(('DELETE ' + path
|
resp = self.http(('DELETE ' + path
|
||||||
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
+ ' HTTP/1.1\r\nHost: localhost\r\n\r\n').encode())
|
||||||
|
|
||||||
return self._body_json(resp)
|
return self._body_json(resp)
|
||||||
|
|
||||||
def put(self, path='/', data=''):
|
def put(self, path='/', data=''):
|
||||||
|
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user