<commit_before>#project:tvnamer
#repository:http://github.com/dbr/tvnamer
#license:Creative Commons GNU GPL v2
# http://creativecommons.org/licenses/GPL/2.0/

"""Tests ignoreing files by regexp (e.g. all files with "sample" in the name)
"""

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

@attr("functional")
def test_no_blacklist():
    """Tests empty list of filename regexps is parsed as expected
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": []}
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s01e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'Scrubs - [01x02] - My Mentor.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_partial_blacklist():
    """Tests single match of filename blacklist
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [".*s02e01.*"]}
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'scrubs.s02e01.avi',
        'Scrubs - [02x02] - My Nightingale.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_full_blacklist():
    """Tests complete blacklist of all filenames
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [".*"]}
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)
<commit_msg>Modified unit tests to use a new config specification in blacklisted file names. Either simple matches or regex matches will be used instead of only regex<commit_after>#project:tvnamer
#repository:http://github.com/dbr/tvnamer
#license:Creative Commons GNU GPL v2
# http://creativecommons.org/licenses/GPL/2.0/

"""Tests ignoreing files by regexp (e.g. all files with "sample" in the name)
"""

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

@attr("functional")
def test_no_blacklist():
    """Tests empty list of filename regexps is parsed as expected
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": []}
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s01e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'Scrubs - [01x02] - My Mentor.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_partial_blacklist_using_simple_match():
    """Tests single match of filename blacklist using a simple match
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [
        {"is_regex": false,
         "match": "s02e01"}
        ]
    }
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'scrubs.s02e01.avi',
        'Scrubs - [02x02] - My Nightingale.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_partial_blacklist_using_regex():
    """Tests single match of filename blacklist using a regex match
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [
        {"is_regex": true,
         "match": ".*s02e01.*"}
        ]
    }
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'scrubs.s02e01.avi',
        'Scrubs - [02x02] - My Nightingale.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_partial_blacklist_using_mix():
    """Tests single match of filename blacklist using a mix of regex and simple match
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [
        {"is_regex": true,
         "match": ".*s02e01.*"},
        {"is_regex": false,
         "match": "s02e02"}
        ]
    }
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)

    expected_files = [
        'Scrubs - [01x01] - My First Day.avi',
        'scrubs.s02e01.avi',
        'scrubs.s02e02.avi']

    verify_out_data(out_data, expected_files)

@attr("functional")
def test_full_blacklist():
    """Tests complete blacklist of all filenames with a regex
    """

    conf = """
    {"always_rename": true,
    "select_first": true,
    "filename_blacklist": [
        {"is_regex": true,
         "match": ".*"}
        ]
    }
    """

    out_data = run_tvnamer(
        with_files = ['scrubs.s01e01.avi', 'scrubs.s02e01.avi', 'scrubs.s02e02.avi'],
        with_config = conf)

{'fraction_non_alphanumeric': 0.14334600760456273, 'fraction_numerical': 0.03384030418250951, 'mean_word_length': 2.8655400440852317, 'pattern_counts': {'":': 34, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '225166', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1824, 'n_words': 387}