def test_template_date(pasila): fmt = TitleFormatter('${series}-${date}') assert fmt.format(**pasila) == 'Pasila-2018-04-12' fmt = TitleFormatter('${date}: ${series}') assert fmt.format(**pasila) == '2018-04-12: Pasila' fmt = TitleFormatter('${series}-${date}-${timestamp}') assert fmt.format(**pasila) == 'Pasila-2018-04-12-2018-04-12T16:30'
def test_template_literal(pasila): fmt = TitleFormatter('Areena ${series}-${episode}') assert fmt.format(**pasila) == 'Areena Pasila-S01E03' fmt = TitleFormatter('${series}: Areena-${episode}') assert fmt.format(**pasila) == 'Pasila: Areena-S01E03' fmt = TitleFormatter('${series}: ${episode} Areena') assert fmt.format(**pasila) == 'Pasila: S01E03 Areena' fmt = TitleFormatter('Areena: ${series} episode ${episode} Areena') assert fmt.format(**pasila) == 'Areena: Pasila episode S01E03 Areena'
def test_template_series_equals_main_title(): data = { 'title': 'Rantahotelli', 'series_title': 'Rantahotelli', } fmt = TitleFormatter('${series}') assert fmt.format(**data) == '' fmt = TitleFormatter('${title}') assert fmt.format(**data) == 'Rantahotelli' fmt = TitleFormatter('${series}${title}') assert fmt.format(**data) == 'Rantahotelli'
def test_template_series_duplicated_in_main_title(): data = { 'title': 'Jopet-show: Haikeaa joulua', 'series_title': 'Jopet-show', } fmt = TitleFormatter('${series}') assert fmt.format(**data) == 'Jopet-show' fmt = TitleFormatter('${title}') assert fmt.format(**data) == 'Haikeaa joulua' fmt = TitleFormatter('${series}${title}') assert fmt.format(**data) == 'Jopet-show: Haikeaa joulua'
def test_template(pasila): fmt = TitleFormatter('${series}${title}${episode}${timestamp}') assert fmt.format(**pasila) == 'Pasila: Vanhempainyhdistys: '\ 'tekstitys englanniksi: S01E03-2018-04-12T16:30' fmt = TitleFormatter('${series}${episode}${timestamp}') assert fmt.format(**pasila) == 'Pasila: S01E03-2018-04-12T16:30' fmt = TitleFormatter('${title}${timestamp}') assert fmt.format(**pasila) == 'Vanhempainyhdistys: '\ 'tekstitys englanniksi-2018-04-12T16:30' fmt = TitleFormatter('${timestamp}${title}') assert fmt.format(**pasila) == '2018-04-12T16:30: '\ 'Vanhempainyhdistys: tekstitys englanniksi'
def test_template_series_equals_main_title(): data = { 'title': 'Rantahotelli', 'series_title': 'Rantahotelli', 'publish_timestamp': datetime(2018, 4, 12, 16, 30, 45, tzinfo=FixedOffset(2)) } fmt = TitleFormatter('${series}') assert fmt.format(**data) == '' fmt = TitleFormatter('${title}') assert fmt.format(**data) == 'Rantahotelli' fmt = TitleFormatter('${series}${title}') assert fmt.format(**data) == 'Rantahotelli'
def test_template_series_duplicated_in_main_title(): data = { 'title': 'Jopet-show: Haikeaa joulua', 'series_title': 'Jopet-show', 'publish_timestamp': datetime(2018, 4, 12, 16, 30, 45, tzinfo=FixedOffset(2)) } fmt = TitleFormatter('${series}') assert fmt.format(**data) == 'Jopet-show' fmt = TitleFormatter('${title}') assert fmt.format(**data) == 'Haikeaa joulua' fmt = TitleFormatter('${series}: ${title}') assert fmt.format(**data) == 'Jopet-show: Haikeaa joulua'
def test_template_incorrectly_balanced_brackets(pasila): fmt = TitleFormatter('${series}: ${title: ${timestamp}}') assert fmt.format(**pasila) == 'Pasila: ${title: 2018-04-12T16:30}'
def test_unclosed_template(pasila): fmt = TitleFormatter('${series}: ${timestamp') assert fmt.format(**pasila) == 'Pasila: ${timestamp' fmt = TitleFormatter('${series}: ${title: ${timestamp}') assert fmt.format(**pasila) == 'Pasila: ${title: 2018-04-12T16:30'
def test_unknown_templates_are_not_substituted(pasila): fmt = TitleFormatter('${series}: ${invalid}: ${timestamp}') assert fmt.format(**pasila) == 'Pasila: ${invalid}: 2018-04-12T16:30'
def test_template_unbalanced_dollar_literals(pasila): fmt = TitleFormatter('${series} $$$ ABC') assert fmt.format(**pasila) == 'Pasila $$ ABC'
def test_template_literal_dollar_sign(pasila): fmt = TitleFormatter('${series} 500$$ ABC') assert fmt.format(**pasila) == 'Pasila 500$ ABC' fmt = TitleFormatter('${series} 500$$ $$$$ ABC') assert fmt.format(**pasila) == 'Pasila 500$ $$ ABC'
def test_template_duplicate_key(pasila): fmt = TitleFormatter('${series}: ${series}') assert fmt.format(**pasila) == 'Pasila: Pasila'