Example #1
0
def verify_name_gen(curtest, tvdb_instance):
    if "seasonnumber" in curtest:
        ep = EpisodeInfo(
            filename = curtest['input'],
            eptype = 'default',
            seriesname = curtest['parsedseriesname'],
            seasonnumber = curtest['seasonnumber'],
            episodenumbers = curtest['episodenumbers'])
    elif any([isinstance(x, datetime.date) for x in curtest['episodenumbers']]):
        ep = EpisodeInfo(
            filename = curtest['input'],
            eptype = 'dated',
            seriesname = curtest['parsedseriesname'],
            episodenumbers = curtest['episodenumbers'])
    else:
        ep = EpisodeInfo(
            filename = curtest['input'],
            eptype = 'noseason',
            seriesname = curtest['parsedseriesname'],
            episodenumbers = curtest['episodenumbers'])

    ep.populateFromTvdb(tvdb_instance, force_name = curtest.get("force_name"))

    assert ep.seriesname is not None, "Corrected series name was none"
    assert ep.episodename is not None, "Episode name was None"

    assertEquals(ep.seriesname, curtest['correctedseriesname'])
    assertEquals(ep.episodename, curtest['episodenames'])
Example #2
0
def test_no_name():
    """Episode without a name
    """
    ep = EpisodeInfo(
        seriesname="Scrubs", seasonnumber=1, episodenumbers=[2], episodename=None, filename="scrubs.example.file.avi"
    )

    assertEquals(ep.generateFilename(), "Scrubs - [01x02].avi")
Example #3
0
def test_datedepisode_no_name_no_ext():
    """DatedEpisodeInfo with no name or extension
    """
    ep = DatedEpisodeInfo(
        seriesname="Scrubs", episodenumbers=[datetime.date(2010, 11, 23)], episodename=None, filename=None
    )

    assertEquals(ep.generateFilename(), "Scrubs - [2010-11-23]")
Example #4
0
def test_multi_episodes_continuous():
    """A two-part episode should not have the episode name repeated
    """
    ep = EpisodeInfo(
        seriesname="Stargate SG-1",
        seasonnumber=1,
        episodenumbers=[1, 2],
        episodename=["Children of the Gods (1)", "Children of the Gods (2)"],
        filename="stargate.example.file.avi",
    )

    assertEquals(ep.generateFilename(), "Stargate SG-1 - [01x01-02] - Children of the Gods (1-2).avi")
Example #5
0
def check_case(curtest):
    """Runs test case, used by test_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()
    assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % (
        theep.seriesname.lower(),
        curtest['parsedseriesname'].lower())

    assertEquals(theep.seasonnumber, curtest['seasonnumber'])

    assertEquals(theep.episodenumbers, curtest['episodenumbers'])
def test_noseason_no_name_no_ext():
    """NoSeasonEpisodeInfo with no name or extension
    """
    ep = NoSeasonEpisodeInfo(
        seriesname = 'Scrubs',
        episodenumbers = [2],
        episodename = None,
        filename = None)

    assertEquals(
        ep.generateFilename(),
        'Scrubs - [02]')
Example #7
0
def test_multi_episodes_seperate():
    """File with two episodes, but with different names
    """
    ep = EpisodeInfo(
        seriesname="Stargate SG-1",
        seasonnumber=1,
        episodenumbers=[2, 3],
        episodename=["Children of the Gods (2)", "The Enemy Within"],
        filename="stargate.example.file.avi",
    )

    assertEquals(ep.generateFilename(), "Stargate SG-1 - [01x02-03] - Children of the Gods (2), The Enemy Within.avi")
def test_no_series_number():
    """Episode without season number
    """
    ep = NoSeasonEpisodeInfo(
        seriesname = 'Scrubs',
        episodenumbers = [2],
        episodename = 'My Mentor',
        filename = None)

    assertEquals(
        ep.generateFilename(),
        'Scrubs - [02] - My Mentor')
Example #9
0
def test_datedepisode_no_name_no_ext():
    """Dated EpisodeInfo with no name or extension
    """
    ep = EpisodeInfo(
        seriesname = 'Scrubs',
        eptype = 'dated',
        episodenumbers = [datetime.date(2010, 11, 23)],
        episodename = '',
        filename = '')

    assertEquals(
        ep.generateFilename(),
        'Scrubs - [2010-11-23]')
Example #10
0
def test_episode_no_name_no_ext():
    """EpisodeInfo with no name or extension
    """
    ep = EpisodeInfo(
        seriesname = 'Scrubs',
        seasonnumber = 1,
        episodenumbers = [2],
        episodename = '',
        filename = '')

    assertEquals(
        ep.generateFilename(),
        'Scrubs - [01x02]')
def test_multi_episodes_seperate():
    ep = EpisodeInfo(
        seriesname = 'Stargate SG-1',
        seasonnumber = 1,
        episodenumbers = [2, 3],
        episodename = [
            'Children of the Gods (2)',
            'The Enemy Within'],
        filename = 'stargate.example.file.avi')

    assertEquals(
        ep.generateFilename(),
        'Stargate SG-1 - [01x02-03] - Children of the Gods (2), The Enemy Within.avi')
Example #12
0
def test_downcase():
    """Simple episode name, converted to lowercase
    """

    ep = EpisodeInfo(
        seriesname="Scrubs",
        seasonnumber=1,
        episodenumbers=[2],
        episodename="My Mentor",
        filename="scrubs.example.file.avi",
    )

    assertEquals(ep.generateFilename(lowercase=True), "scrubs - [01x02] - my mentor.avi")
Example #13
0
def test_simple_no_ext():
    """Simple episode with out extension
    """
    ep = EpisodeInfo(
        seriesname = 'Scrubs',
        seasonnumber = 1,
        episodenumbers = [2],
        episodename = 'My Mentor',
        filename = None)

    assertEquals(
        ep.generateFilename(),
        'Scrubs - [01x02] - My Mentor')
Example #14
0
def verify_name_gen(curtest, tvdb_instance):
    ep = EpisodeInfo(
        seriesname=curtest["parsedseriesname"],
        seasonnumber=curtest["seasonnumber"],
        episodenumbers=curtest["episodenumbers"],
    )
    correctedSeriesName, epName = getEpisodeName(tvdb_instance, ep)

    assert correctedSeriesName is not None, "Corrected series name was none"
    assert epName is not None, "Episode name was None"

    assertEquals(epName, curtest["episodenames"])
    assertEquals(correctedSeriesName, curtest["correctedseriesname"])
Example #15
0
def test_verify_test_data_sanity():
    """Checks all test data is consistent.

    Keys within each test category must be consistent, but keys can vary
    category to category. E.g date-based episodes do not have a season number
    """
    from helpers import assertEquals

    for test_category, testcases in files.items():
        keys = [ctest.keys() for ctest in testcases]
        for k1 in keys:
            for k2 in keys:
                assertEquals(sorted(k1), sorted(k2))
def test_multi_episodes_continuous():
    ep = EpisodeInfo(
        seriesname = 'Stargate SG-1',
        seasonnumber = 1,
        episodenumbers = [1, 2],
        episodename = [
            'Children of the Gods (1)',
            'Children of the Gods (2)'],
        filename = 'stargate.example.file.avi')

    assertEquals(
        ep.generateFilename(),
        'Stargate SG-1 - [01x01-02] - Children of the Gods (1-2).avi')
Example #17
0
def test_single_episode():
    """Simple episode name, with show/season/episode/name/filename
    """

    ep = EpisodeInfo(
        seriesname="Scrubs",
        seasonnumber=1,
        episodenumbers=[2],
        episodename="My Mentor",
        filename="scrubs.example.file.avi",
    )

    assertEquals(ep.generateFilename(), "Scrubs - [01x02] - My Mentor.avi")
Example #18
0
def test_verify_test_data_sanity():
    """Checks all test data is consistent
    """
    from helpers import assertEquals

    keys = []
    for alltests in files.values():
        for ctest in alltests:
            keys.append(ctest.keys())

    for k1 in keys:
        for k2 in keys:
            assertEquals(sorted(k1), sorted(k2))
Example #19
0
def test_episode_numeric_title():
    # type: () -> None
    """An episode with a name starting with a number should not be
    detected as a range
    """

    ep = EpisodeInfo(seriesname='Star Trek TNG',
                     seasonnumber=1,
                     episodenumbers=[15],
                     episodename=['11001001'],
                     filename='STTNG-S01E15-11001001.avi')

    assertEquals(ep.generate_filename(),
                 'Star Trek TNG - [01x15] - 11001001.avi')
Example #20
0
def test_multi_episodes_seperate():
    """File with two episodes, but with different names
    """
    ep = EpisodeInfo(
        seriesname='Stargate SG-1',
        seasonnumber=1,
        episodenumbers=[2, 3],
        episodename=['Children of the Gods (2)', 'The Enemy Within'],
        filename='stargate.example.file.avi')

    assertEquals(
        ep.generateFilename(),
        'Stargate SG-1 - [01x02-03] - Children of the Gods (2), The Enemy Within.avi'
    )
Example #21
0
def test_episode_numeric_title():
    """An episode with a name starting with a number should not be
    detected as a range
    """

    ep = EpisodeInfo(
        seriesname="Star Trek TNG",
        seasonnumber=1,
        episodenumbers=[15],
        episodename=["11001001"],
        filename="STTNG-S01E15-11001001.avi",
    )

    assertEquals(ep.generateFilename(), "Star Trek TNG - [01x15] - 11001001.avi")
Example #22
0
def test_dotfilenames():
    """Tests makeValidFilename on filenames only consisting of .
    """
    assertEquals(makeValidFilename("."), "_.")
    assertEquals(makeValidFilename(".."), "_..")
    assertEquals(makeValidFilename("..."), "_...")
    assertEquals(makeValidFilename(".test.rc"), "_.test.rc")
Example #23
0
def test_multi_episodes_continuous():
    # type: () -> None
    """A two-part episode should not have the episode name repeated
    """
    ep = EpisodeInfo(
        seriesname='Stargate SG-1',
        seasonnumber=1,
        episodenumbers=[1, 2],
        episodename=['Children of the Gods (1)', 'Children of the Gods (2)'],
        filename='stargate.example.file.avi')

    assertEquals(
        ep.generate_filename(),
        'Stargate SG-1 - [01x01-02] - Children of the Gods (1-2).avi')
def test_dotfilenames():
    """Tests makeValidFilename on filenames only consisting of .
    """
    assertEquals(makeValidFilename("."), "_.")
    assertEquals(makeValidFilename(".."), "_..")
    assertEquals(makeValidFilename("..."), "_...")
    assertEquals(makeValidFilename(".test.rc"), "_.test.rc")
def test_windowsfilenames():
    """Tests makeValidFilename windows_safe flag makes Windows-safe filenames
    """
    assertEquals(makeValidFilename("Test/File.avi", windows_safe = True), "Test_File.avi")
    assertEquals(makeValidFilename("\\/:*?<Evil>|\"", windows_safe = True), "______Evil___")
    assertEquals(makeValidFilename("COM2.txt", windows_safe = True), "_COM2.txt")
    assertEquals(makeValidFilename("COM2", windows_safe = True), "_COM2")
Example #26
0
def _test_truncation(max_len, windows_safe):
    """Tests truncation works correctly.
    Called with different parameters for both Windows and Darwin/Linux.
    """
    assertEquals(makeValidFilename("a" * 300, windows_safe = windows_safe), "a" * max_len)
    assertEquals(makeValidFilename("a" * 255 + ".avi", windows_safe = windows_safe), "a" * (max_len-4) + ".avi")
    assertEquals(makeValidFilename("a" * 251 + "b" * 10 + ".avi", windows_safe = windows_safe), "a" * (max_len-4) + ".avi")
    assertEquals(makeValidFilename("test." + "a" * 255, windows_safe = windows_safe), "test." + "a" * (max_len-5))
def _test_truncation(max_len, windows_safe):
    """Tests truncation works correctly.
    Called with different parameters for both Windows and Darwin/Linux.
    """
    assertEquals(makeValidFilename("a" * 300, windows_safe = windows_safe), "a" * max_len)
    assertEquals(makeValidFilename("a" * 255 + ".avi", windows_safe = windows_safe), "a" * (max_len-4) + ".avi")
    assertEquals(makeValidFilename("a" * 251 + "b" * 10 + ".avi", windows_safe = windows_safe), "a" * (max_len-4) + ".avi")
    assertEquals(makeValidFilename("test." + "a" * 255, windows_safe = windows_safe), "test." + "a" * (max_len-5))
Example #28
0
def check_case(curtest):
    """Runs test case, used by test_parsing_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()

    if theep.seriesname is None and curtest['parsedseriesname'] is None:
        pass  # allow for None seriesname
    else:
        assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(
        ), "%s == %s" % (theep.seriesname.lower(),
                         curtest['parsedseriesname'].lower())

    assertEquals(theep.episodenumbers, curtest['episodenumbers'])
    if not isinstance(theep, (DatedEpisodeInfo, NoSeasonEpisodeInfo)):
        assertEquals(theep.seasonnumber, curtest['seasonnumber'])
Example #29
0
def check_case(curtest):
    """Runs test case, used by test_parsing_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()

    if theep.seriesname is None and curtest['parsedseriesname'] is None:
        pass # allow for None seriesname
    else:
        assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % (
            theep.seriesname.lower(),
            curtest['parsedseriesname'].lower())

    assertEquals(theep.episodenumbers, curtest['episodenumbers'])
    if hasattr(curtest, 'seasonnumber'):
        assertEquals(int(theep.seasonnumber), curtest['seasonnumber'])
Example #30
0
def check_case(curtest):
    """Runs test case, used by test_parsing_generator
    """
    parser = FileParser(curtest['input'])
    theep = parser.parse()

    if theep.seriesname is None and curtest['parsedseriesname'] is None:
        pass # allow for None seriesname
    else:
        assert theep.seriesname.lower() == curtest['parsedseriesname'].lower(), "%s == %s" % (
            theep.seriesname.lower(),
            curtest['parsedseriesname'].lower())

    assertEquals(theep.episodenumbers, curtest['episodenumbers'])
    if not isinstance(theep, (DatedEpisodeInfo, NoSeasonEpisodeInfo)):
        assertEquals(theep.seasonnumber, curtest['seasonnumber'])
Example #31
0
def test_windowsfilenames():
    """Tests makeValidFilename windows_safe flag makes Windows-safe filenames
    """
    assertEquals(makeValidFilename("Test/File.avi", windows_safe=True),
                 "Test_File.avi")
    assertEquals(makeValidFilename("\\/:*?<Evil>|\"", windows_safe=True),
                 "______Evil___")
    assertEquals(makeValidFilename("COM2.txt", windows_safe=True), "_COM2.txt")
    assertEquals(makeValidFilename("COM2", windows_safe=True), "_COM2")
Example #32
0
def verify_name_gen(curtest, tvdb_instance):
    if "seasonnumber" in curtest:
        ep = EpisodeInfo(
            seriesname=curtest["parsedseriesname"],
            seasonnumber=curtest["seasonnumber"],
            episodenumbers=curtest["episodenumbers"],
        )
    elif any([isinstance(x, datetime.date) for x in curtest["episodenumbers"]]):
        ep = DatedEpisodeInfo(seriesname=curtest["parsedseriesname"], episodenumbers=curtest["episodenumbers"])
    else:
        ep = NoSeasonEpisodeInfo(seriesname=curtest["parsedseriesname"], episodenumbers=curtest["episodenumbers"])

    ep.populateFromTvdb(tvdb_instance, force_name=curtest.get("force_name"))

    assert ep.seriesname is not None, "Corrected series name was none"
    assert ep.episodename is not None, "Episode name was None"

    assertEquals(ep.seriesname, curtest["correctedseriesname"])
    assertEquals(ep.episodename, curtest["episodenames"])
Example #33
0
def verify_name_gen(curtest, tvdb_instance):
    if "seasonnumber" in curtest:
        ep = EpisodeInfo(seriesname=curtest['parsedseriesname'],
                         seasonnumber=curtest['seasonnumber'],
                         episodenumbers=curtest['episodenumbers'])
    elif any([isinstance(x, datetime.date)
              for x in curtest['episodenumbers']]):
        ep = DatedEpisodeInfo(seriesname=curtest['parsedseriesname'],
                              episodenumbers=curtest['episodenumbers'])
    else:
        ep = NoSeasonEpisodeInfo(seriesname=curtest['parsedseriesname'],
                                 episodenumbers=curtest['episodenumbers'])

    ep.populateFromTvdb(tvdb_instance)

    assert ep.seriesname is not None, "Corrected series name was none"
    assert ep.episodename is not None, "Episode name was None"

    assertEquals(ep.seriesname, curtest['correctedseriesname'])
    assertEquals(ep.episodename, curtest['episodenames'])
def verify_name_gen(curtest, tvdb_instance):
    if "seasonnumber" in curtest:
        ep = EpisodeInfo(
            seriesname = curtest['parsedseriesname'],
            seasonnumber = curtest['seasonnumber'],
            episodenumbers = curtest['episodenumbers'])
    elif any([isinstance(x, datetime.date) for x in curtest['episodenumbers']]):
        ep = DatedEpisodeInfo(
            seriesname = curtest['parsedseriesname'],
            episodenumbers = curtest['episodenumbers'])
    else:
        ep = NoSeasonEpisodeInfo(
            seriesname = curtest['parsedseriesname'],
            episodenumbers = curtest['episodenumbers'])

    correctedSeriesName, epName = getEpisodeName(tvdb_instance, ep)

    assert correctedSeriesName is not None, "Corrected series name was none"
    assert epName is not None, "Episode name was None"

    assertEquals(epName, curtest['episodenames'])
    assertEquals(correctedSeriesName, curtest['correctedseriesname'])
Example #35
0
        def cur_test():
            for seas in xrange(1, 11):
                for ep in xrange(1, 11):

                    name_data = cdata['name_data']

                    name_data['seasno'] = seas
                    name_data['epno'] = ep

                    names = [x % name_data for x in name_formats]

                    for cur in names:
                        p = FileParser(cur).parse()

                        assertEquals(p.episodenumbers, [name_data['epno']])
                        assertEquals(p.seasonnumber, name_data['seasno'])
                        assertEquals(p.seriesname, name_data['seriesname'])
Example #36
0
        def cur_test():
            for seas in xrange(1, 11):
                for ep in xrange(1, 11):

                    name_data = cdata['name_data']

                    name_data['seasno'] = seas
                    name_data['epno'] = ep

                    names = [x % name_data for x in name_formats]

                    for cur in names:
                        p = FileParser(cur).parse()

                        assertEquals(p.episodenumbers, [name_data['epno']])
                        assertEquals(p.seriesname, name_data['seriesname'])
                        # Only EpisodeInfo has seasonnumber
                        if p.eptype not in ['dated', 'noseason']:
                            assertEquals(int(p.seasonnumber), name_data['seasno'])
Example #37
0
        def cur_test():
            for seas in xrange(1, 11):
                for ep in xrange(1, 11):

                    name_data = cdata['name_data']

                    name_data['seasno'] = seas
                    name_data['epno'] = ep

                    names = [x % name_data for x in name_formats]

                    for cur in names:
                        p = FileParser(cur).parse()

                        assertEquals(p.episodenumbers, [name_data['epno']])
                        assertEquals(p.seriesname, name_data['seriesname'])
                        # Only EpisodeInfo has seasonnumber
                        if not isinstance(p, (DatedEpisodeInfo, NoSeasonEpisodeInfo)):
                            assertEquals(p.seasonnumber, name_data['seasno'])
Example #38
0
        def cur_test():
            for seas in range(1, 11):
                for ep in range(1, 11):

                    name_data = cdata['name_data']

                    name_data['seasno'] = seas
                    name_data['epno'] = ep

                    names = [x % name_data for x in name_formats]

                    for cur in names:
                        p = FileParser(cur).parse()

                        assertEquals(p.episodenumbers, [name_data['epno']])
                        assertEquals(p.seriesname, name_data['seriesname'])
                        # Only EpisodeInfo has seasonnumber
                        if not isinstance(p, (DatedEpisodeInfo, NoSeasonEpisodeInfo)):
                            assertEquals(p.seasonnumber, name_data['seasno'])
Example #39
0
def test_noseasonepisodeinfo_naming():
    """Parsing a e23 episode should return NoSeasonEpisodeInfo class
    """
    p = FileParser("scrubs - e23.avi").parse()
    assertType(p, NoSeasonEpisodeInfo)
    assertEquals(p.generateFilename(), "scrubs - [23].avi")
Example #40
0
def test_datedepisodeinfo_naming():
    """Parsing a 2009.06.05 episode should return DatedEpisodeInfo class
    """
    p = FileParser("scrubs.2009.06.05.avi").parse()
    assertType(p, DatedEpisodeInfo)
    assertEquals(p.generateFilename(), "scrubs - [2009-06-05].avi")
Example #41
0
def test_episodeinfo_naming():
    """Parsing a s01e01 episode should return EpisodeInfo class
    """
    p = FileParser("scrubs.s01e01.avi").parse()
    assertType(p, EpisodeInfo)
    assertEquals(p.generateFilename(), "scrubs - [01x01].avi")
Example #42
0
def test_customblacklist():
    """Test make_valid_filename custom_blacklist feature
    """
    assertEquals(make_valid_filename("Test.avi", custom_blacklist="e"),
                 "T_st.avi")
Example #43
0
def test_dirseperators():
    """Tests make_valid_filename removes directory separators
    """
    assertEquals(make_valid_filename("Test/File.avi"), "Test_File.avi")
    assertEquals(make_valid_filename("Test/File"), "Test_File")
Example #44
0
def test_basic():
    """Test make_valid_filename does not mess up simple filenames
    """
    assertEquals(make_valid_filename("test.avi"), "test.avi")
    assertEquals(make_valid_filename("Test File.avi"), "Test File.avi")
    assertEquals(make_valid_filename("Test"), "Test")
Example #45
0
def test_noseasonepisodeinfo_naming():
    """Parsing a e23 episode should return NoSeasonEpisodeInfo class
    """
    p = FileParser("scrubs - e23.avi").parse()
    assertType(p, NoSeasonEpisodeInfo)
    assertEquals(p.generateFilename(), "scrubs - [23].avi")
Example #46
0
def test_replacewith():
    """Tests replacing blacklisted character with custom characters
    """
    assertEquals(makeValidFilename("My Test File.avi", custom_blacklist=" ", replace_with="."), "My.Test.File.avi")