Private GIT

Skip to content
Snippets Groups Projects
Commit bc5d620f authored by labrys's avatar labrys
Browse files

Merge pull request #235 from labrys/lint-all_tests

Lint all_tests.py
parents f5f58f9d a14630be
No related branches found
No related tags found
No related merge requests found
......@@ -18,49 +18,83 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=line-too-long
"""
Perform all tests in tests/
"""
import fnmatch
import os
import sys
import unittest
tests_dir = os.path.abspath(__file__)[:-len(os.path.basename(__file__))]
sys.path.insert(1, os.path.join(tests_dir, '../lib'))
sys.path.insert(1, os.path.join(tests_dir, '..'))
TESTS_DIR = os.path.abspath(__file__)[:-len(os.path.basename(__file__))]
sys.path.insert(1, os.path.join(TESTS_DIR, '../lib'))
sys.path.insert(1, os.path.join(TESTS_DIR, '..'))
class AllTests(unittest.TestCase):
"""
Performs all tests in tests directory.
Methods
setUp
test_all
_get_module_strings
_get_test_files
_get_test_suites
"""
# Block issue_submitter_tests to avoid issue tracker spam on every build
blacklist = [tests_dir + 'all_tests.py', tests_dir + 'issue_submitter_tests.py', tests_dir + 'search_tests.py']
blacklist = [TESTS_DIR + 'all_tests.py', TESTS_DIR + 'issue_submitter_tests.py', TESTS_DIR + 'search_tests.py']
def setUp(self):
"""
Get all tests
"""
self.test_file_strings = self._get_test_files()
self.module_strings = self._get_module_strings()
self.suites = self._get_test_suites()
self.testSuite = unittest.TestSuite(self.suites)
self.test_suite = unittest.TestSuite(self.suites)
def testAll(self):
def test_all(self):
"""
Perform all tests
"""
print "===================="
print "STARTING - ALL TESTS"
print "===================="
for included_files in self.test_file_strings:
print "- " + included_files[len(tests_dir):-3]
print "- " + included_files[len(TESTS_DIR):-3]
text_runner = unittest.TextTestRunner().run(self.testSuite)
text_runner = unittest.TextTestRunner().run(self.test_suite)
if not text_runner.wasSuccessful():
sys.exit(-1)
def _get_module_strings(self):
"""
Convert the file names into module names
:return: all module names
"""
modules = []
for file_string in self.test_file_strings:
modules.append(file_string[len(tests_dir):len(file_string) - 3].replace(os.sep, '.'))
modules.append(file_string[len(TESTS_DIR):len(file_string) - 3].replace(os.sep, '.'))
return modules
def _get_test_files(self):
"""
Get the name of all the tests in the tests directory
:return: all file names that match
"""
matches = []
for root, _, file_names in os.walk(tests_dir):
for root, _, file_names in os.walk(TESTS_DIR):
for filename in fnmatch.filter(file_names, '*_tests.py'):
filename_with_path = os.path.join(root, filename)
......@@ -70,8 +104,12 @@ class AllTests(unittest.TestCase):
return matches
def _get_test_suites(self):
return [unittest.defaultTestLoader.loadTestsFromName(file_string) for file_string in self.module_strings]
"""
Load all test suites
:return: all test suites from tests
"""
return [unittest.defaultTestLoader.loadTestsFromName(file_string) for file_string in self.module_strings]
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment