# Path: handroll/commands/base.py
# class Command(object):
#     """A command class with the minimal interface required for each command."""
# 
#     name = 'command'
#     description = 'the command description'
#     help = 'the command help'
# 
#     def register(self, subparsers):
#         """Register required options.
# 
#         Commands should invoke this method and use the returned parser to
#         add command specific options.
#         """
#         parser = subparsers.add_parser(
#             self.name, description=self.description, help=self.help)
#         parser.set_defaults(func=self.run)
#         return parser
# 
#     def run(self, args):
#         """Run whatever action the command intends."""
#         raise NotImplementedError()
# 
# Path: handroll/commands/base.py
# def finish():
#     print(_('Complete.'))
#     sys.exit()
# 
# Path: handroll/commands/build.py
# class BuildCommand(Command):
# 
#     name = 'build'
#     description = _('Build a site in an output directory.')
#     help = _('build a site')
# 
#     def register(self, subparsers):
#         parser = super(BuildCommand, self).register(subparsers)
#         parser.add_argument(
#             'site', nargs='?', help=_('the path to your website'))
#         parser.add_argument('outdir', nargs='?', help=_(
#             'an optional output directory to create or'
#             ' update if it already exists'))
# 
#     def run(self, args):
#         site = Site.build(args)
#         director = prepare_director(args, site)
#         director.produce()
#         finish()
# 
# Path: handroll/commands/scaffold.py
# class ScaffoldCommand(Command):
# 
#     name = 'scaffold'
#     description = _(
#         'Make a new handroll site from a scaffold '
#         'or list the available scaffolds')
#     help = _('make a new handroll site')
# 
#     def register(self, subparsers):
#         parser = super(ScaffoldCommand, self).register(subparsers)
#         parser.add_argument(
#             'scaffold', nargs='?', help=_('the scaffold to generate'))
#         parser.add_argument(
#             'site', nargs='?', default='site',
#             help=_('the path to your website'))
# 
#     def run(self, args):
#         if args.scaffold:
#             scaffolder.make(args.scaffold, args.site)
#             finish()
#         else:
#             scaffolder.list_scaffolds()
# 
# Path: handroll/commands/watch.py
# class WatchCommand(Command):
# 
#     name = 'watch'
#     description = _(
#         'watch the site for changes and'
#         ' run a web server in the output directory')
#     help = _('watch a site and run a web server')
# 
#     def register(self, subparsers):
#         parser = super(WatchCommand, self).register(subparsers)
#         parser.add_argument(
#             'site', nargs='?', help=_('the path to your website'))
#         parser.add_argument('outdir', nargs='?', help=_(
#             'an optional output directory to create or'
#             ' update if it already exists'))
# 
#     def run(self, args):
#         site = Site.build(args)
#         director = prepare_director(args, site)
#         director.produce()
#         serve(site, director)
# 
# Path: handroll/tests/testcase.py
# class TestCase(unittest.TestCase):
# 
#     def __init__(self, methodName='runTest'):
#         super(TestCase, self).__init__(methodName)
#         self.factory = Factory()


import mock
from handroll.commands import Command
from handroll.commands.base import finish
from handroll.commands.build import BuildCommand
from handroll.commands.scaffold import ScaffoldCommand
from handroll.commands.watch import WatchCommand
from handroll.tests import TestCase

class TestWatchCommand(TestCase):

    def test_register_site(self):
        parser = mock.Mock()
        subparsers = mock.Mock()
        subparsers.add_parser.return_value = parser
        command = WatchCommand()
        command.register(subparsers)
        site_call = (('site',), {'nargs': '?', 'help': mock.ANY})
        self.assertIn(site_call, parser.add_argument.call_args_list)

    def test_register_outdir(self):
        parser = mock.Mock()
        subparsers = mock.Mock()
        subparsers.add_parser.return_value = parser
        command = WatchCommand()
        command.register(subparsers)
        outdir_call = (('outdir',), {'nargs': '?', 'help': mock.ANY})
        self.assertIn(outdir_call, parser.add_argument.call_args_list)

    @mock.patch('handroll.commands.watch.serve')
    def test_complete_watch(self, serve):
        site = self.factory.make_site()
        args = mock.Mock(site=site.path, outdir='.')
        command = WatchCommand()
        command.run(args)
        self.assertTrue(serve.called)



# Path: handroll/commands/base.py
# class Command(object):
#     """A command class with the minimal interface required for each command."""
# 
#     name = 'command'
#     description = 'the command description'
#     help = 'the command help'
# 
#     def register(self, subparsers):
#         """Register required options.
# 
#         Commands should invoke this method and use the returned parser to
#         add command specific options.
#         """
#         parser = subparsers.add_parser(
#             self.name, description=self.description, help=self.help)
#         parser.set_defaults(func=self.run)
#         return parser
# 
#     def run(self, args):
#         """Run whatever action the command intends."""
#         raise NotImplementedError()
# 
# Path: handroll/commands/base.py
# def finish():
#     print(_('Complete.'))
#     sys.exit()
# 
# Path: handroll/commands/build.py
# class BuildCommand(Command):
# 
#     name = 'build'
#     description = _('Build a site in an output directory.')
#     help = _('build a site')
# 
#     def register(self, subparsers):
#         parser = super(BuildCommand, self).register(subparsers)
#         parser.add_argument(
#             'site', nargs='?', help=_('the path to your website'))
#         parser.add_argument('outdir', nargs='?', help=_(
#             'an optional output directory to create or'
#             ' update if it already exists'))
# 
#     def run(self, args):
#         site = Site.build(args)
#         director = prepare_director(args, site)
#         director.produce()
#         finish()
# 
# Path: handroll/commands/scaffold.py
# class ScaffoldCommand(Command):
# 
#     name = 'scaffold'
#     description = _(
#         'Make a new handroll site from a scaffold '
#         'or list the available scaffolds')
#     help = _('make a new handroll site')
# 
#     def register(self, subparsers):
#         parser = super(ScaffoldCommand, self).register(subparsers)
#         parser.add_argument(
#             'scaffold', nargs='?', help=_('the scaffold to generate'))
#         parser.add_argument(
#             'site', nargs='?', default='site',
#             help=_('the path to your website'))
# 
#     def run(self, args):
#         if args.scaffold:
#             scaffolder.make(args.scaffold, args.site)
#             finish()
#         else:
#             scaffolder.list_scaffolds()
# 
# Path: handroll/commands/watch.py
# class WatchCommand(Command):
# 
#     name = 'watch'
#     description = _(
#         'watch the site for changes and'
#         ' run a web server in the output directory')
#     help = _('watch a site and run a web server')
# 
#     def register(self, subparsers):
#         parser = super(WatchCommand, self).register(subparsers)
#         parser.add_argument(
#             'site', nargs='?', help=_('the path to your website'))
#         parser.add_argument('outdir', nargs='?', help=_(
#             'an optional output directory to create or'
#             ' update if it already exists'))
# 
#     def run(self, args):
#         site = Site.build(args)
#         director = prepare_director(args, site)
#         director.produce()
#         serve(site, director)
# 
# Path: handroll/tests/testcase.py
# class TestCase(unittest.TestCase):
# 
#     def __init__(self, methodName='runTest'):
#         super(TestCase, self).__init__(methodName)
#         self.factory = Factory()


# Path: handroll/tests/test_commands.py
import mock
from handroll.commands import Command
from handroll.commands.base import finish
from handroll.commands.build import BuildCommand
from handroll.commands.scaffold import ScaffoldCommand
from handroll.commands.watch import WatchCommand
from handroll.tests import TestCase


class TestWatchCommand(TestCase):

    def test_register_site(self):
        parser = mock.Mock()
        subparsers = mock.Mock()
        subparsers.add_parser.return_value = parser
        command = WatchCommand()
        command.register(subparsers)
        site_call = (('site',), {'nargs': '?', 'help': mock.ANY})
        self.assertIn(site_call, parser.add_argument.call_args_list)

    def test_register_outdir(self):
        parser = mock.Mock()
        subparsers = mock.Mock()
        subparsers.add_parser.return_value = parser
        command = WatchCommand()
        command.register(subparsers)
        outdir_call = (('outdir',), {'nargs': '?', 'help': mock.ANY})
        self.assertIn(outdir_call, parser.add_argument.call_args_list)

    @mock.patch('handroll.commands.watch.serve')
    def test_complete_watch(self, serve):
        site = self.factory.make_site()
        args = mock.Mock(site=site.path, outdir='.')
        command = WatchCommand()
        command.run(args)
        self.assertTrue(serve.called)



class TestScaffoldCommand(TestCase):