<commit_before>import os, shutil

from nose.tools import *

#stub urlopen calls
import urlopenmock

from core.errors import UnexpectedFormatException

class TestScript(object):
    base = 'python tvrenamr.py'
    working = 'tests/data/working'
    renamed = 'tests/data/renamed'
    organised = 'tests/data/organised'
    exceptions = 'tests/exceptions.txt'
    logging = 'debug'
    
    def setUp(self):
        files = 'tests/data/files'
        for fn in os.listdir(files): shutil.copy(os.path.join(files, fn), os.path.join(self.working, fn))
    
    def tearDown(self):
        shutil.rmtree(self.working)
        os.mkdir(self.working)
    
    """
    - use no options
    - use -r
    - use -a and -r
    - use -n
    - use -s
    - use -e
    - use -t
    - use -o
    - use --regex
    - use exceptions file
    - use --deluge
    - use --deluge-share-ratio
    - use unexpected format
    """
    def test_single_rename_with_no_options(self):
        os.system('%s -l%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.working))
        assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus The Truth.avi' % self.working))
    
    def test_single_rename_with_rename_folder_location_specified(self):
        os.system('%s -l%s -r%s %s/chuck.s1e10.blah.HDTV.XViD.avi' % (self.base, self.logging, self.renamed, self.working))
        assert_true(os.path.exists('%s/Chuck - 110 - Chuck Versus The Nemesis.avi' % self.renamed))
    
    def test_single_rename_with_rename_folder_location_specified_and_organise_option(self):
        os.system('%s -l%s --organise -r%s %s/chuck.s1e11.blah.HDTV.XViD.avi' % (self.base, self.logging, self.renamed, self.working))
        assert_true(os.path.exists('%s/Chuck/Season 1/Chuck - 111 - Chuck Versus The Crown Vic.avi' % self.renamed))
    
    def test_single_rename_with_name_option(self):
        os.system('%s -l%s -n%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, '\'Stargate SG-1\'', self.working))
        assert_true(os.path.exists('%s/Stargate SG-1 - 108 - The Nox.avi' % self.working))
    
    def test_single_rename_with_season_option(self):
        os.system('%s -l%s -s2 %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.working))
        assert_true(os.path.exists('%s/Chuck - 208 - Chuck Versus The Gravitron.avi' % self.working))
    
    def test_single_rename_with_episode_option(self):
        os.system('%s -l%s -e9 %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.working))
        assert_true(os.path.exists('%s/Chuck - 109 - Chuck Versus The Imported Hard Salami.avi' % self.working))
    
    def test_single_rename_with_leading_the_moved_to_end_of_show_name_option(self):
        os.system('%s -l%s -t %s/The.Big.Bang.Theory.S03E01.HDTV.XViD-NoTV.avi' % (self.base, self.logging, self.working))
        assert_true(os.path.exists('%s/Big Bang Theory, The - 301 - The Electric Can Opener Fluctuation.avi' % self.working))
    
    def test_single_rename_with_output_format_specified(self):
        os.system('%s -l%s -o%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, '\'%s%e - %n %t\'', self.working))
        assert_true(os.path.exists('%s/108 - Chuck Chuck Versus The Truth.avi' % self.working))
    
    def test_single_rename_with_custom_regular_expression_specified(self):
        os.system('%s -l%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.working))
        assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus The Truth.avi' % self.working))
    
    def test_single_rename_with_exceptions_file_used(self):
        # os.system('%s -l%s -x%s %s/avatar.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.exceptions, self.working))
        # assert_true(os.path.exists('%s/Avatar, The Last Airbender - 108 - Winter Solstice (2) - Avatar Roku.avi' % self.working))
        pass
    
    def test_single_rename_with_deluge_option(self):
        # os.system('%s -l%s --deluge %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, self.working))
        # assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus the Truth.avi' % self.working))
        pass
    
    def test_single_rename_with_deluge_share_ratio_option(self):
        # os.system('%s -l%s --deluge-share-ratio%d %s/chuck.s1e08.blah.HDTV.XViD.avi' % (self.base, self.logging, 2, self.working))
        # assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus the Truth.avi' % self.working))
        pass

    def test_single_rename_with_an_unexpected_format_raises_an_unexpected_format_exception(self):
        #assert_raises(UnexpectedFormatException, os.system('%s %s/\'West Wing.avi\'' % (self.base, self.logging, self.working)))
        pass

    
    """
    - use recursive and no options
    - use recursive and -r
    - use recursive and -a and -r
    - use recursive and -n
    - use recursive and -s
    - use recursive and -e
    - use recursive and -t
    - use recursive and -o<commit_msg>moved class variables out to module level<commit_after>import os, shutil

from nose.tools import *

#stub urlopen calls
import urlopenmock

from core.errors import UnexpectedFormatException

base = 'python tvrenamr.py'
working = 'tests/data/working'
renamed = 'tests/data/renamed'
organised = 'tests/data/organised'
exceptions = 'tests/exceptions.txt'
logging = 'debug'

class TestScript(object):
    
    def setUp(self):
        files = 'tests/data/files'
        for fn in os.listdir(files): shutil.copy(os.path.join(files, fn), os.path.join(working, fn))
    
    def tearDown(self):
        shutil.rmtree(working)
        os.mkdir(working)
    
    """
    - use no options
    - use -r
    - use -a and -r
    - use -n
    - use -s
    - use -e
    - use -t
    - use -o
    - use --regex
    - use exceptions file
    - use --deluge
    - use --deluge-share-ratio
    - use unexpected format
    """
    def test_single_rename_with_no_options(self):
        os.system('%s -l%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, working))
        assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus The Truth.avi' % working))
    
    def test_single_rename_with_rename_folder_location_specified(self):
        os.system('%s -l%s -r%s %s/chuck.s1e10.blah.HDTV.XViD.avi' % (base, logging, renamed, working))
        assert_true(os.path.exists('%s/Chuck - 110 - Chuck Versus The Nemesis.avi' % renamed))
    
    def test_single_rename_with_rename_folder_location_specified_and_organise_option(self):
        os.system('%s -l%s --organise -r%s %s/chuck.s1e11.blah.HDTV.XViD.avi' % (base, logging, renamed, working))
        assert_true(os.path.exists('%s/Chuck/Season 1/Chuck - 111 - Chuck Versus The Crown Vic.avi' % renamed))
    
    def test_single_rename_with_name_option(self):
        os.system('%s -l%s -n%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, '\'Stargate SG-1\'', working))
        assert_true(os.path.exists('%s/Stargate SG-1 - 108 - The Nox.avi' % working))
    
    def test_single_rename_with_season_option(self):
        os.system('%s -l%s -s2 %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, working))
        assert_true(os.path.exists('%s/Chuck - 208 - Chuck Versus The Gravitron.avi' % working))
    
    def test_single_rename_with_episode_option(self):
        os.system('%s -l%s -e9 %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, working))
        assert_true(os.path.exists('%s/Chuck - 109 - Chuck Versus The Imported Hard Salami.avi' % working))
    
    def test_single_rename_with_leading_the_moved_to_end_of_show_name_option(self):
        os.system('%s -l%s -t %s/The.Big.Bang.Theory.S03E01.HDTV.XViD-NoTV.avi' % (base, logging, working))
        assert_true(os.path.exists('%s/Big Bang Theory, The - 301 - The Electric Can Opener Fluctuation.avi' % working))
    
    def test_single_rename_with_output_format_specified(self):
        os.system('%s -l%s -o%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, '\'%s%e - %n %t\'', working))
        assert_true(os.path.exists('%s/108 - Chuck Chuck Versus The Truth.avi' % working))
    
    def test_single_rename_with_custom_regular_expression_specified(self):
        os.system('%s -l%s %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, working))
        assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus The Truth.avi' % working))
    
    def test_single_rename_with_exceptions_file_used(self):
        # os.system('%s -l%s -x%s %s/avatar.s1e08.blah.HDTV.XViD.avi' % (base, logging, exceptions, working))
        # assert_true(os.path.exists('%s/Avatar, The Last Airbender - 108 - Winter Solstice (2) - Avatar Roku.avi' % working))
        pass
    
    def test_single_rename_with_deluge_option(self):
        # os.system('%s -l%s --deluge %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, working))
        # assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus the Truth.avi' % working))
        pass
    
    def test_single_rename_with_deluge_share_ratio_option(self):
        # os.system('%s -l%s --deluge-share-ratio%d %s/chuck.s1e08.blah.HDTV.XViD.avi' % (base, logging, 2, working))
        # assert_true(os.path.exists('%s/Chuck - 108 - Chuck Versus the Truth.avi' % working))
        pass

    def test_single_rename_with_an_unexpected_format_raises_an_unexpected_format_exception(self):
        #assert_raises(UnexpectedFormatException, os.system('%s %s/\'West Wing.avi\'' % (base, logging, working)))
        pass

    
    """
    - use recursive and no options
    - use recursive and -r
    - use recursive and -a and -r
    - use recursive and -n
    - use recursive and -s
    - use recursive and -e
    - use recursive and -t
    - use recursive and -o
{'fraction_non_alphanumeric': 0.14148804616652927, 'fraction_numerical': 0.016488046166529265, 'mean_word_length': 2.927559692432214, 'pattern_counts': {'":': 0, '<': 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': '5359172', 'n_tokens_mistral': 3730, 'n_tokens_neox': 3623, 'n_words': 677}