Private GIT

Skip to content
Snippets Groups Projects
Commit aa406617 authored by Dennis Lutter's avatar Dennis Lutter
Browse files

to much to tell … added a snatch tester …which test if the whole search...

to much to tell … added a snatch tester …which test if the whole search parsing picking routine works as wanted
parent a4514a5c
Branches
Tags
No related merge requests found
......@@ -21,7 +21,7 @@ if __name__ == "__main__":
import glob
import unittest
test_file_strings = [ x for x in glob.glob('*_tests.py') if x != __file__]
test_file_strings = [ x for x in glob.glob('*_tests.py') if not x in __file__]
module_strings = [file_string[0:len(file_string) - 3] for file_string in test_file_strings]
suites = [unittest.defaultTestLoader.loadTestsFromName(file_string) for file_string in module_strings]
testSuite = unittest.TestSuite(suites)
......
......@@ -20,11 +20,6 @@
import unittest
import test_lib as test
import sys, os.path
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
class DBBasicTests(test.SickbeardTestDBCase):
......
......@@ -10,7 +10,7 @@ from sickbeard.name_parser import parser
import sickbeard
sickbeard.SYS_ENCODING = 'UTF-8'
DEBUG = VERBOSE = True
DEBUG = VERBOSE = False
simple_test_cases = {
'standard': {
......
......@@ -23,14 +23,12 @@ import unittest
import test_lib as test
import sys, os.path
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
from sickbeard.postProcessor import PostProcessor
import sickbeard
from sickbeard.tv import TVEpisode, TVShow
class PPInitTests(unittest.TestCase):
def setUp(self):
......@@ -42,6 +40,7 @@ class PPInitTests(unittest.TestCase):
def test_init_folder_name(self):
self.assertEqual(self.pp.folder_name, test.SHOWNAME)
class PPPrivateTests(test.SickbeardTestDBCase):
......
import unittest
import test_lib as test
import sys, os.path
sys.path.append(os.path.abspath('..'))
......@@ -8,14 +9,10 @@ from sickbeard import show_name_helpers, scene_exceptions, common, name_cache
import sickbeard
from sickbeard import db
from sickbeard.databases import cache_db
from sickbeard.tv import TVShow as Show
class Show:
def __init__(self, name, tvdbid, tvrname):
self.name = name
self.tvdbid = tvdbid
self.tvrname = tvrname
class SceneTests(unittest.TestCase):
class SceneTests(test.SickbeardTestDBCase):
def _test_sceneToNormalShowNames(self, name, expected):
result = show_name_helpers.sceneToNormalShowNames(name)
......@@ -26,8 +23,11 @@ class SceneTests(unittest.TestCase):
self.assertTrue(len(set(dot_expected).intersection(set(dot_result))) == len(dot_expected))
def _test_allPossibleShowNames(self, name, tvdbid=0, tvrname=None, expected=[]):
s = Show(tvdbid)
s.name = name
s.tvrname = tvrname
result = show_name_helpers.allPossibleShowNames(Show(name, tvdbid, tvrname))
result = show_name_helpers.allPossibleShowNames(s)
self.assertTrue(len(set(expected).intersection(set(result))) == len(expected))
def _test_filterBadReleases(self, name, expected):
......@@ -38,14 +38,20 @@ class SceneTests(unittest.TestCase):
self.assertTrue(show_name_helpers.isGoodResult(name, show))
def test_isGoodName(self):
self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show/Name', 0, ''))
self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show. Name', 0, ''))
self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show- Name', 0, ''))
self._test_isGoodName('Show.Name.Part.IV.Test-Test', Show('Show Name', 0, ''))
self._test_isGoodName('Show.Name.1x02.Test-Test', Show('Show Name', 0, ''))
self._test_isGoodName('Show.Name.S01.Test-Test', Show('Show Name', 0, ''))
self._test_isGoodName('Show.Name.E02.Test-Test', Show('Show: Name', 0, ''))
self._test_isGoodName('Show Name Season 2 Test', Show('Show: Name', 0, ''))
listOfcases = [('Show.Name.S01E02.Test-Test', 'Show/Name'),
('Show.Name.S01E02.Test-Test', 'Show. Name'),
('Show.Name.S01E02.Test-Test', 'Show- Name'),
('Show.Name.Part.IV.Test-Test', 'Show Name'),
('Show.Name.S01.Test-Test', 'Show Name'),
('Show.Name.E02.Test-Test', 'Show: Name'),
('Show Name Season 2 Test', 'Show: Name'),
]
for testCase in listOfcases:
scene_name, show_name = testCase
s = Show(0)
s.name = show_name
self._test_isGoodName(scene_name, s)
def test_sceneToNormalShowNames(self):
self._test_sceneToNormalShowNames('Show Name 2010', ['Show Name 2010', 'Show Name (2010)'])
......@@ -77,7 +83,6 @@ class SceneTests(unittest.TestCase):
self._test_allPossibleShowNames('Show Name (FCN)', -1, 'TVRage Name', expected=['Show Name (FCN)', 'Show Name (Full Country Name)', 'Exception Test', 'TVRage Name'])
def test_filterBadReleases(self):
self._test_filterBadReleases('Show.S02.German.Stuff-Grp', False)
self._test_filterBadReleases('Show.S02.Some.Stuff-Core2HD', False)
self._test_filterBadReleases('Show.S02.Some.German.Stuff-Grp', False)
......@@ -85,14 +90,11 @@ class SceneTests(unittest.TestCase):
self._test_filterBadReleases('Show.S02.This.Is.German', False)
class SceneExceptionTestCase(test.SickbeardTestDBCase):
print 'Loading exceptions...',
db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)
def setUp(self):
super(SceneExceptionTestCase, self).setUp()
scene_exceptions.retrieve_exceptions()
print 'done.'
class SceneExceptionTestCase(unittest.TestCase):
def test_sceneExceptionsEmpty(self):
self.assertEqual(scene_exceptions.get_scene_exceptions(0), [])
......
# coding=UTF-8
# Author: Dennis Lutter <lad1337@gmail.com>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Sick Beard is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
import random
import unittest
import test_lib as test
import sys, os.path
import sickbeard.search as search
import sickbeard
from sickbeard.tv import TVEpisode, TVShow
import sickbeard.common as c
tests = {"Dexter": {"q": c.HD, "s": 5, "e": 7, "b": 'Dexter.S05E07.720p.BluRay.X264-REWARD', "i": ['Dexter.S05E07.720p.BluRay.X264-REWARD', 'Dexter.S05E07.720p.X264-REWARD']},
"House": {"q": c.HD, "s": 4, "e": 5, "b": 'House.4x5.720p.BluRay.X264-REWARD', "i": ['Dexter.S05E04.720p.X264-REWARD', 'House.4x5.720p.BluRay.X264-REWARD']}
}
def _create_fake_xml(items):
xml = '<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:newznab="http://www.newznab.com/DTD/2010/feeds/attributes/" encoding="utf-8"><channel>'
for item in items:
xml += '<item><title>' + item + '</title>\n'
xml += '<link>http://fantasy.com/' + item + '</link></item>'
xml += '</channel></rss>'
return xml
# the real one tries to contact tvdb just stop it from getting more info on the ep
def _fake_specifyEP(self, season, episode):
pass
TVEpisode.specifyEpisode = _fake_specifyEP
searchItems = []
class SearchTest(test.SickbeardTestDBCase):
def _fake_getURL(self, url, headers=None):
global searchItems
return _create_fake_xml(searchItems)
def _fake_isActive(self):
return True
def __init__(self, something):
for provider in sickbeard.providers.sortedProviderList():
provider.getURL = self._fake_getURL
#provider.isActive = self._fake_isActive
super(SearchTest, self).__init__(something)
def test_generator(tvdbdid, show_name, curData, forceSearch):
def test(self):
global searchItems
searchItems = curData["i"]
show = TVShow(tvdbdid)
show.name = show_name
show.quality = curData["q"]
show.saveToDB()
sickbeard.showList.append(show)
episode = TVEpisode(show, curData["s"], curData["e"])
episode.status = c.WANTED
episode.saveToDB()
bestResult = search.findEpisode(episode, forceSearch)
if not bestResult:
self.assertEqual(curData["b"], bestResult)
self.assertEqual(curData["b"], bestResult.name)
return test
if __name__ == '__main__':
print "=================="
print "STARTING - Snatch TESTS"
print "=================="
print "######################################################################"
# create the test methods
tvdbdid = 1
for forceSearch in (True, False):
for name, curData in tests.items():
if forceSearch:
test_name = 'test_manual_%s_%s' % (name, tvdbdid)
else:
test_name = 'test_%s_%s' % (name, tvdbdid)
test = test_generator(tvdbdid, name, curData, forceSearch)
setattr(SearchTest, test_name, test)
tvdbdid += 1
suite = unittest.TestLoader().loadTestsFromTestCase(SearchTest)
unittest.TextTestRunner(verbosity=2).run(suite)
......@@ -27,11 +27,28 @@ sys.path.append(os.path.abspath('../lib'))
import sickbeard
import shutil, time
from sickbeard import encodingKludge as ek
from sickbeard import encodingKludge as ek, providers, tvcache
from sickbeard import db
from sickbeard.databases import mainDB
from sickbeard.databases import cache_db
#=================
# test globals
#=================
TESTDIR = os.path.abspath('.')
TESTDBNAME = "sickbeard.db"
TESTCACHEDBNAME = "cache.db"
SHOWNAME = u"show name"
SEASON = 4
EPISODE = 2
FILENAME = u"show name - s0" + str(SEASON) + "e0" + str(EPISODE) + ".mkv"
FILEDIR = os.path.join(TESTDIR, SHOWNAME)
FILEPATH = os.path.join(FILEDIR, FILENAME)
#sickbeard.logger.sb_log_instance = sickbeard.logger.SBRotatingLogHandler(os.path.join(TESTDIR, 'sickbeard.log'), sickbeard.logger.NUM_LOGS, sickbeard.logger.LOG_SIZE)
sickbeard.logger.SBRotatingLogHandler.log_file = os.path.join(os.path.join(TESTDIR, 'Logs'), 'test_sickbeard.log')
#=================
......@@ -43,22 +60,23 @@ sickbeard.QUALITY_DEFAULT = 4
sickbeard.SEASON_FOLDERS_DEFAULT = 1
sickbeard.SEASON_FOLDERS_FORMAT = 'Season %02d'
sickbeard.NAMING_SHOW_NAME = 1
sickbeard.NAMING_EP_NAME = 1
sickbeard.NAMING_EP_TYPE = 0
sickbeard.NAMING_MULTI_EP_TYPE = 1
sickbeard.NAMING_SEP_TYPE = 0
sickbeard.NAMING_USE_PERIODS = 0
sickbeard.NAMING_QUALITY = 0
sickbeard.NAMING_DATES = 1
sickbeard.PROVIDER_ORDER = ["sick_beard_index"]
sickbeard.newznabProviderList = providers.getNewznabProviderList("Sick Beard Index|http://momo.sickbeard.com/||1!!!NZBs.org|http://beta.nzbs.org/||0")
sickbeard.providerList = providers.makeProviderList()
sickbeard.PROG_DIR = os.path.abspath('..')
sickbeard.DATA_DIR = sickbeard.PROG_DIR
#=================
# test globals
#=================
TESTDIR = os.path.abspath('.')
TESTDBNAME = "test_sickbeard.db"
SHOWNAME = u"show name"
SEASON = 4
EPISODE = 2
FILENAME = u"show name - s0" + str(SEASON) + "e0" + str(EPISODE) + ".mkv"
FILEDIR = os.path.join(TESTDIR, SHOWNAME)
FILEPATH = os.path.join(FILEDIR, FILENAME)
sickbeard.LOG_DIR = os.path.join(TESTDIR, 'Logs')
sickbeard.logger.sb_log_instance.initLogging(False)
#=================
# dummy functions
......@@ -84,13 +102,40 @@ class SickbeardTestDBCase(unittest.TestCase):
tearDown_test_db()
tearDown_test_episode_file()
class TestDBConnection(db.DBConnection, object):
def __init__(self, dbFileName=TESTDBNAME):
dbFileName = os.path.join(TESTDIR, dbFileName)
super(TestDBConnection, self).__init__(dbFileName)
class TestCacheDBConnection(TestDBConnection, object):
def __init__(self, providerName):
db.DBConnection.__init__(self, os.path.join(TESTDIR, TESTCACHEDBNAME))
# Create the table if it's not already there
try:
sql = "CREATE TABLE "+providerName+" (name TEXT, season NUMERIC, episodes TEXT, tvrid NUMERIC, tvdbid NUMERIC, url TEXT, time NUMERIC, quality TEXT);"
self.connection.execute(sql)
self.connection.commit()
except sqlite3.OperationalError, e:
if str(e) != "table "+providerName+" already exists":
raise
# Create the table if it's not already there
try:
sql = "CREATE TABLE lastUpdate (provider TEXT, time NUMERIC);"
self.connection.execute(sql)
self.connection.commit()
except sqlite3.OperationalError, e:
if str(e) != "table lastUpdate already exists":
raise
# this will override the normal db connection
sickbeard.db.DBConnection = TestDBConnection
sickbeard.tvcache.CacheDBConnection = TestCacheDBConnection
#=================
......@@ -104,12 +149,19 @@ def setUp_test_db():
# fix up any db problems
db.sanityCheckDatabase(db.DBConnection(), mainDB.MainSanityCheck)
#and for cache.b too
db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)
def tearDown_test_db():
"""Deletes the test db
although this seams not to work on my system it leaves me with an zero kb file
"""
os.remove(ek.ek(os.path.join, TESTDIR, TESTDBNAME))
#return False
if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)):
os.remove(os.path.join(TESTDIR, TESTDBNAME))
if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)):
os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME))
def setUp_test_episode_file():
if not os.path.exists(FILEDIR):
......@@ -119,9 +171,12 @@ def setUp_test_episode_file():
f.write("foo bar")
f.close()
def tearDown_test_episode_file():
shutil.rmtree(FILEDIR)
tearDown_test_db()
if __name__ == '__main__':
print "=================="
print "Dont call this directly"
......
......@@ -19,13 +19,8 @@
import random
import unittest
import test_lib as test
import sys, os.path
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
import sickbeard
from sickbeard.tv import TVEpisode, TVShow
from sickbeard import exceptions
......@@ -69,7 +64,6 @@ class TVShowTests(test.SickbeardTestDBCase):
self.assertEqual(show.name, "newName")
class TVEpisodeTests(test.SickbeardTestDBCase):
def setUp(self):
......@@ -78,7 +72,12 @@ class TVEpisodeTests(test.SickbeardTestDBCase):
def test_init_empty_db(self):
show = TVShow(0001, "en")
self.assertRaises(exceptions.EpisodeNotFoundException, TVEpisode, show, test.SEASON, test.EPISODE)
ep = TVEpisode(show, 1, 1)
ep.name = "asdasdasdajkaj"
ep.saveToDB()
ep.loadFromDB(1, 1)
self.assertEqual(ep.name, "asdasdasdajkaj")
class TVTests(test.SickbeardTestDBCase):
......@@ -101,8 +100,6 @@ class TVTests(test.SickbeardTestDBCase):
#TODO: implement
if __name__ == '__main__':
print "=================="
print "STARTING - TV TESTS"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment