[test] Adding logging to TestJSInterpreter
This commit is contained in:
parent
cd2bf30a60
commit
5238ed11ac
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
@ -15,6 +16,8 @@ from youtube_dl.jsinterp import JSInterpreter
|
|||||||
from test.jstests import gettestcases
|
from test.jstests import gettestcases
|
||||||
|
|
||||||
defs = 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):
|
class TestJSInterpreter(unittest.TestCase):
|
||||||
@ -22,7 +25,7 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
self.defs = defs
|
self.defs = defs
|
||||||
|
|
||||||
|
|
||||||
def generator(test_case):
|
def generator(test_case, name):
|
||||||
def test_template(self):
|
def test_template(self):
|
||||||
for test in test_case['subtests']:
|
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=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'])
|
self.assertEqual(jsi.call_function(*a['call']), a['value'])
|
||||||
else:
|
else:
|
||||||
self.assertEqual(jsi.run(), a['value'])
|
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']:
|
if 'i' not in test_case['skip']:
|
||||||
reason = False
|
reason = False
|
||||||
@ -43,16 +50,20 @@ def generator(test_case):
|
|||||||
|
|
||||||
# And add them to TestJSInterpreter
|
# And add them to TestJSInterpreter
|
||||||
for n, tc in enumerate(defs):
|
for n, tc in enumerate(defs):
|
||||||
if any('asserts' in test for test in tc['subtests']):
|
if 'i' not in tc['skip'] or tc['skip']['i'] is not True:
|
||||||
test_method = generator(tc)
|
|
||||||
tname = 'test_' + str(tc['name'])
|
tname = 'test_' + str(tc['name'])
|
||||||
i = 1
|
i = 1
|
||||||
while hasattr(TestJSInterpreter, tname):
|
while hasattr(TestJSInterpreter, tname):
|
||||||
tname = 'test_%s_%d' % (tc['name'], i)
|
tname = 'test_%s_%d' % (tc['name'], i)
|
||||||
i += 1
|
i += 1
|
||||||
test_method.__name__ = str(tname)
|
if any('asserts' in test for test in tc['subtests']):
|
||||||
setattr(TestJSInterpreter, test_method.__name__, test_method)
|
test_method = generator(tc, tname)
|
||||||
del test_method
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -4,8 +4,8 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import copy
|
|
||||||
import logging
|
import logging
|
||||||
|
import copy
|
||||||
|
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
@ -39,7 +39,7 @@ class TestJSInterpreterParse(unittest.TestCase):
|
|||||||
self.defs = defs
|
self.defs = defs
|
||||||
|
|
||||||
|
|
||||||
def generator(test_case):
|
def generator(test_case, name):
|
||||||
def test_template(self):
|
def test_template(self):
|
||||||
for a in test_case['subtests']:
|
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=None if 'globals' not in a else a['globals'])
|
||||||
@ -49,7 +49,7 @@ def generator(test_case):
|
|||||||
else:
|
else:
|
||||||
log.debug('No AST, trying to parsing only')
|
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']:
|
if 'p' not in test_case['skip']:
|
||||||
reason = False
|
reason = False
|
||||||
@ -59,15 +59,15 @@ def generator(test_case):
|
|||||||
return test_template if not reason else unittest.skip(reason)(test_template)
|
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):
|
for n, tc in enumerate(defs):
|
||||||
if 'p' not in tc['skip'] or tc['skip']['p'] is not True:
|
if 'p' not in tc['skip'] or tc['skip']['p'] is not True:
|
||||||
test_method = generator(tc)
|
|
||||||
tname = 'test_' + str(tc['name'])
|
tname = 'test_' + str(tc['name'])
|
||||||
i = 1
|
i = 1
|
||||||
while hasattr(TestJSInterpreterParse, tname):
|
while hasattr(TestJSInterpreterParse, tname):
|
||||||
tname = 'test_%s_%d' % (tc['name'], i)
|
tname = 'test_%s_%d' % (tc['name'], i)
|
||||||
i += 1
|
i += 1
|
||||||
|
test_method = generator(tc, tname)
|
||||||
test_method.__name__ = str(tname)
|
test_method.__name__ = str(tname)
|
||||||
setattr(TestJSInterpreterParse, test_method.__name__, test_method)
|
setattr(TestJSInterpreterParse, test_method.__name__, test_method)
|
||||||
del test_method
|
del test_method
|
||||||
|
Loading…
x
Reference in New Issue
Block a user