# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
#     def setUpSuite(self):
#     def tearDownSuite(self):
#     def run(self, result):
# def skip_unless_has_mod(module, submodule):
# def get_test_id(size=4):
# def random_string(size=5):
# def temp_file(name=None):
# def make_tmp_file(text=None, tdir=None):
# def get_conf_file():
# def get_orig_settings():
# def get_settings(conf=None):
# def get_types_by_string():
# def get_types_by_id():
# def get_pushover_api():
# def get_pushbullet_api():
# def get_google_api():
# def remove_file(file_path):
# 
# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
# 
#     def setUpSuite(self):
#         # Back up current config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if not os.path.exists(backup):
#             shutil.move(curr_config, backup)
#         # Make new config for testing
#         Config.make_config()
# 
#     def tearDownSuite(self):
#         # Restore original config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if os.path.exists(backup):
#             shutil.move(backup, curr_config)
# 
#     def run(self, result):
#         # Before tests
#         self.setUpSuite()
#         # Set buffering
#         result.buffer = True
#         # Run tests
#         super(MHTestSuite, self).run(result)
#         # After tests
#         self.tearDownSuite()
# 
# Path: tests/test_media.py
# class MediaObjectTests(unittest.TestCase):
# 
#     def setUp(self):
#         # Conf
#         self.conf = common.get_conf_file()
#         # Set up push object
#         self.push = Notify.MHPush({
#             'enabled': False,
#             'notify_name': '',
#             'pushover':{
#                 'api_key': common.random_string(),
#                 'user_key': common.random_string(),
#             },
#         }, True)
#         # Make temp stuff
#         self.folder = tempfile.mkdtemp(
#             dir=os.path.dirname(self.conf))
#         self.tmp_file = common.make_tmp_file('.avi')
#         # Build base settings
#         self.settings = common.get_settings()['TV']
#         self.settings['folder'] = self.folder
# 
#     def tearDown(self):
#         if os.path.exists(self.folder):
#             shutil.rmtree(self.folder)
#         if os.path.exists(self.tmp_file):
#             os.unlink(self.tmp_file)


import os
import mediahandler.types.tv as TV
from re import escape
from tests.common import unittest
from tests.common import MHTestSuite
from tests.test_media import MediaObjectTests
    def test_tv_output_skipped(self):
        title = "Archer"
        season = "Season 3"
        one = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e01.avi")
        one_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E01.avi")
        two = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e02.avi")
        two_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E02.avi")
        three = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e03.avi")
        three_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E03.avi")
        four = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e03.nfo")
        four_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E03.nfo")
        output = """Rename episodes using [TheTVDB]
Auto-detected query: [greys anatomy]
Fetching episode data for [Grey's Anatomy]
Skipped [{one}] because [{one_to}] already exists
Skipped [{two}] because [{two_to}] already exists
Skipped [{three}] because [{three_to}] already exists
[COPY] Rename [{four}] to [{four_to}]
Processed 3 files
Done ?(?????)?
""".format(one=one, one_to=one_to, two=two, two_to=two_to,
           three=three, three_to=three_to, four=four, four_to=four_to)
        (new_files, skipped) = self.episode._process_output(
            output, self.tmp_file)
        expected = [os.path.basename(one), os.path.basename(two), os.path.basename(three)]
        self.assertEqual(new_files, [])
        self.assertEqual(skipped, expected)


def suite():

# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
#     def setUpSuite(self):
#     def tearDownSuite(self):
#     def run(self, result):
# def skip_unless_has_mod(module, submodule):
# def get_test_id(size=4):
# def random_string(size=5):
# def temp_file(name=None):
# def make_tmp_file(text=None, tdir=None):
# def get_conf_file():
# def get_orig_settings():
# def get_settings(conf=None):
# def get_types_by_string():
# def get_types_by_id():
# def get_pushover_api():
# def get_pushbullet_api():
# def get_google_api():
# def remove_file(file_path):
# 
# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
# 
#     def setUpSuite(self):
#         # Back up current config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if not os.path.exists(backup):
#             shutil.move(curr_config, backup)
#         # Make new config for testing
#         Config.make_config()
# 
#     def tearDownSuite(self):
#         # Restore original config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if os.path.exists(backup):
#             shutil.move(backup, curr_config)
# 
#     def run(self, result):
#         # Before tests
#         self.setUpSuite()
#         # Set buffering
#         result.buffer = True
#         # Run tests
#         super(MHTestSuite, self).run(result)
#         # After tests
#         self.tearDownSuite()
# 
# Path: tests/test_media.py
# class MediaObjectTests(unittest.TestCase):
# 
#     def setUp(self):
#         # Conf
#         self.conf = common.get_conf_file()
#         # Set up push object
#         self.push = Notify.MHPush({
#             'enabled': False,
#             'notify_name': '',
#             'pushover':{
#                 'api_key': common.random_string(),
#                 'user_key': common.random_string(),
#             },
#         }, True)
#         # Make temp stuff
#         self.folder = tempfile.mkdtemp(
#             dir=os.path.dirname(self.conf))
#         self.tmp_file = common.make_tmp_file('.avi')
#         # Build base settings
#         self.settings = common.get_settings()['TV']
#         self.settings['folder'] = self.folder
# 
#     def tearDown(self):
#         if os.path.exists(self.folder):
#             shutil.rmtree(self.folder)
#         if os.path.exists(self.tmp_file):
#             os.unlink(self.tmp_file)


# Path: tests/test_tv.py
import os
import mediahandler.types.tv as TV
from re import escape
from tests.common import unittest
from tests.common import MHTestSuite
from tests.test_media import MediaObjectTests

    def test_tv_output_skipped(self):
        title = "Archer"
        season = "Season 3"
        one = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e01.avi")
        one_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E01.avi")
        two = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e02.avi")
        two_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E02.avi")
        three = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e03.avi")
        three_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E03.avi")
        four = os.path.join(os.path.sep, "Downloaded", f"{title} {season}", "Archer.s03e03.nfo")
        four_to = os.path.join(os.path.sep, self.folder, title, season, "Archer.S03E03.nfo")
        output = """Rename episodes using [TheTVDB]
Auto-detected query: [greys anatomy]
Fetching episode data for [Grey's Anatomy]
Skipped [{one}] because [{one_to}] already exists
Skipped [{two}] because [{two_to}] already exists
Skipped [{three}] because [{three_to}] already exists
[COPY] Rename [{four}] to [{four_to}]
Processed 3 files
Done ?(?????)?
""".format(one=one, one_to=one_to, two=two, two_to=two_to,
           three=three, three_to=three_to, four=four, four_to=four_to)
        (new_files, skipped) = self.episode._process_output(
            output, self.tmp_file)
        expected = [os.path.basename(one), os.path.basename(two), os.path.basename(three)]
        self.assertEqual(new_files, [])
        self.assertEqual(skipped, expected)


def suite():

    s = MHTestSuite()