# Path: vimswitch/test/BaseTestCase.py
# class BaseTestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#         unittest.TestCase.__init__(self, *args, **kwargs)
# 
#         # Python < 3.2 does not have assertNotRegex
#         if not hasattr(self, 'assertNotRegex'):
#             self.assertNotRegex = self.assertNotRegexpMatches
# 
#     def assertMultilineRegexpMatches(self, string, regexp):
#         """
#         Asserts that the entirety of `string` matches `regexp`. `regexp` can be
#         a multiline string with indentation.
#         """
#         regexp = textwrap.dedent(regexp)
#         regexp = regexp.strip()
#         regexp = '^' + regexp + '$'
#         regexp = re.compile(regexp, re.DOTALL)
# 
#         self.assertRegexpMatches(string, regexp)
# 
#     def assertStdout(self, stdout, regexp):
#         "Asserts that the `stdout` io stream matches `regexp`"
#         stdoutText = stdout.getvalue().strip()
#         self.assertMultilineRegexpMatches(stdoutText, regexp)
# 
#     def resetStdout(self, stdout):
#         stdout.seek(0)
#         stdout.truncate(0)
# 
# Path: vimswitch/test/Stubs.py
# def DiskIoStub():
#     diskIo = MagicMock(DiskIo)
#     return diskIo
# 
# Path: vimswitch/ActionResolver.py
# class ActionResolver:
#     def __init__(self, app, commandLineParser):
#         self.app = app
#         self.commandLineParser = commandLineParser
#         self.exitCode = 0
# 
#     def doActions(self):
#         actionString = self.commandLineParser.action
# 
#         if actionString == 'switchProfile':
#             action = createSwitchProfileAction(self.app)
#             action.profile = self.commandLineParser.profile
#         elif actionString == 'updateProfile':
#             action = createUpdateProfileAction(self.app)
#             action.profile = self.commandLineParser.profile
#         elif actionString == 'showCurrentProfile':
#             action = createShowCurrentProfileAction(self.app)
#         elif actionString == 'showVersion':
#             action = createShowVersionAction(self.app)
#         else:
#             action = createInvalidArgsAction(self.app)
#             action.errorMessage = self.commandLineParser.errorMessage
#             action.helpText = self.commandLineParser.helpText
# 
#         action.execute()
#         self.exitCode = action.exitCode
# 
# 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/CommandLineParser.py
# class CommandLineParser:
#     def __init__(self):
#         self.action = ''
#         self.profile = None
#         self.errorMessage = ''
#         self.helpText = ''
# 
#     def parse(self, argv):
#         parser = self._createParser()
#         self.helpText = parser.format_help()
# 
#         argv = argv[1:]  # Remove the program name from the arguments
#         arguments = parser.parse_args(argv)
# 
#         self._processArguments(parser, arguments, argv)
# 
#     def _createParser(self):
#         parser = CustomArgumentParser(
#             prog='vimswitch',
#             description='A utility for switching between vim profiles.')
#         parser.add_argument('profile', nargs='?')
#         parser.add_argument('-u', '--update', action='store_true',
#                             help='download profile again')
#         parser.add_argument('-v', '--version', action='store_true',
#                             help='show version')
#         return parser
# 
#     def _processArguments(self, parser, arguments, argv):
#         if parser.hasError:
#             self.errorMessage = parser.errorMessage
#             self.action = 'invalidArgs'
#         elif arguments.version:
#             self.action = 'showVersion'
#         elif arguments.update:
#             self.action = 'updateProfile'
#             profileName = arguments.profile
#             if profileName is None:
#                 self.profile = None
#             else:
#                 self.profile = Profile(profileName)
#         elif arguments.profile is not None:
#             self.action = 'switchProfile'
#             profileName = arguments.profile
#             self.profile = Profile(profileName)
#         elif len(argv) == 0:
#             self.action = 'showCurrentProfile'
# 
# 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


from .BaseTestCase import BaseTestCase
from .Stubs import DiskIoStub
from mock import patch
from vimswitch.ActionResolver import ActionResolver
from vimswitch.Application import Application
from vimswitch.CommandLineParser import CommandLineParser
from vimswitch.Profile import Profile


class TestActionResolver(BaseTestCase):

    def setUp(self):
        app = Application()
        app.diskIo = DiskIoStub()  # Fake all disk operations

# Path: vimswitch/test/BaseTestCase.py
# class BaseTestCase(unittest.TestCase):
#     def __init__(self, *args, **kwargs):
#         unittest.TestCase.__init__(self, *args, **kwargs)
# 
#         # Python < 3.2 does not have assertNotRegex
#         if not hasattr(self, 'assertNotRegex'):
#             self.assertNotRegex = self.assertNotRegexpMatches
# 
#     def assertMultilineRegexpMatches(self, string, regexp):
#         """
#         Asserts that the entirety of `string` matches `regexp`. `regexp` can be
#         a multiline string with indentation.
#         """
#         regexp = textwrap.dedent(regexp)
#         regexp = regexp.strip()
#         regexp = '^' + regexp + '$'
#         regexp = re.compile(regexp, re.DOTALL)
# 
#         self.assertRegexpMatches(string, regexp)
# 
#     def assertStdout(self, stdout, regexp):
#         "Asserts that the `stdout` io stream matches `regexp`"
#         stdoutText = stdout.getvalue().strip()
#         self.assertMultilineRegexpMatches(stdoutText, regexp)
# 
#     def resetStdout(self, stdout):
#         stdout.seek(0)
#         stdout.truncate(0)
# 
# Path: vimswitch/test/Stubs.py
# def DiskIoStub():
#     diskIo = MagicMock(DiskIo)
#     return diskIo
# 
# Path: vimswitch/ActionResolver.py
# class ActionResolver:
#     def __init__(self, app, commandLineParser):
#         self.app = app
#         self.commandLineParser = commandLineParser
#         self.exitCode = 0
# 
#     def doActions(self):
#         actionString = self.commandLineParser.action
# 
#         if actionString == 'switchProfile':
#             action = createSwitchProfileAction(self.app)
#             action.profile = self.commandLineParser.profile
#         elif actionString == 'updateProfile':
#             action = createUpdateProfileAction(self.app)
#             action.profile = self.commandLineParser.profile
#         elif actionString == 'showCurrentProfile':
#             action = createShowCurrentProfileAction(self.app)
#         elif actionString == 'showVersion':
#             action = createShowVersionAction(self.app)
#         else:
#             action = createInvalidArgsAction(self.app)
#             action.errorMessage = self.commandLineParser.errorMessage
#             action.helpText = self.commandLineParser.helpText
# 
#         action.execute()
#         self.exitCode = action.exitCode
# 
# 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/CommandLineParser.py
# class CommandLineParser:
#     def __init__(self):
#         self.action = ''
#         self.profile = None
#         self.errorMessage = ''
#         self.helpText = ''
# 
#     def parse(self, argv):
#         parser = self._createParser()
#         self.helpText = parser.format_help()
# 
#         argv = argv[1:]  # Remove the program name from the arguments
#         arguments = parser.parse_args(argv)
# 
#         self._processArguments(parser, arguments, argv)
# 
#     def _createParser(self):
#         parser = CustomArgumentParser(
#             prog='vimswitch',
#             description='A utility for switching between vim profiles.')
#         parser.add_argument('profile', nargs='?')
#         parser.add_argument('-u', '--update', action='store_true',
#                             help='download profile again')
#         parser.add_argument('-v', '--version', action='store_true',
#                             help='show version')
#         return parser
# 
#     def _processArguments(self, parser, arguments, argv):
#         if parser.hasError:
#             self.errorMessage = parser.errorMessage
#             self.action = 'invalidArgs'
#         elif arguments.version:
#             self.action = 'showVersion'
#         elif arguments.update:
#             self.action = 'updateProfile'
#             profileName = arguments.profile
#             if profileName is None:
#                 self.profile = None
#             else:
#                 self.profile = Profile(profileName)
#         elif arguments.profile is not None:
#             self.action = 'switchProfile'
#             profileName = arguments.profile
#             self.profile = Profile(profileName)
#         elif len(argv) == 0:
#             self.action = 'showCurrentProfile'
# 
# 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/test/test_ActionResolver.py
from .BaseTestCase import BaseTestCase
from .Stubs import DiskIoStub
from mock import patch
from vimswitch.ActionResolver import ActionResolver
from vimswitch.Application import Application
from vimswitch.CommandLineParser import CommandLineParser
from vimswitch.Profile import Profile



class TestActionResolver(BaseTestCase):

    def setUp(self):
        app = Application()
        app.diskIo = DiskIoStub()  # Fake all disk operations

        self.commandLineParser = CommandLineParser()