Merge pull request #968 from JackDandy/feature/FixEpisodeNameNoneStr

Change don't allow none strings for episode names
This commit is contained in:
JackDandy 2017-08-22 14:34:47 +01:00 committed by GitHub
commit 7d117dbea0
2 changed files with 39 additions and 4 deletions

View file

@ -65,11 +65,15 @@ from common import NAMING_DUPLICATE, NAMING_EXTEND, NAMING_LIMITED_EXTEND, NAMIN
NAMING_LIMITED_EXTEND_E_PREFIXED
def dirty_setter(attr_name):
def dirty_setter(attr_name, types=None):
def wrapper(self, val):
if getattr(self, attr_name) != val:
setattr(self, attr_name, val)
self.dirty = True
if None is types or isinstance(val, types):
setattr(self, attr_name, val)
self.dirty = True
else:
logger.log('Didn\'t change property "%s" because expected: %s, but got: %s with value: %s' %
(attr_name, types, type(val), val), logger.WARNING)
return wrapper
@ -1486,7 +1490,7 @@ class TVEpisode(object):
self.wantedQuality = []
name = property(lambda self: self._name, dirty_setter('_name'))
name = property(lambda self: self._name, dirty_setter('_name', basestring))
season = property(lambda self: self._season, dirty_setter('_season'))
episode = property(lambda self: self._episode, dirty_setter('_episode'))
absolute_number = property(lambda self: self._absolute_number, dirty_setter('_absolute_number'))

View file

@ -98,6 +98,34 @@ class TVTests(test.SickbeardTestDBCase):
#TODO: implement
class TVFormatPatternTests(test.SickbeardTestDBCase):
def setUp(self):
super(TVFormatPatternTests, self).setUp()
sickbeard.showList = []
def test_getEpisode(self):
show = TVShow(1, 1, 'en')
show.name = 'show name'
show.tvrname = 'show name'
show.network = 'cbs'
show.genre = 'crime'
show.runtime = 40
show.status = '5'
show.airs = 'monday'
show.startyear = 1987
sickbeard.showList = [show]
show.episodes[1] = {}
show.episodes[1][1] = TVEpisode(show, 1, 1, '16)')
show.episodes[1][1].dirty = False
show.episodes[1][1].name = None
self.assertEqual(show.episodes[1][1].dirty, False)
self.assertEqual(show.episodes[1][1]._format_pattern('%SN - %Sx%0E - %EN - %QN'), 'show name - 1x01 - - Unknown')
show.episodes[1][1].dirty = False
show.episodes[1][1].name = 'ep name'
self.assertEqual(show.episodes[1][1].dirty, True)
self.assertEqual(show.episodes[1][1]._format_pattern('%SN - %Sx%0E - %EN - %QN'), 'show name - 1x01 - ep name - Unknown')
if __name__ == '__main__':
print('==================')
print('STARTING - TV TESTS')
@ -111,3 +139,6 @@ if __name__ == '__main__':
print('######################################################################')
suite = unittest.TestLoader().loadTestsFromTestCase(TVTests)
unittest.TextTestRunner(verbosity=2).run(suite)
print('######################################################################')
suite = unittest.TestLoader().loadTestsFromTestCase(TVFormatPatternTests)
unittest.TextTestRunner(verbosity=2).run(suite)