# Path: vimswitch/test/FakeFileDownloader.py
# def createFakeFileDownloader(app, root):
#     diskIo = app.get('diskIo', createDiskIo(app))
#     fakeFileDownloader = FakeFileDownloader(root, diskIo)
#     return fakeFileDownloader
# 
# Path: vimswitch/test/FileSystemTestCase.py
# class FileSystemTestCase(BaseTestCase):
#     """
#     Inherit from this class when a unit test needs to access the disk. This
#     class sets up a sandbox so that disk modifications only occur within a
#     working directory. This keeps test code from affecting other files on the
#     system.
# 
#     To get a path relative to  the working directory use getTestPath(). To get a
#     path to test data use getDataPath().
# 
#     The working directory is cleared after every test so there is no need to do
#     it manually within your tests.
#     """
# 
#     def setUp(self):
#         self.sandbox = FileSystemSandbox()
#         self.sandbox.enable(self.getWorkingDir())
#         self.clearWorkingDirectory()
# 
#     def tearDown(self):
#         self.clearWorkingDirectory()
#         self.sandbox.disable()
# 
#     @classmethod
#     def getMyDir(self):
#         return os.path.dirname(__file__)
# 
#     @classmethod
#     def getTestPath(self, path):
#         "Returns path prepended by the working directory"
#         fullPath = os.path.join(self.getWorkingDir(), path)
#         return os.path.normpath(fullPath)
# 
#     @classmethod
#     def getDataPath(self, path):
#         "Returns path prepended by the test data directory"
#         dataDir = 'data'
#         fullPath = os.path.join(self.getMyDir(), dataDir, path)
#         return os.path.normpath(fullPath)
# 
#     @classmethod
#     def getWorkingDir(self):
#         """"Returns the path to a directory where we can safely create files and
#         directories during tests"""
#         dirName = 'workingDir'
#         return os.path.join(self.getMyDir(), dirName)
# 
#     def copyDataToWorkingDir(self, dataSrc, workingDirDest):
#         "Copies a file or dir from the data directory to the working directory"
#         dataSrc = self.getDataPath(dataSrc)
#         workingDirDest = self.getTestPath(workingDirDest)
#         if os.path.isdir(dataSrc):
#             shutil.copytree(dataSrc, workingDirDest)
#         else:
#             shutil.copy(dataSrc, workingDirDest)
# 
#     def clearWorkingDirectory(self):
#         for entry in os.listdir(self.getWorkingDir()):
#             fullPath = os.path.join(self.getWorkingDir(), entry)
#             if os.path.isfile(fullPath):
#                 # If file is readonly, make it writable
#                 if not os.access(fullPath, os.W_OK):
#                     os.chmod(fullPath, stat.S_IWRITE)
#                 os.remove(fullPath)
#             elif os.path.isdir(fullPath):
#                 shutil.rmtree(fullPath, onerror=_remove_readonly)
# 
# Path: vimswitch/Application.py
# class Application:
#     """
#     A container for components that are used application-wide.
# 
#     Examples of how this class can be used:
# 
#       - Set a component
#         `app.foo = myFoo`
# 
#       - Get (or create) a component:
#         `foo = app.get('foo', Foo())`
#         This will try to return `app.foo`. If that does not exist, then it will
#         set `app.foo = Foo()` and return that instead.
# 
#       - Get an already created component
#         `foo = app.foo`
#         Use this when you are sure that app.foo has already been set
#     """
# 
#     def get(self, attr, default):
#         """
#         Returns self.attr. If attr does not exist, then make self.attr = default
#         and then return default.
#         """
#         if hasattr(self, attr):
#             return getattr(self, attr)
#         else:
#             setattr(self, attr, default)
#             return default
# 
# Path: vimswitch/Profile.py
# class Profile:
#     def __init__(self, name):
#         self.name = name
# 
#     def getName(self):
#         return self.name
# 
#     def getDirName(self):
#         return self.name.replace('/', '.')
# 
#     def __eq__(self, other):
#         return isinstance(other, Profile) and self.name == other.name
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return "Profile('%s')" % self.name
# 
# Path: vimswitch/ProfileRetriever.py
# def getProfileRetriever(app):
#     return app.get('profileRetriever', createProfileRetriever(app))
# 
# Path: vimswitch/Settings.py
# class Settings:
# 
#     def __init__(self, homePath=''):
#         """
#         homePath is used as the prefix for all other paths. If homePath is not
#         specified it gets set to the user's home directory.
#         """
#         self.homePath = homePath or os.path.expanduser('~')
#         self.configPath = os.path.join(self.homePath, '.vimswitch')
#         self.configFilePath = os.path.join(self.configPath, 'vimswitchrc')
#         self.cachePath = os.path.join(self.configPath, 'profiles')
#         self.downloadsPath = os.path.join(self.configPath, 'downloads')
#         self.profileFiles = ['.vimrc', '_vimrc']
#         self.profileDirs = ['.vim', '_vim']
#         self.defaultProfile = Profile('default')
#         self.currentProfile = None
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__


from .FakeFileDownloader import createFakeFileDownloader
from .FileSystemTestCase import FileSystemTestCase
from mock import patch
from vimswitch.Application import Application
from vimswitch.Profile import Profile
from vimswitch.ProfileRetriever import getProfileRetriever
from vimswitch.Settings import Settings
from vimswitch.six import StringIO


class TestProfileRetriever(FileSystemTestCase):
    def setUp(self):
        FileSystemTestCase.setUp(self)
        app = Application()

        app.settings = Settings(self.getWorkingDir())
        app.fileDownloader = createFakeFileDownloader(app, self.getDataPath('fake_internet'))

        self.profileRetriever = getProfileRetriever(app)
        self.diskIo = app.diskIo
        self.diskIo.createDirWithParents(app.settings.downloadsPath)
        self.diskIo.createDirWithParents(app.settings.cachePath)

    def test_retrieve_retrievesProfile(self):

# Path: vimswitch/test/FakeFileDownloader.py
# def createFakeFileDownloader(app, root):
#     diskIo = app.get('diskIo', createDiskIo(app))
#     fakeFileDownloader = FakeFileDownloader(root, diskIo)
#     return fakeFileDownloader
# 
# Path: vimswitch/test/FileSystemTestCase.py
# class FileSystemTestCase(BaseTestCase):
#     """
#     Inherit from this class when a unit test needs to access the disk. This
#     class sets up a sandbox so that disk modifications only occur within a
#     working directory. This keeps test code from affecting other files on the
#     system.
# 
#     To get a path relative to  the working directory use getTestPath(). To get a
#     path to test data use getDataPath().
# 
#     The working directory is cleared after every test so there is no need to do
#     it manually within your tests.
#     """
# 
#     def setUp(self):
#         self.sandbox = FileSystemSandbox()
#         self.sandbox.enable(self.getWorkingDir())
#         self.clearWorkingDirectory()
# 
#     def tearDown(self):
#         self.clearWorkingDirectory()
#         self.sandbox.disable()
# 
#     @classmethod
#     def getMyDir(self):
#         return os.path.dirname(__file__)
# 
#     @classmethod
#     def getTestPath(self, path):
#         "Returns path prepended by the working directory"
#         fullPath = os.path.join(self.getWorkingDir(), path)
#         return os.path.normpath(fullPath)
# 
#     @classmethod
#     def getDataPath(self, path):
#         "Returns path prepended by the test data directory"
#         dataDir = 'data'
#         fullPath = os.path.join(self.getMyDir(), dataDir, path)
#         return os.path.normpath(fullPath)
# 
#     @classmethod
#     def getWorkingDir(self):
#         """"Returns the path to a directory where we can safely create files and
#         directories during tests"""
#         dirName = 'workingDir'
#         return os.path.join(self.getMyDir(), dirName)
# 
#     def copyDataToWorkingDir(self, dataSrc, workingDirDest):
#         "Copies a file or dir from the data directory to the working directory"
#         dataSrc = self.getDataPath(dataSrc)
#         workingDirDest = self.getTestPath(workingDirDest)
#         if os.path.isdir(dataSrc):
#             shutil.copytree(dataSrc, workingDirDest)
#         else:
#             shutil.copy(dataSrc, workingDirDest)
# 
#     def clearWorkingDirectory(self):
#         for entry in os.listdir(self.getWorkingDir()):
#             fullPath = os.path.join(self.getWorkingDir(), entry)
#             if os.path.isfile(fullPath):
#                 # If file is readonly, make it writable
#                 if not os.access(fullPath, os.W_OK):
#                     os.chmod(fullPath, stat.S_IWRITE)
#                 os.remove(fullPath)
#             elif os.path.isdir(fullPath):
#                 shutil.rmtree(fullPath, onerror=_remove_readonly)
# 
# Path: vimswitch/Application.py
# class Application:
#     """
#     A container for components that are used application-wide.
# 
#     Examples of how this class can be used:
# 
#       - Set a component
#         `app.foo = myFoo`
# 
#       - Get (or create) a component:
#         `foo = app.get('foo', Foo())`
#         This will try to return `app.foo`. If that does not exist, then it will
#         set `app.foo = Foo()` and return that instead.
# 
#       - Get an already created component
#         `foo = app.foo`
#         Use this when you are sure that app.foo has already been set
#     """
# 
#     def get(self, attr, default):
#         """
#         Returns self.attr. If attr does not exist, then make self.attr = default
#         and then return default.
#         """
#         if hasattr(self, attr):
#             return getattr(self, attr)
#         else:
#             setattr(self, attr, default)
#             return default
# 
# Path: vimswitch/Profile.py
# class Profile:
#     def __init__(self, name):
#         self.name = name
# 
#     def getName(self):
#         return self.name
# 
#     def getDirName(self):
#         return self.name.replace('/', '.')
# 
#     def __eq__(self, other):
#         return isinstance(other, Profile) and self.name == other.name
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return "Profile('%s')" % self.name
# 
# Path: vimswitch/ProfileRetriever.py
# def getProfileRetriever(app):
#     return app.get('profileRetriever', createProfileRetriever(app))
# 
# Path: vimswitch/Settings.py
# class Settings:
# 
#     def __init__(self, homePath=''):
#         """
#         homePath is used as the prefix for all other paths. If homePath is not
#         specified it gets set to the user's home directory.
#         """
#         self.homePath = homePath or os.path.expanduser('~')
#         self.configPath = os.path.join(self.homePath, '.vimswitch')
#         self.configFilePath = os.path.join(self.configPath, 'vimswitchrc')
#         self.cachePath = os.path.join(self.configPath, 'profiles')
#         self.downloadsPath = os.path.join(self.configPath, 'downloads')
#         self.profileFiles = ['.vimrc', '_vimrc']
#         self.profileDirs = ['.vim', '_vim']
#         self.defaultProfile = Profile('default')
#         self.currentProfile = None
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__


# Path: vimswitch/test/test_ProfileRetriever.py
from .FakeFileDownloader import createFakeFileDownloader
from .FileSystemTestCase import FileSystemTestCase
from mock import patch
from vimswitch.Application import Application
from vimswitch.Profile import Profile
from vimswitch.ProfileRetriever import getProfileRetriever
from vimswitch.Settings import Settings
from vimswitch.six import StringIO



class TestProfileRetriever(FileSystemTestCase):
    def setUp(self):
        FileSystemTestCase.setUp(self)
        app = Application()

        app.settings = Settings(self.getWorkingDir())
        app.fileDownloader = createFakeFileDownloader(app, self.getDataPath('fake_internet'))

        self.profileRetriever = getProfileRetriever(app)
        self.diskIo = app.diskIo
        self.diskIo.createDirWithParents(app.settings.downloadsPath)
        self.diskIo.createDirWithParents(app.settings.cachePath)

    def test_retrieve_retrievesProfile(self):

        profile = Profile('test/vimrc')