summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2017-12-06 15:35:28 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2017-12-06 15:35:28 +0300
commit7ae5bef233d744f514427a33e1da531040d3fd6f (patch)
tree1bf4ddf1dcfc1d888fdc0c7a21b2f0fe3d3fb37b
parent79b1d4f5ff664cba84108fd124d78362949faa99 (diff)
downloadunit-7ae5bef233d744f514427a33e1da531040d3fd6f.tar.gz
unit-7ae5bef233d744f514427a33e1da531040d3fd6f.tar.bz2
Tests: check_modules() function introduced.
-rw-r--r--test/test_basic.py7
-rw-r--r--test/test_configuration.py7
-rw-r--r--test/unit.py50
3 files changed, 54 insertions, 10 deletions
diff --git a/test/test_basic.py b/test/test_basic.py
index e6a5c6e8..ec893325 100644
--- a/test/test_basic.py
+++ b/test/test_basic.py
@@ -3,6 +3,13 @@ import unittest
class TestUnitBasic(unit.TestUnitControl):
+ @classmethod
+ def setUpClass(cls):
+ u = unit.TestUnit()
+ module_missed = u.check_modules('python')
+ if module_missed:
+ raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
+
def test_get(self):
resp = self.get()
self.assertEqual(resp, {'listeners': {}, 'applications': {}}, 'empty')
diff --git a/test/test_configuration.py b/test/test_configuration.py
index 7d487e49..8d913077 100644
--- a/test/test_configuration.py
+++ b/test/test_configuration.py
@@ -3,6 +3,13 @@ import unittest
class TestUnitConfiguration(unit.TestUnitControl):
+ @classmethod
+ def setUpClass(cls):
+ u = unit.TestUnit()
+ module_missed = u.check_modules('python')
+ if module_missed:
+ raise unittest.SkipTest('Unit has no ' + module_missed + ' module')
+
def test_json_applications(self):
self.assertIn('error', self.put('/applications', '"{}"'),
'applications string')
diff --git a/test/unit.py b/test/unit.py
index b8cd5154..0857272e 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -12,6 +12,45 @@ import subprocess
class TestUnit(unittest.TestCase):
def setUp(self):
+ self._run()
+
+ def tearDown(self):
+ self._stop()
+
+ if '--log' in sys.argv:
+ with open(self.testdir + '/unit.log', 'r') as f:
+ print(f.read())
+
+ if '--leave' not in sys.argv:
+ shutil.rmtree(self.testdir)
+
+ def check_modules(self, *modules):
+ self._run()
+
+ for i in range(50):
+ with open(self.testdir + '/unit.log', 'r') as f:
+ log = f.read()
+ m = re.search('controller started', log, re.M | re.S)
+
+ if m is None:
+ time.sleep(0.1)
+ else:
+ break
+
+ if m is None:
+ exit("Unit is writing log too long")
+
+ ret = ''
+ for module in modules:
+ m = re.search('module: ' + module, log, re.M | re.S)
+ if m is None:
+ ret = module
+
+ self._stop()
+
+ return ret
+
+ def _run(self):
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
os.mkdir(self.testdir + '/state')
@@ -33,9 +72,7 @@ class TestUnit(unittest.TestCase):
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit")
- # TODO dependency check
-
- def tearDown(self):
+ def _stop(self):
with open(self.testdir + '/unit.pid', 'r') as f:
pid = f.read().rstrip()
@@ -49,13 +86,6 @@ class TestUnit(unittest.TestCase):
if os.path.exists(self.testdir + '/unit.pid'):
exit("Could not terminate unit")
- if '--log' in sys.argv:
- with open(self.testdir + '/unit.log', 'r') as f:
- print(f.read())
-
- if '--leave' not in sys.argv:
- shutil.rmtree(self.testdir)
-
def _waitforfiles(self, *files):
for i in range(50):
wait = False