summaryrefslogtreecommitdiffhomepage
path: root/test/unit
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-03-23 02:13:46 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2020-03-23 02:13:46 +0000
commit3fd4b4cfab9541437d07048f3973368e568fe98f (patch)
tree5ddcb73b29ae64394f30317fa17f81aacd7537f2 /test/unit
parentc7cc247baa2f9b6cd2499416644adf0bd13ff070 (diff)
downloadunit-3fd4b4cfab9541437d07048f3973368e568fe98f.tar.gz
unit-3fd4b4cfab9541437d07048f3973368e568fe98f.tar.bz2
Tests: rearranging functions in main.py.
Diffstat (limited to '')
-rw-r--r--test/unit/main.py138
1 files changed, 69 insertions, 69 deletions
diff --git a/test/unit/main.py b/test/unit/main.py
index a1182e5c..cdab486f 100644
--- a/test/unit/main.py
+++ b/test/unit/main.py
@@ -152,47 +152,6 @@ class TestUnit(unittest.TestCase):
def setUp(self):
self._run()
- def tearDown(self):
- self.stop()
-
- # detect errors and failures for current test
-
- def list2reason(exc_list):
- if exc_list and exc_list[-1][0] is self:
- return exc_list[-1][1]
-
- if hasattr(self, '_outcome'):
- result = self.defaultTestResult()
- self._feedErrorsToResult(result, self._outcome.errors)
- else:
- result = getattr(
- self, '_outcomeForDoCleanups', self._resultForDoCleanups
- )
-
- success = not list2reason(result.errors) and not list2reason(
- result.failures
- )
-
- # check unit.log for alerts
-
- unit_log = self.testdir + '/unit.log'
-
- with open(unit_log, 'r', encoding='utf-8', errors='ignore') as f:
- self._check_alerts(f.read())
-
- # remove unit.log
-
- if not TestUnit.save_log and success:
- shutil.rmtree(self.testdir)
-
- else:
- self._print_log()
-
- def stop(self):
- self._stop()
- self.stop_processes()
- atexit.unregister(self.stop)
-
def _run(self):
build_dir = self.pardir + '/build'
self.unitd = build_dir + '/unitd'
@@ -237,6 +196,47 @@ class TestUnit(unittest.TestCase):
]
self.skip_sanitizer = False
+ def tearDown(self):
+ self.stop()
+
+ # detect errors and failures for current test
+
+ def list2reason(exc_list):
+ if exc_list and exc_list[-1][0] is self:
+ return exc_list[-1][1]
+
+ if hasattr(self, '_outcome'):
+ result = self.defaultTestResult()
+ self._feedErrorsToResult(result, self._outcome.errors)
+ else:
+ result = getattr(
+ self, '_outcomeForDoCleanups', self._resultForDoCleanups
+ )
+
+ success = not list2reason(result.errors) and not list2reason(
+ result.failures
+ )
+
+ # check unit.log for alerts
+
+ unit_log = self.testdir + '/unit.log'
+
+ with open(unit_log, 'r', encoding='utf-8', errors='ignore') as f:
+ self._check_alerts(f.read())
+
+ # remove unit.log
+
+ if not TestUnit.save_log and success:
+ shutil.rmtree(self.testdir)
+
+ else:
+ self._print_log()
+
+ def stop(self):
+ self._stop()
+ self.stop_processes()
+ atexit.unregister(self.stop)
+
def _stop(self):
if self._p.poll() is not None:
return
@@ -254,34 +254,6 @@ class TestUnit(unittest.TestCase):
p.kill()
self.fail("Could not terminate unit")
- def _check_alerts(self, log):
- found = False
-
- alerts = re.findall('.+\[alert\].+', log)
-
- if alerts:
- print('All alerts/sanitizer errors found in log:')
- [print(alert) for alert in alerts]
- found = True
-
- if self.skip_alerts:
- for skip in self.skip_alerts:
- alerts = [al for al in alerts if re.search(skip, al) is None]
-
- if alerts:
- self._print_log(log)
- self.assertFalse(alerts, 'alert(s)')
-
- if not self.skip_sanitizer:
- sanitizer_errors = re.findall('.+Sanitizer.+', log)
-
- if sanitizer_errors:
- self._print_log(log)
- self.assertFalse(sanitizer_errors, 'sanitizer error(s)')
-
- if found:
- print('skipped.')
-
def run_process(self, target, *args):
if not hasattr(self, '_processes'):
self._processes = []
@@ -331,6 +303,34 @@ class TestUnit(unittest.TestCase):
for f in files:
os.chmod(os.path.join(root, f), 0o777)
+ def _check_alerts(self, log):
+ found = False
+
+ alerts = re.findall('.+\[alert\].+', log)
+
+ if alerts:
+ print('All alerts/sanitizer errors found in log:')
+ [print(alert) for alert in alerts]
+ found = True
+
+ if self.skip_alerts:
+ for skip in self.skip_alerts:
+ alerts = [al for al in alerts if re.search(skip, al) is None]
+
+ if alerts:
+ self._print_log(log)
+ self.assertFalse(alerts, 'alert(s)')
+
+ if not self.skip_sanitizer:
+ sanitizer_errors = re.findall('.+Sanitizer.+', log)
+
+ if sanitizer_errors:
+ self._print_log(log)
+ self.assertFalse(sanitizer_errors, 'sanitizer error(s)')
+
+ if found:
+ print('skipped.')
+
@staticmethod
def _parse_args():
parser = argparse.ArgumentParser(add_help=False)