#!/usr/bin/env python

"""Tests multi-episode filename generation
"""

from functional_runner import run_tvnamer, verify_out_data
from nose.plugins.attrib import attr


@attr("functional")
def test_multiep_different_names():
    """Default config - two different names are joined with 'multiep_join_name_with', 'multiep_format' doesn't matter
    """

    conf = """
    {"multiep_join_name_with": ", ",
    "batch": true,
    "multiep_format": "%(foo)s"}
    """

    out_data = run_tvnamer(
        with_files = ["star.trek.enterprise.s01e03e04.avi"],
        with_config = conf,
        with_input = "")

    expected_files = ['Star Trek: Enterprise - [01x03-04] - Fight or Flight, Strange New World.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_multiep_same_names():
    """Default config - same names, format according to 'multiep_format', 'multiep_join_name_with' doesn't matter
    """

    conf = """
    {"multiep_join_name_with": ", ",
    "batch": true,
    "multiep_format": "%(epname)s (%(episodemin)s-%(episodemax)s)"}
    """

    out_data = run_tvnamer(
        with_files = ["star.trek.enterprise.s01e01e02.avi"],
        with_config = conf,
        with_input = "")

    expected_files = ['Star Trek: Enterprise - [01x01-02] - Broken Bow (1-2).avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_multiep_same_names_without_number():
    """Default config - same names, ensure that missing number doesn't matter
    """

    conf = """
    {"multiep_join_name_with": ", ",
    "batch": true,
    "multiep_format": "%(epname)s (Parts %(episodemin)s-%(episodemax)s)"}
    """

    out_data = run_tvnamer(
        with_files = ["star.trek.deep.space.nine.s01e01e02.avi"],
        with_config = conf,
        with_input = "")

    expected_files = ['Star Trek: Deep Space Nine - [01x01-02] - Emissary (Parts 1-2).avi']

    verify_out_data(out_data, expected_files)

@@ -357,32 +357,162 @@
 conf = %22%22%22%0A    %7B
+%0A    %22output_filename_replacements%22: %5B%0A        %7B%22is_regex%22: false,%0A        %22match%22: %22:%22,%0A        %22replacement%22: %22 -%22%7D%0A    %5D,%0A%0A    
 %22multiep_join_na
@@ -519,32 +519,32 @@
 me_with%22: %22, %22,%0A
-
     %22batch%22: tru
@@ -755,33 +755,34 @@
 es = %5B'Star Trek
-:
+ -
  Enterprise - %5B0
@@ -1067,32 +1067,161 @@
 conf = %22%22%22%0A    %7B
+%0A    %22output_filename_replacements%22: %5B%0A        %7B%22is_regex%22: false,%0A        %22match%22: %22:%22,%0A        %22replacement%22: %22 -%22%7D%0A    %5D,%0A    
 %22multiep_join_na
@@ -1507,17 +1507,18 @@
 tar Trek
-:
+ -
  Enterpr
@@ -1780,16 +1780,146 @@
 %22%22%0A    %7B
+%0A    %22output_filename_replacements%22: %5B%0A        %7B%22is_regex%22: false,%0A        %22match%22: %22:%22,%0A        %22replacement%22: %22 -%22%7D%0A    %5D,%0A%0A    
 %22multiep
@@ -2224,17 +2224,18 @@
 tar Trek
-:
+ -
  Deep Sp

Fix tests on OS X failing due to ":" weirdness