# 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: mediahandler/util/config.py
# def _find_app(settings, app):
#     """Looks for an installed application in the user's local $PATH.
# 
#     Raises an ImportError if the application is not found.
#     """
# 
#     # Save in settings
#     name = app['name'].lower()
#     settings[name] = None
# 
#     # Retrieve local paths
#     split_token = ';' if mh.__iswin__ else ':'
#     local_paths = os.environ['PATH'].rsplit(split_token)
# 
#     # Look for app in local paths
#     for local_path in local_paths:
#         path = os.path.join(local_path, app['exec'])
# 
#         # If the path exists, store & exit the loop
#         if os.path.isfile(path):
#             settings[name] = path
#             break
# 
#         # Try .exe for windows
#         if mh.__iswin__:
#             win_path = path + '.exe'
#             if os.path.isfile(win_path):
#                 settings[name] = win_path
#                 break
# 
#     # If app not found, raise ImportError
#     if settings[name] is None:
#         error = '{0} application not found'.format(app['name'])
#         raise ImportError(error)


import os
import mock
import shutil
import tests.common as common
import mediahandler.types.audiobooks as Books
        import mutagen.mp3
from tests.common import unittest
from tests.common import MHTestSuite
from tests.test_media import MediaObjectTests
from mediahandler.util.config import _find_app
        expected = [
            os.path.join(self.folder, 'Part 1'),
            os.path.join(self.folder, 'Part 2'),
            os.path.join(self.folder, 'Part 3'),
        ]
        # Run test
        result = self.book._get_chapters(self.folder, file_array, 'mp3')
        # Check results
        self.assertEqual(len(result), 3)
        self.assertListEqual(result, expected)

    def test_chunks_single(self):
        # Set max length to 15 mins
        self.book.max_length = 900
        # Copy file into folder
        dst = os.path.join(self.folder, _book_track_mp3.format('1'))
        shutil.copy(self.audio_file, dst)
        # Set up query
        file_array = sorted(os.listdir(self.folder))
        # Make cover
        self.make_cover()
        expected = [os.path.join(self.folder, 'Part 1')]
        # Run test
        result = self.book._get_chapters(self.folder, file_array, 'mp3')
        # Check results
        self.assertEqual(len(result), 1)
        self.assertListEqual(result, expected)


# @unittest.skipUnless(sys.platform.startswith("linux"), "requires a Linux system")

# 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: mediahandler/util/config.py
# def _find_app(settings, app):
#     """Looks for an installed application in the user's local $PATH.
# 
#     Raises an ImportError if the application is not found.
#     """
# 
#     # Save in settings
#     name = app['name'].lower()
#     settings[name] = None
# 
#     # Retrieve local paths
#     split_token = ';' if mh.__iswin__ else ':'
#     local_paths = os.environ['PATH'].rsplit(split_token)
# 
#     # Look for app in local paths
#     for local_path in local_paths:
#         path = os.path.join(local_path, app['exec'])
# 
#         # If the path exists, store & exit the loop
#         if os.path.isfile(path):
#             settings[name] = path
#             break
# 
#         # Try .exe for windows
#         if mh.__iswin__:
#             win_path = path + '.exe'
#             if os.path.isfile(win_path):
#                 settings[name] = win_path
#                 break
# 
#     # If app not found, raise ImportError
#     if settings[name] is None:
#         error = '{0} application not found'.format(app['name'])
#         raise ImportError(error)


# Path: tests/test_books.py
import os
import mock
import shutil
import tests.common as common
import mediahandler.types.audiobooks as Books
        import mutagen.mp3
from tests.common import unittest
from tests.common import MHTestSuite
from tests.test_media import MediaObjectTests
from mediahandler.util.config import _find_app

        expected = [
            os.path.join(self.folder, 'Part 1'),
            os.path.join(self.folder, 'Part 2'),
            os.path.join(self.folder, 'Part 3'),
        ]
        # Run test
        result = self.book._get_chapters(self.folder, file_array, 'mp3')
        # Check results
        self.assertEqual(len(result), 3)
        self.assertListEqual(result, expected)

    def test_chunks_single(self):
        # Set max length to 15 mins
        self.book.max_length = 900
        # Copy file into folder
        dst = os.path.join(self.folder, _book_track_mp3.format('1'))
        shutil.copy(self.audio_file, dst)
        # Set up query
        file_array = sorted(os.listdir(self.folder))
        # Make cover
        self.make_cover()
        expected = [os.path.join(self.folder, 'Part 1')]
        # Run test
        result = self.book._get_chapters(self.folder, file_array, 'mp3')
        # Check results
        self.assertEqual(len(result), 1)
        self.assertListEqual(result, expected)


# @unittest.skipUnless(sys.platform.startswith("linux"), "requires a Linux system")

@unittest.skip("Too resource heavy right now")