diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 4110506b5..8fbc67762 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import os import sys +import logging if sys.version_info < (2, 7): import unittest2 as unittest @@ -15,6 +16,8 @@ from youtube_dl.jsinterp import JSInterpreter from test.jstests import gettestcases defs = gettestcases() +# set level to logging.DEBUG to see messages about missing assertions +logging.basicConfig(stream=sys.stderr, level=logging.WARNING) class TestJSInterpreter(unittest.TestCase): @@ -22,7 +25,7 @@ class TestJSInterpreter(unittest.TestCase): self.defs = defs -def generator(test_case): +def generator(test_case, name): def test_template(self): for test in test_case['subtests']: jsi = JSInterpreter(test['code'], variables=None if 'globals' not in test else test['globals']) @@ -32,6 +35,10 @@ def generator(test_case): self.assertEqual(jsi.call_function(*a['call']), a['value']) else: self.assertEqual(jsi.run(), a['value']) + else: + log.debug('No asserts, skipping subtest') + + log = logging.getLogger('TestJSInterpreter.%s' % name) if 'i' not in test_case['skip']: reason = False @@ -43,16 +50,20 @@ def generator(test_case): # And add them to TestJSInterpreter for n, tc in enumerate(defs): - if any('asserts' in test for test in tc['subtests']): - test_method = generator(tc) + if 'i' not in tc['skip'] or tc['skip']['i'] is not True: tname = 'test_' + str(tc['name']) i = 1 while hasattr(TestJSInterpreter, tname): tname = 'test_%s_%d' % (tc['name'], i) i += 1 - test_method.__name__ = str(tname) - setattr(TestJSInterpreter, test_method.__name__, test_method) - del test_method + if any('asserts' in test for test in tc['subtests']): + test_method = generator(tc, tname) + test_method.__name__ = str(tname) + setattr(TestJSInterpreter, test_method.__name__, test_method) + del test_method + else: + log = logging.getLogger('TestJSInterpreter') + log.debug('''Skipping %s:There isn't any assertion''' % tname) if __name__ == '__main__': unittest.main() diff --git a/test/test_jsinterp_parse.py b/test/test_jsinterp_parse.py index 7e4295990..06b0be070 100644 --- a/test/test_jsinterp_parse.py +++ b/test/test_jsinterp_parse.py @@ -4,8 +4,8 @@ from __future__ import unicode_literals import os import sys -import copy import logging +import copy if sys.version_info < (2, 7): import unittest2 as unittest @@ -39,7 +39,7 @@ class TestJSInterpreterParse(unittest.TestCase): self.defs = defs -def generator(test_case): +def generator(test_case, name): def test_template(self): for a in test_case['subtests']: jsi = JSInterpreter(a['code'], variables=None if 'globals' not in a else a['globals']) @@ -49,7 +49,7 @@ def generator(test_case): else: log.debug('No AST, trying to parsing only') - log = logging.getLogger('TestJSInterpreterParse.test_' + str(tc['name'])) + log = logging.getLogger('TestJSInterpreterParse.%s' + name) if 'p' not in test_case['skip']: reason = False @@ -59,15 +59,15 @@ def generator(test_case): return test_template if not reason else unittest.skip(reason)(test_template) -# And add them to TestJSInterpreter +# And add them to TestJSInterpreterParse for n, tc in enumerate(defs): if 'p' not in tc['skip'] or tc['skip']['p'] is not True: - test_method = generator(tc) tname = 'test_' + str(tc['name']) i = 1 while hasattr(TestJSInterpreterParse, tname): tname = 'test_%s_%d' % (tc['name'], i) i += 1 + test_method = generator(tc, tname) test_method.__name__ = str(tname) setattr(TestJSInterpreterParse, test_method.__name__, test_method) del test_method