From 6e8dd1c551ba488e6a01bd7d6b252596ca7d40bf Mon Sep 17 00:00:00 2001
From: marco <10120390+mac12m99@users.noreply.github.com>
Date: Wed, 6 Jan 2021 20:45:55 +0100
Subject: [PATCH] migliorati i test
---
tests/template.html | 1 -
tests/test_generic.py | 79 ++++++++++++++++++++++++++-----------------
2 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/tests/template.html b/tests/template.html
index 3de62433..6579c1cb 100644
--- a/tests/template.html
+++ b/tests/template.html
@@ -57,7 +57,6 @@
{%- if test_case.stdout %} {{ test_case.stdout|e }} {% endif %}
{%- if test_case.err %}{{ test_case.err[0].__name__ }}: {{ test_case.err[1] }} {% endif %}
- {%- if test_case.err %}{{ test_case.test_exception_info }} {% endif %}
|
{%- endif %}
diff --git a/tests/test_generic.py b/tests/test_generic.py
index 88200568..bc39d682 100644
--- a/tests/test_generic.py
+++ b/tests/test_generic.py
@@ -6,7 +6,7 @@
# export PYTHONPATH=/home/user/.kodi/addons/plugin.video.kod
# export KOD_TST_CH=channel
# python tests/test_generic.py
-
+import html
import os
import sys
import unittest
@@ -141,23 +141,33 @@ chNumRis = {
servers = []
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])
ret = []
logger.record = True
for chItem in channel_list:
- try:
- ch = chItem.channel
- if ch not in chBlackList:
- module = __import__('channels.%s' % ch, fromlist=["channels.%s" % ch])
- hasChannelConfig = False
- mainlist = module.mainlist(Item())
- menuItemlist = {}
- logMenu = {}
- serversFound = {}
+ ch = chItem.channel
+ if ch not in chBlackList:
+ hasChannelConfig = False
+ mainlist = []
+ module = None
+ error = None
+ menuItemlist = {}
+ 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)
if it.action == 'channel_config':
@@ -165,6 +175,8 @@ for chItem in channel_list:
continue
if it.action == 'search': # channel-specific
continue
+ menuItemlist[it.title] = []
+
itemlist = getattr(module, it.action)(it)
menuItemlist[it.title] = itemlist
logMenu[it.title] = logger.recordedLog
@@ -180,19 +192,24 @@ for chItem in channel_list:
if serversFound[it.title]:
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(
{'name': srv.server.lower(), 'server': srv} for srv in serversFound[it.title] if srv.server)
break
+ except:
+ import traceback
+ logger.error(traceback.format_exc())
+ logMenu[it.title] = logger.recordedLog
+ logger.recordedLog = ''
- channels.append(
- {'ch': ch, 'hasChannelConfig': hasChannelConfig, 'mainlist': mainlist, 'menuItemlist': menuItemlist,
- 'serversFound': serversFound, 'module': module, 'logMenu': logMenu})
- except:
- import traceback
- logger.error(traceback.format_exc())
- print(logger.recordedLog)
- logger.recordedLog = ''
+ channels.append(
+ {'ch': ch, 'hasChannelConfig': hasChannelConfig, 'mainlist': mainlist, 'menuItemlist': menuItemlist,
+ 'serversFound': serversFound, 'module': module, 'logMenu': logMenu, 'error': error})
logger.record = False
@@ -211,6 +228,7 @@ for s in servers:
@parameterized.parameterized_class(channels)
class GenericChannelTest(unittest.TestCase):
def test_mainlist(self):
+ self.assertIsNone(self.error, self.error)
self.assertTrue(self.mainlist, 'channel ' + self.ch + ' has no mainlist')
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,
'channel ' + self.ch + ' -> ' + self.title + ' returned wrong number of results
'
+ str(risNum) + ' but should be ' + str(chNumRis[self.ch][content]) + '
' +
- '
'.join([i.title for i in self.itemlist if not i.nextPage]))
+ '
'.join([html.escape(i.title) for i in self.itemlist if not i.nextPage]))
break
for resIt in self.itemlist:
logger.info(resIt.title + ' -> ' + resIt.url)
self.assertLess(len(resIt.fulltitle), 110,
- 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong titles
' + resIt.fulltitle)
+ 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong titles:
' + html.escape(resIt.fulltitle))
if resIt.url:
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),
- 'channel ' + self.ch + ' -> ' + self.title + ' -> ' + resIt.title + ' might contain wrong url
' + resIt.url)
+ 'channel ' + self.ch + ' -> ' + self.title + ' -> ' + html.escape(resIt.title) + ' might contain wrong url
' + html.escape(resIt.url))
if 'year' in resIt.infoLabels and resIt.infoLabels['year']:
- msgYear = 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong infolabels year
' + str(
- resIt.infoLabels['year'])
- self.assert_(type(resIt.infoLabels['year']) is int or resIt.infoLabels['year'].isdigit(),
- msgYear)
- self.assert_(int(resIt.infoLabels['year']) > 1900 and int(resIt.infoLabels['year']) < 2100,
- msgYear)
+ msgYear = 'channel ' + self.ch + ' -> ' + self.title + ' might contain wrong infolabels year:
' + html.escape(str(resIt.infoLabels['year']))
+ self.assert_(type(resIt.infoLabels['year']) is int or resIt.infoLabels['year'].isdigit(), msgYear)
+ self.assert_(1900 < int(resIt.infoLabels['year']) < 2100, msgYear)
if resIt.title == typo(config.get_localized_string(30992), 'color kod bold'): # next page
nextPageItemlist = getattr(self.module, resIt.action)(resIt)
@@ -326,5 +341,7 @@ if __name__ == '__main__':
if 'KOD_TST_CH' not in os.environ:
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)
+ import webbrowser
+ webbrowser.open(os.path.join(config.get_runtime_path(), 'reports', 'report.html'))
else:
unittest.main()