4 import rtv_propertiesfile
, rtv_programmeinfo
6 class Favourite(rtv_propertiesfile
.PropertiesFile
):
10 self
.sub_title_re
= None
12 self
.not_channel
= None
13 self
.deleteAfterDays
= None
16 self
.destination
= None
17 self
.real_title
= None
18 self
.unique_subtitles
= True
22 self
._sub
_title
_re
= None
25 def matches( self
, pi
):
27 if self
.title_re
is None:
28 return False # This favourite is empty
30 if self
._title
_re
is None:
31 self
._title
_re
= re
.compile( self
.title_re
+ "$" )
33 if not self
._title
_re
.match( pi
.title
):
36 if self
.not_channel
is not None and self
.not_channel
== pi
.channel
:
39 if self
.channel
is not None and self
.channel
!= pi
.channel
:
42 if self
.sub_title_re
is not None and pi
.sub_title
is not None:
43 if self
._sub
_title
_re
is None:
44 self
._sub
_title
_re
= re
.compile( self
.sub_title_re
+ "$" )
45 if not self
._sub
_title
_re
.match( pi
.sub_title
):
49 # TODO: other things to match on e.g. time, categories
51 class FakeProg( object ):
52 def __init__( self
, title
, channel
, sub_title
= None ):
54 self
.channel
= channel
55 self
.sub_title
= sub_title
57 def test_Empty_favourite_never_matches():
59 assert( not fav
.matches( FakeProg( "t", "c" ) ) )
61 def test_Wrong_title_doesnt_match():
63 fav
.title_re
= "other"
64 assert( not fav
.matches( FakeProg( "this", "c" ) ) )
66 def test_Right_title_matches():
69 assert( fav
.matches( FakeProg( "this", "c" ) ) )
71 def test_Wrong_subtitle_doesnt_match():
74 fav
.sub_title_re
= "other"
75 assert( not fav
.matches( FakeProg( "this", "c", "this_sub" ) ) )
77 def test_Right_subtitle_matches():
80 fav
.sub_title_re
= "this_sub"
81 assert( fav
.matches( FakeProg( "this", "c", "this_sub" ) ) )
83 def test_Wrong_channel_doesnt_match():
87 assert( not fav
.matches( FakeProg( "this", "c" ) ) )
89 def test_Right_channel_does_match():
93 assert( fav
.matches( FakeProg( "this", "c" ) ) )
95 def test_Not_channel_excludes():
98 fav
.not_channel
= "Dave"
99 assert( not fav
.matches( FakeProg( "this", "Dave" ) ) )
101 def test_Unmatching_not_channel_doesnt_exclude():
103 fav
.title_re
= "this"
104 fav
.not_channel
= "Dave"
105 assert( fav
.matches( FakeProg( "this", "BBC One" ) ) )
108 test_Empty_favourite_never_matches()
109 test_Wrong_title_doesnt_match()
110 test_Right_title_matches()
111 test_Wrong_subtitle_doesnt_match()
112 test_Right_subtitle_matches()
113 test_Wrong_channel_doesnt_match()
114 test_Right_channel_does_match()
115 test_Not_channel_excludes()
116 test_Unmatching_not_channel_doesnt_exclude()