1#!/usr/bin/env python 2# Copyright 2013-2019, Damian Johnson and The Tor Project 3# See LICENSE for licensing information 4 5""" 6Runs nyx's unit tests. When running this you may notice your screen flicker. 7This is because we're a curses application, and so testing requires us to 8render to the screen. 9""" 10 11import os 12import unittest 13 14import stem.util.conf 15import stem.util.system 16import stem.util.test_tools 17 18import nyx 19import test 20 21SRC_PATHS = [os.path.join(test.NYX_BASE, path) for path in ( 22 'nyx', 23 'test', 24 'run_tests.py', 25 'setup.py', 26 'run_nyx', 27)] 28 29 30@nyx.uses_settings 31def main(): 32 nyx.PAUSE_TIME = 0.000001 # make pauses negligibly low since our tests trigger things rapidly 33 test_config = stem.util.conf.get_config('test') 34 test_config.load(os.path.join(test.NYX_BASE, 'test', 'settings.cfg')) 35 36 orphaned_pyc = stem.util.test_tools.clean_orphaned_pyc([test.NYX_BASE]) 37 38 for path in orphaned_pyc: 39 print('Deleted orphaned pyc file: %s' % path) 40 41 pyflakes_task, pycodestyle_task = None, None 42 43 if stem.util.test_tools.is_pyflakes_available(): 44 pyflakes_task = stem.util.system.DaemonTask(stem.util.test_tools.pyflakes_issues, (SRC_PATHS,), start = True) 45 46 if stem.util.test_tools.is_pep8_available(): 47 pycodestyle_task = stem.util.system.DaemonTask(stem.util.test_tools.stylistic_issues, (SRC_PATHS,), start = True) 48 49 tests = unittest.defaultTestLoader.discover('test', pattern = '*.py') 50 test_runner = unittest.TextTestRunner() 51 test_runner.run(tests) 52 53 print('') 54 55 static_check_issues = {} 56 57 if pyflakes_task: 58 for path, issues in pyflakes_task.join().items(): 59 for issue in issues: 60 static_check_issues.setdefault(path, []).append(issue) 61 62 if pycodestyle_task: 63 for path, issues in pycodestyle_task.join().items(): 64 for issue in issues: 65 static_check_issues.setdefault(path, []).append(issue) 66 67 if static_check_issues: 68 print('STATIC CHECKS') 69 70 for file_path in static_check_issues: 71 print('* %s' % file_path) 72 73 for issue in static_check_issues[file_path]: 74 print(' line %-4s - %-40s %s' % (issue.line_number, issue.message, issue.line)) 75 76 print 77 78 79if __name__ == '__main__': 80 main() 81