# 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):
#     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()


import os
import shutil
import tests.common as common
import mediahandler.types as Types
import mediahandler.util.notify as Notify
from re import search, escape
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite
        to = os.path.join(os.path.sep, 'Media', 'TV', 'Downton Abbey', 'Season 5', 'Downton.Abbey.S05E03.mkv')
        output = """Rename episodes using [TheTVDB]
Auto-detected query: [Downton Abbey]
Fetching episode data for [Downton Abbey]
Skipped [{fro}] because [{to}] already exists
Processed 1 files
Done ?(?????)?
""".format(fro=fro, to=to)
        (new_file, skipped) = self.media._process_output(output, self.tmp_file)
        expected = [os.path.basename(fro)]
        self.assertEqual(skipped, expected)
        self.assertEqual(new_file, [])

    def test_remove_bad_files(self):
        # Add files to folder
        bad_folder = tempfile.mkdtemp(dir=self.folder)
        file1 = common.make_tmp_file('.nfo', self.folder)
        file2 = common.make_tmp_file('.srt', self.folder)
        file3 = common.make_tmp_file('.txt', bad_folder)
        # Run test
        self.media._remove_bad_files(self.folder)
        # Check results
        self.assertFalse(os.path.exists(file1))
        self.assertFalse(os.path.exists(file2))
        self.assertFalse(os.path.exists(file3))
        self.assertTrue(os.path.exists(bad_folder))
        self.assertTrue(os.path.exists(self.tmp_file))


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):
#     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
import os
import shutil
import tests.common as common
import mediahandler.types as Types
import mediahandler.util.notify as Notify
from re import search, escape
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite

        to = os.path.join(os.path.sep, 'Media', 'TV', 'Downton Abbey', 'Season 5', 'Downton.Abbey.S05E03.mkv')
        output = """Rename episodes using [TheTVDB]
Auto-detected query: [Downton Abbey]
Fetching episode data for [Downton Abbey]
Skipped [{fro}] because [{to}] already exists
Processed 1 files
Done ?(?????)?
""".format(fro=fro, to=to)
        (new_file, skipped) = self.media._process_output(output, self.tmp_file)
        expected = [os.path.basename(fro)]
        self.assertEqual(skipped, expected)
        self.assertEqual(new_file, [])

    def test_remove_bad_files(self):
        # Add files to folder
        bad_folder = tempfile.mkdtemp(dir=self.folder)
        file1 = common.make_tmp_file('.nfo', self.folder)
        file2 = common.make_tmp_file('.srt', self.folder)
        file3 = common.make_tmp_file('.txt', bad_folder)
        # Run test
        self.media._remove_bad_files(self.folder)
        # Check results
        self.assertFalse(os.path.exists(file1))
        self.assertFalse(os.path.exists(file2))
        self.assertFalse(os.path.exists(file3))
        self.assertTrue(os.path.exists(bad_folder))
        self.assertTrue(os.path.exists(self.tmp_file))


def suite():

    s = MHTestSuite()