diff --git a/test/jstests/branch.py b/test/jstests/branch.py index 537bb49e5..bd1d38da6 100644 --- a/test/jstests/branch.py +++ b/test/jstests/branch.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _RELATIONS -skip = {'i': 'Interpreting if statement not yet implemented'} +skip = {'interpret': 'Interpreting if statement not yet implemented'} tests = [ { diff --git a/test/jstests/debug.py b/test/jstests/debug.py index 3d6f3ee74..a998cb68e 100644 --- a/test/jstests/debug.py +++ b/test/jstests/debug.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token -skip = {'i': 'Interpreting debugger statement not yet implemented', - 'p': 'Test not yet implemented: missing code and ast'} +skip = {'interpret': 'Interpreting debugger statement not yet implemented', + 'parse': 'Test not yet implemented: missing code and ast'} tests = [ { diff --git a/test/jstests/do_loop.py b/test/jstests/do_loop.py index ef19a22c4..6d419b0ca 100644 --- a/test/jstests/do_loop.py +++ b/test/jstests/do_loop.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _UNARY_OPERATORS, _RELATIONS -skip = {'i': 'Interpreting do loop not yet implemented'} +skip = {'interpret': 'Interpreting do loop not yet implemented'} tests = [ { diff --git a/test/jstests/for_empty.py b/test/jstests/for_empty.py index df88b88f8..6a99e5b3f 100644 --- a/test/jstests/for_empty.py +++ b/test/jstests/for_empty.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _UNARY_OPERATORS, _RELATIONS -skip = {'i': 'Interpreting for empty loop not yet implemented'} +skip = {'interpret': 'Interpreting for empty loop not yet implemented'} tests = [ { diff --git a/test/jstests/for_in.py b/test/jstests/for_in.py index dfcd86c79..af385f007 100644 --- a/test/jstests/for_in.py +++ b/test/jstests/for_in.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS -skip = {'i': 'Interpreting for in loop not yet implemented'} +skip = {'interpret': 'Interpreting for in loop not yet implemented'} tests = [ { diff --git a/test/jstests/for_loop.py b/test/jstests/for_loop.py index 84a2aa7c5..f45958fe5 100644 --- a/test/jstests/for_loop.py +++ b/test/jstests/for_loop.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _UNARY_OPERATORS, _RELATIONS -skip = {'i': 'Interpreting for loop not yet implemented'} +skip = {'interpret': 'Interpreting for loop not yet implemented'} tests = [ { diff --git a/test/jstests/func_expr.py b/test/jstests/func_expr.py index cd5f817d9..da43137b7 100644 --- a/test/jstests/func_expr.py +++ b/test/jstests/func_expr.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS -skip = {'i': 'Interpreting function expression not yet implemented'} +skip = {'interpret': 'Interpreting function expression not yet implemented'} tests = [ { diff --git a/test/jstests/label.py b/test/jstests/label.py index 1cd9d8164..91170bdb9 100644 --- a/test/jstests/label.py +++ b/test/jstests/label.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token -skip = {'i': 'Interpreting label not yet implemented', - 'p': 'Test not yet implemented: missing code and ast'} +skip = {'interpret': 'Interpreting label not yet implemented', + 'parse': 'Test not yet implemented: missing code and ast'} tests = [ { diff --git a/test/jstests/object_literal.py b/test/jstests/object_literal.py index 0a827700f..683128352 100644 --- a/test/jstests/object_literal.py +++ b/test/jstests/object_literal.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _OPERATORS -skip = {'i': 'Interpreting object literals not yet implemented'} +skip = {'interpret': 'Interpreting object literals not yet implemented'} tests = [ { diff --git a/test/jstests/precedence.py b/test/jstests/precedence.py index 8008ff589..e8b042e70 100644 --- a/test/jstests/precedence.py +++ b/test/jstests/precedence.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _OPERATORS -skip = {'i': 'Interpreting built-in fields not yet implemented'} +skip = {'interpret': 'Interpreting built-in fields not yet implemented'} tests = [ { diff --git a/test/jstests/switch.py b/test/jstests/switch.py index 098560b93..22ac2f590 100644 --- a/test/jstests/switch.py +++ b/test/jstests/switch.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _UNARY_OPERATORS -skip = {'i': 'Interpreting switch statement not yet implemented'} +skip = {'interpret': 'Interpreting switch statement not yet implemented'} tests = [ { diff --git a/test/jstests/try_statement.py b/test/jstests/try_statement.py index 841bcc524..961ab9ff3 100644 --- a/test/jstests/try_statement.py +++ b/test/jstests/try_statement.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token -skip = {'i': 'Interpreting try statement not yet implemented', - 'p': 'Test not yet implemented: missing code and ast'} +skip = {'interpret': 'Interpreting try statement not yet implemented', + 'parse': 'Test not yet implemented: missing code and ast'} tests = [ { diff --git a/test/jstests/unary.py b/test/jstests/unary.py index 400d2b6f4..4d7c16774 100644 --- a/test/jstests/unary.py +++ b/test/jstests/unary.py @@ -1,5 +1,5 @@ -skip = {'p': True} +skip = {'parse': True} tests = [ { diff --git a/test/jstests/while_loop.py b/test/jstests/while_loop.py index 32facc518..5a4bc39ee 100644 --- a/test/jstests/while_loop.py +++ b/test/jstests/while_loop.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token from youtube_dl.jsinterp.tstream import _ASSIGN_OPERATORS, _UNARY_OPERATORS, _RELATIONS -skip = {'i': 'Interpreting while loop not yet implemented'} +skip = {'interpret': 'Interpreting while loop not yet implemented'} tests = [ { diff --git a/test/jstests/with_statement.py b/test/jstests/with_statement.py index 82c04c099..c84aec1c5 100644 --- a/test/jstests/with_statement.py +++ b/test/jstests/with_statement.py @@ -1,7 +1,7 @@ from youtube_dl.jsinterp.jsgrammar import Token -skip = {'i': 'Interpreting with statement not yet implemented', - 'p': 'Test not yet implemented: missing code and ast'} +skip = {'interpret': 'Interpreting with statement not yet implemented', + 'parse': 'Test not yet implemented: missing code and ast'} tests = [ { diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 8fbc67762..36b6b7cb0 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals +# Allow direct execution import os import sys import logging @@ -28,7 +29,7 @@ class TestJSInterpreter(unittest.TestCase): 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']) + jsi = JSInterpreter(test['code'], variables=test.get('globals')) if 'asserts' in test: for a in test['asserts']: if 'call' in a: @@ -36,34 +37,39 @@ def generator(test_case, name): else: self.assertEqual(jsi.run(), a['value']) else: - log.debug('No asserts, skipping subtest') + log.debug('No assertion for subtest, skipping') log = logging.getLogger('TestJSInterpreter.%s' % name) - - if 'i' not in test_case['skip']: - reason = False - else: - reason = test_case['skip']['i'] - - return test_template if not reason else unittest.skip(reason)(test_template) + return test_template # And add them to TestJSInterpreter for n, tc in enumerate(defs): - 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 - 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) + reason = tc['skip'].get('interpret', False) + tname = 'test_' + str(tc['name']) + i = 1 + while hasattr(TestJSInterpreter, tname): + tname = 'test_%s_%d' % (tc['name'], i) + i += 1 + + if reason is not True: + log_reason = 'Entirely' + elif not any('asserts' in test for test in tc['subtests']): + log_reason = '''There isn't any assertion''' + else: + log_reason = None + + if log_reason is not None: + test_method = generator(tc, tname) + test_method.__name__ = str(tname) + if reason is not False: + test_method.__unittest_skip__ = True + test_method.__unittest_skip_why__ = reason + setattr(TestJSInterpreter, test_method.__name__, test_method) + del test_method + else: + log = logging.getLogger('TestJSInterpreter') + log.debug('Skipping %s:%s' % (tname, log_reason)) if __name__ == '__main__': unittest.main() diff --git a/test/test_jsinterp_parse.py b/test/test_jsinterp_parse.py index 10e2a2338..9aaf3f44b 100644 --- a/test/test_jsinterp_parse.py +++ b/test/test_jsinterp_parse.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals +# Allow direct execution import os import sys import logging @@ -18,7 +19,7 @@ from .jstests import gettestcases def traverse(node, tree_types=(list, tuple)): - if type(node) == zip: + if sys.version_info > (3,) and isinstance(node, zip): node = list(copy.deepcopy(node)) if isinstance(node, tree_types): tree = [] @@ -42,35 +43,37 @@ class TestJSInterpreterParse(unittest.TestCase): 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']) + jsi = JSInterpreter(a['code'], variables=a.get('globals')) parsed = list(jsi.parse()) if 'ast' in a: self.assertEqual(traverse(parsed), traverse(a['ast'])) else: - log.debug('No AST, trying to parsing only') + log.debug('No AST for subtest, trying to parse only') - log = logging.getLogger('TestJSInterpreterParse.%s' + name) - - if 'p' not in test_case['skip']: - reason = False - else: - reason = test_case['skip']['p'] - - return test_template if not reason else unittest.skip(reason)(test_template) + log = logging.getLogger('TestJSInterpreterParse.%s' % name) + return test_template # And add them to TestJSInterpreterParse for n, tc in enumerate(defs): - if 'p' not in tc['skip'] or tc['skip']['p'] is not True: - tname = 'test_' + str(tc['name']) - i = 1 - while hasattr(TestJSInterpreterParse, tname): - tname = 'test_%s_%d' % (tc['name'], i) - i += 1 + reason = tc['skip'].get('parse', False) + tname = 'test_' + str(tc['name']) + i = 1 + while hasattr(TestJSInterpreterParse, tname): + tname = 'test_%s_%d' % (tc['name'], i) + i += 1 + if reason is not True: test_method = generator(tc, tname) + if reason is not False: + test_method.__unittest_skip__ = True + test_method.__unittest_skip_why__ = reason test_method.__name__ = str(tname) setattr(TestJSInterpreterParse, test_method.__name__, test_method) del test_method + else: + log = logging.getLogger('TestJSInterpreterParse') + log.debug('Skipping %s:Entirely' % tname) + if __name__ == '__main__': unittest.main()