Skip to content

Commit

Permalink
to much to tell … added a snatch tester …which test if the whole sear…
Browse files Browse the repository at this point in the history
…ch parsing picking routine works as wanted
  • Loading branch information
lad1337 committed Apr 17, 2012
1 parent a4514a5 commit aa40661
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 69 deletions.
2 changes: 1 addition & 1 deletion tests/all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)
Expand Down
5 changes: 0 additions & 5 deletions tests/db_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion tests/name_parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sickbeard
sickbeard.SYS_ENCODING = 'UTF-8'

DEBUG = VERBOSE = True
DEBUG = VERBOSE = False

simple_test_cases = {
'standard': {
Expand Down
5 changes: 2 additions & 3 deletions tests/pp_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
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):
Expand All @@ -42,6 +40,7 @@ def test_init_file_name(self):
def test_init_folder_name(self):
self.assertEqual(self.pp.folder_name, test.SHOWNAME)


class PPPrivateTests(test.SickbeardTestDBCase):


Expand Down
72 changes: 37 additions & 35 deletions tests/scene_helpers_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import test_lib as test

import sys, os.path
sys.path.append(os.path.abspath('..'))
Expand All @@ -8,26 +9,25 @@
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)
self.assertTrue(len(set(expected).intersection(set(result))) == len(expected))

dot_result = show_name_helpers.sceneToNormalShowNames(name.replace(' ','.'))
dot_expected = [x.replace(' ','.') for x in expected]
dot_result = show_name_helpers.sceneToNormalShowNames(name.replace(' ', '.'))
dot_expected = [x.replace(' ', '.') for x in expected]
self.assertTrue(len(set(dot_expected).intersection(set(dot_result))) == len(dot_expected))

def _test_allPossibleShowNames(self, name, tvdbid=0, tvrname=None, expected=[]):

result = show_name_helpers.allPossibleShowNames(Show(name, tvdbid, tvrname))
s = Show(tvdbid)
s.name = name
s.tvrname = tvrname

result = show_name_helpers.allPossibleShowNames(s)
self.assertTrue(len(set(expected).intersection(set(result))) == len(expected))

def _test_filterBadReleases(self, name, expected):
Expand All @@ -38,14 +38,20 @@ def _test_isGoodName(self, name, show):
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)'])
Expand All @@ -56,7 +62,7 @@ def test_sceneToNormalShowNames(self):
self._test_sceneToNormalShowNames('Show and Name 2010', ['Show and Name 2010', 'Show & Name 2010', 'Show and Name (2010)', 'Show & Name (2010)'])
self._test_sceneToNormalShowNames('show name us', ['show name us', 'show name (us)'])
self._test_sceneToNormalShowNames('Show And Name', ['Show And Name', 'Show & Name'])

# failure cases
self._test_sceneToNormalShowNames('Show Name 90210', ['Show Name 90210'])
self._test_sceneToNormalShowNames('Show Name YA', ['Show Name YA'])
Expand All @@ -66,7 +72,7 @@ def test_allPossibleShowNames(self):
myDB = db.DBConnection("cache.db")
myDB.action("INSERT INTO scene_exceptions (tvdb_id, show_name) VALUES (?,?)", [-1, 'Exception Test'])
common.countryList['Full Country Name'] = 'FCN'

self._test_allPossibleShowNames('Show Name', expected=['Show Name'])
self._test_allPossibleShowNames('Show Name', -1, expected=['Show Name', 'Exception Test'])
self._test_allPossibleShowNames('Show Name', tvrname='TVRage Name', expected=['Show Name', 'TVRage Name'])
Expand All @@ -77,22 +83,18 @@ def test_allPossibleShowNames(self):
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)
self._test_filterBadReleases('German.Show.S02.Some.Stuff-Grp', True)
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)
scene_exceptions.retrieve_exceptions()
print 'done.'

class SceneExceptionTestCase(unittest.TestCase):
def setUp(self):
super(SceneExceptionTestCase, self).setUp()
scene_exceptions.retrieve_exceptions()

def test_sceneExceptionsEmpty(self):
self.assertEqual(scene_exceptions.get_scene_exceptions(0), [])
Expand All @@ -104,33 +106,33 @@ def test_sceneExceptionByName(self):
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Babylon5'), 70726)
self.assertEqual(scene_exceptions.get_scene_exception_by_name('babylon 5'), 70726)
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Carlos 2010'), 164451)

def test_sceneExceptionByNameEmpty(self):
self.assertEqual(scene_exceptions.get_scene_exception_by_name('nothing useful'), None)

def test_sceneExceptionsResetNameCache(self):
# clear the exceptions
myDB = db.DBConnection("cache.db")
myDB.action("DELETE FROM scene_exceptions")

# put something in the cache
name_cache.addNameToCache('Cached Name', 0)

# updating should clear the cache so our previously "Cached Name" won't be in there
scene_exceptions.retrieve_exceptions()
self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), None)

# put something in the cache
name_cache.addNameToCache('Cached Name', 0)

# updating should not clear the cache this time since our exceptions didn't change
scene_exceptions.retrieve_exceptions()
self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)


if __name__ == '__main__':
if len(sys.argv) > 1:
suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneExceptionTestCase.test_'+sys.argv[1])
suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneExceptionTestCase.test_' + sys.argv[1])
unittest.TextTestRunner(verbosity=2).run(suite)
else:
suite = unittest.TestLoader().loadTestsFromTestCase(SceneTests)
Expand Down
110 changes: 110 additions & 0 deletions tests/snatch_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# coding=UTF-8
# Author: Dennis Lutter <[email protected]>
# 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)
Loading

0 comments on commit aa40661

Please sign in to comment.