# 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: 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 re
import sys
import shutil
import tests.common as common
import mediahandler.handler as MH
import mediahandler.util.notify as Notify
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite
from mediahandler.util.config import _find_app

    def test_add_music_disabled(self):
        self.run_add_type_test('Music', False)

    def test_add_books_enabled(self):
        self.run_add_type_test('Audiobooks')

    def test_add_books_disabled(self):
        self.run_add_type_test('Audiobooks', False)

    def test_bad_module_name(self):
        # Modify args & settings for books
        delattr(self.handler.tv, 'enabled')
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file()
        # Run first test
        regex1 = r"'MHSettings' object has no attribute 'enabled'"
        self.assertRaisesRegexp(
            AttributeError, regex1,
            self.handler._add_media_files, self.tmp_file)
        # Second test
        self.handler.stype = 'Fake'
        regex2 = r"'MHandler' object has no attribute 'fake'"
        self.assertRaisesRegexp(
            AttributeError, regex2,
            self.handler._add_media_files, 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: 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_handler.py
import os
import re
import sys
import shutil
import tests.common as common
import mediahandler.handler as MH
import mediahandler.util.notify as Notify
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite
from mediahandler.util.config import _find_app


    def test_add_music_disabled(self):
        self.run_add_type_test('Music', False)

    def test_add_books_enabled(self):
        self.run_add_type_test('Audiobooks')

    def test_add_books_disabled(self):
        self.run_add_type_test('Audiobooks', False)

    def test_bad_module_name(self):
        # Modify args & settings for books
        delattr(self.handler.tv, 'enabled')
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file()
        # Run first test
        regex1 = r"'MHSettings' object has no attribute 'enabled'"
        self.assertRaisesRegexp(
            AttributeError, regex1,
            self.handler._add_media_files, self.tmp_file)
        # Second test
        self.handler.stype = 'Fake'
        regex2 = r"'MHandler' object has no attribute 'fake'"
        self.assertRaisesRegexp(
            AttributeError, regex2,
            self.handler._add_media_files, self.tmp_file)


def suite():

    s = MHTestSuite()