migliorati i test
This commit is contained in:
@@ -57,7 +57,6 @@
|
|||||||
<td class="col-xs-9" colspan="3">
|
<td class="col-xs-9" colspan="3">
|
||||||
{%- if test_case.stdout %}<p style="white-space: pre-line;">{{ test_case.stdout|e }}</p>{% endif %}
|
{%- if test_case.stdout %}<p style="white-space: pre-line;">{{ test_case.stdout|e }}</p>{% endif %}
|
||||||
{%- if test_case.err %}<p style="color:maroon;">{{ test_case.err[0].__name__ }}: {{ test_case.err[1] }}</p>{% endif %}
|
{%- if test_case.err %}<p style="color:maroon;">{{ test_case.err[0].__name__ }}: {{ test_case.err[1] }}</p>{% endif %}
|
||||||
{%- if test_case.err %}<p style="color:maroon;">{{ test_case.test_exception_info }}</p>{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|||||||
+48
-31
@@ -6,7 +6,7 @@
|
|||||||
# export PYTHONPATH=/home/user/.kodi/addons/plugin.video.kod
|
# export PYTHONPATH=/home/user/.kodi/addons/plugin.video.kod
|
||||||
# export KOD_TST_CH=channel
|
# export KOD_TST_CH=channel
|
||||||
# python tests/test_generic.py
|
# python tests/test_generic.py
|
||||||
|
import html
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
@@ -141,23 +141,33 @@ chNumRis = {
|
|||||||
servers = []
|
servers = []
|
||||||
channels = []
|
channels = []
|
||||||
|
|
||||||
channel_list = channelselector.filterchannels("all") if 'KOD_TST_CH' not in os.environ else [Item(channel=os.environ['KOD_TST_CH'], action="mainlist")]
|
# channel_list = channelselector.filterchannels("all") if 'KOD_TST_CH' not in os.environ else [Item(channel=os.environ['KOD_TST_CH'], action="mainlist")]
|
||||||
|
channel_list = [Item(channel='tantifilm', action="mainlist")]
|
||||||
logger.info([c.channel for c in channel_list])
|
logger.info([c.channel for c in channel_list])
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
logger.record = True
|
logger.record = True
|
||||||
for chItem in channel_list:
|
for chItem in channel_list:
|
||||||
try:
|
ch = chItem.channel
|
||||||
ch = chItem.channel
|
if ch not in chBlackList:
|
||||||
if ch not in chBlackList:
|
hasChannelConfig = False
|
||||||
module = __import__('channels.%s' % ch, fromlist=["channels.%s" % ch])
|
mainlist = []
|
||||||
hasChannelConfig = False
|
module = None
|
||||||
mainlist = module.mainlist(Item())
|
error = None
|
||||||
menuItemlist = {}
|
menuItemlist = {}
|
||||||
logMenu = {}
|
serversFound = {}
|
||||||
serversFound = {}
|
logMenu = {}
|
||||||
|
|
||||||
for it in mainlist:
|
try:
|
||||||
|
module = __import__('channels.%s' % ch, fromlist=["channels.%s" % ch])
|
||||||
|
mainlist = module.mainlist(Item())
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
error = logger.recordedLog
|
||||||
|
logger.recordedLog = ''
|
||||||
|
for it in mainlist:
|
||||||
|
try:
|
||||||
print('preparing ' + ch + ' -> ' + it.title)
|
print('preparing ' + ch + ' -> ' + it.title)
|
||||||
|
|
||||||
if it.action == 'channel_config':
|
if it.action == 'channel_config':
|
||||||
@@ -165,6 +175,8 @@ for chItem in channel_list:
|
|||||||
continue
|
continue
|
||||||
if it.action == 'search': # channel-specific
|
if it.action == 'search': # channel-specific
|
||||||
continue
|
continue
|
||||||
|
menuItemlist[it.title] = []
|
||||||
|
|
||||||
itemlist = getattr(module, it.action)(it)
|
itemlist = getattr(module, it.action)(it)
|
||||||
menuItemlist[it.title] = itemlist
|
menuItemlist[it.title] = itemlist
|
||||||
logMenu[it.title] = logger.recordedLog
|
logMenu[it.title] = logger.recordedLog
|
||||||
@@ -180,19 +192,24 @@ for chItem in channel_list:
|
|||||||
|
|
||||||
if serversFound[it.title]:
|
if serversFound[it.title]:
|
||||||
if hasattr(module, 'play'):
|
if hasattr(module, 'play'):
|
||||||
serversFound[it.title] = [getattr(module, 'play')(resIt)[0] for srv in serversFound[it.title]]
|
tmp = []
|
||||||
|
for srv in serversFound[it.title]:
|
||||||
|
itPlay = getattr(module, 'play')(srv)
|
||||||
|
if itPlay:
|
||||||
|
tmp.append(itPlay[0])
|
||||||
|
serversFound[it.title] = tmp
|
||||||
servers.extend(
|
servers.extend(
|
||||||
{'name': srv.server.lower(), 'server': srv} for srv in serversFound[it.title] if srv.server)
|
{'name': srv.server.lower(), 'server': srv} for srv in serversFound[it.title] if srv.server)
|
||||||
break
|
break
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
logMenu[it.title] = logger.recordedLog
|
||||||
|
logger.recordedLog = ''
|
||||||
|
|
||||||
channels.append(
|
channels.append(
|
||||||
{'ch': ch, 'hasChannelConfig': hasChannelConfig, 'mainlist': mainlist, 'menuItemlist': menuItemlist,
|
{'ch': ch, 'hasChannelConfig': hasChannelConfig, 'mainlist': mainlist, 'menuItemlist': menuItemlist,
|
||||||
'serversFound': serversFound, 'module': module, 'logMenu': logMenu})
|
'serversFound': serversFound, 'module': module, 'logMenu': logMenu, 'error': error})
|
||||||
except:
|
|
||||||
import traceback
|
|
||||||
logger.error(traceback.format_exc())
|
|
||||||
print(logger.recordedLog)
|
|
||||||
logger.recordedLog = ''
|
|
||||||
|
|
||||||
logger.record = False
|
logger.record = False
|
||||||
|
|
||||||
@@ -211,6 +228,7 @@ for s in servers:
|
|||||||
@parameterized.parameterized_class(channels)
|
@parameterized.parameterized_class(channels)
|
||||||
class GenericChannelTest(unittest.TestCase):
|
class GenericChannelTest(unittest.TestCase):
|
||||||
def test_mainlist(self):
|
def test_mainlist(self):
|
||||||
|
self.assertIsNone(self.error, self.error)
|
||||||
self.assertTrue(self.mainlist, 'channel ' + self.ch + ' has no mainlist')
|
self.assertTrue(self.mainlist, 'channel ' + self.ch + ' has no mainlist')
|
||||||
self.assertTrue(self.hasChannelConfig, 'channel ' + self.ch + ' has no channel config')
|
self.assertTrue(self.hasChannelConfig, 'channel ' + self.ch + ' has no channel config')
|
||||||
|
|
||||||
@@ -255,25 +273,22 @@ class GenericChannelMenuItemTest(unittest.TestCase):
|
|||||||
self.assertEqual(chNumRis[self.ch][content], risNum,
|
self.assertEqual(chNumRis[self.ch][content], risNum,
|
||||||
'channel ' + self.ch + ' -> ' + self.title + ' returned wrong number of results<br>'
|
'channel ' + self.ch + ' -> ' + self.title + ' returned wrong number of results<br>'
|
||||||
+ str(risNum) + ' but should be ' + str(chNumRis[self.ch][content]) + '<br>' +
|
+ str(risNum) + ' but should be ' + str(chNumRis[self.ch][content]) + '<br>' +
|
||||||
'<br>'.join([i.title for i in self.itemlist if not i.nextPage]))
|
'<br>'.join([html.escape(i.title) for i in self.itemlist if not i.nextPage]))
|
||||||
break
|
break
|
||||||
|
|
||||||
for resIt in self.itemlist:
|
for resIt in self.itemlist:
|
||||||
logger.info(resIt.title + ' -> ' + resIt.url)
|
logger.info(resIt.title + ' -> ' + resIt.url)
|
||||||
self.assertLess(len(resIt.fulltitle), 110,
|
self.assertLess(len(resIt.fulltitle), 110,
|
||||||
'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong titles<br>' + resIt.fulltitle)
|
'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong titles:<br>' + html.escape(resIt.fulltitle))
|
||||||
if resIt.url:
|
if resIt.url:
|
||||||
self.assertIsInstance(resIt.url, str,
|
self.assertIsInstance(resIt.url, str,
|
||||||
'channel ' + self.ch + ' -> ' + self.title + ' -> ' + resIt.title + ' contain non-string url')
|
'channel ' + self.ch + ' -> ' + self.title + ' -> ' + html.escape(resIt.title) + ' contain non-string url')
|
||||||
self.assertIsNotNone(re.match(validUrlRegex, resIt.url),
|
self.assertIsNotNone(re.match(validUrlRegex, resIt.url),
|
||||||
'channel ' + self.ch + ' -> ' + self.title + ' -> ' + resIt.title + ' might contain wrong url<br>' + resIt.url)
|
'channel ' + self.ch + ' -> ' + self.title + ' -> ' + html.escape(resIt.title) + ' might contain wrong url<br>' + html.escape(resIt.url))
|
||||||
if 'year' in resIt.infoLabels and resIt.infoLabels['year']:
|
if 'year' in resIt.infoLabels and resIt.infoLabels['year']:
|
||||||
msgYear = 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong infolabels year<br>' + str(
|
msgYear = 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong infolabels year:<br>' + html.escape(str(resIt.infoLabels['year']))
|
||||||
resIt.infoLabels['year'])
|
self.assert_(type(resIt.infoLabels['year']) is int or resIt.infoLabels['year'].isdigit(), msgYear)
|
||||||
self.assert_(type(resIt.infoLabels['year']) is int or resIt.infoLabels['year'].isdigit(),
|
self.assert_(1900 < int(resIt.infoLabels['year']) < 2100, msgYear)
|
||||||
msgYear)
|
|
||||||
self.assert_(int(resIt.infoLabels['year']) > 1900 and int(resIt.infoLabels['year']) < 2100,
|
|
||||||
msgYear)
|
|
||||||
|
|
||||||
if resIt.title == typo(config.get_localized_string(30992), 'color kod bold'): # next page
|
if resIt.title == typo(config.get_localized_string(30992), 'color kod bold'): # next page
|
||||||
nextPageItemlist = getattr(self.module, resIt.action)(resIt)
|
nextPageItemlist = getattr(self.module, resIt.action)(resIt)
|
||||||
@@ -326,5 +341,7 @@ if __name__ == '__main__':
|
|||||||
if 'KOD_TST_CH' not in os.environ:
|
if 'KOD_TST_CH' not in os.environ:
|
||||||
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(report_name='report', add_timestamp=False, combine_reports=True,
|
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(report_name='report', add_timestamp=False, combine_reports=True,
|
||||||
report_title='KoD Test Suite', template=os.path.join(config.get_runtime_path(), 'tests', 'template.html')), exit=False)
|
report_title='KoD Test Suite', template=os.path.join(config.get_runtime_path(), 'tests', 'template.html')), exit=False)
|
||||||
|
import webbrowser
|
||||||
|
webbrowser.open(os.path.join(config.get_runtime_path(), 'reports', 'report.html'))
|
||||||
else:
|
else:
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user