Example #1
0
    def test_exception_raised_select_template_no_config(self, mock_exit):
        arguments = PropertyMock(return_value={'--select': True})
        type(self.interface).arguments = arguments
        self.config.items.side_effect = ConfigParser.NoSectionError('template')

        s = Settings(self.interface, self.config)

        with self.assertRaises(FacioException):
            with self.assertRaises(ConfigParser.NoSectionError):
                s.get_template_path()
        self.mocked_facio_exceptions_puts.assert_any_call(
            'Error: Missing [template] section in Facio configuration file.')
        self.assertTrue(mock_exit.called)
Example #2
0
    def test_exception_raised_select_template_no_config(self, mock_exit):
        arguments = PropertyMock(return_value={
            '--select': True})
        type(self.interface).arguments = arguments
        self.config.items.side_effect = ConfigParser.NoSectionError('template')

        s = Settings(self.interface, self.config)

        with self.assertRaises(FacioException):
            with self.assertRaises(ConfigParser.NoSectionError):
                s.get_template_path()
        self.mocked_facio_exceptions_puts.assert_any_call(
            'Error: Missing [template] section in Facio configuration file.')
        self.assertTrue(mock_exit.called)
Example #3
0
File: run.py Project: jackqu7/Facio
    def run(self):
        """ Run the Facio processes. """

        interface = CommandLineInterface()
        interface.start()

        config = ConfigurationFile()
        parsed = config.read()

        settings = Settings(interface, parsed)
        state.update_context_variables(settings.get_variables())

        template = Template(settings.get_template_path())
        template.update_copy_ignore_globs(settings.copy_ignore_globs())
        template.update_render_ignore_globs(settings.render_ignore_globs())
        template.copy()

        pipeline = Hook()
        pipeline.load(os.path.join(
            state.get_project_root(),
            HOOKS_FILE_NAME))

        if pipeline.has_before():
            pipeline.run_before()

        template.rename()
        template.render()

        if pipeline.has_after():
            pipeline.run_after()

        self.success('Done')
Example #4
0
    def run(self):
        """ Run the Facio processes. """

        interface = CommandLineInterface()
        interface.start()

        config = ConfigurationFile()
        parsed = config.read()

        settings = Settings(interface, parsed)
        state.update_context_variables(settings.get_variables())

        template = Template(settings.get_template_path())
        template.update_copy_ignore_globs(settings.copy_ignore_globs())
        template.update_render_ignore_globs(settings.render_ignore_globs())
        template.copy()

        pipeline = Hook()
        pipeline.load(os.path.join(state.get_project_root(), HOOKS_FILE_NAME))

        if pipeline.has_before():
            pipeline.run_before()

        template.rename()
        template.render()

        if pipeline.has_after():
            pipeline.run_after()

        self.success('Done')
Example #5
0
    def test_template_selection_input_error(self, mock_input, mock_exit):
        arguments = PropertyMock(return_value={'--select': True})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [
            ('foo', '/foo'),
        ]
        mock_input.return_value = 0

        s = Settings(self.interface, self.config)

        with self.assertRaises(FacioException):
            with self.assertRaises(ValueError):
                s.get_template_path()
        self.mocked_facio_exceptions_puts.assert_any_call(
            'Error: A template was not selected')
        self.assertTrue(mock_exit.called)
Example #6
0
    def test_template_selection_input_error(self, mock_input, mock_exit):
        arguments = PropertyMock(return_value={
            '--select': True})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [
            ('foo', '/foo'),
        ]
        mock_input.return_value = 0

        s = Settings(self.interface, self.config)

        with self.assertRaises(FacioException):
            with self.assertRaises(ValueError):
                s.get_template_path()
        self.mocked_facio_exceptions_puts.assert_any_call(
            'Error: A template was not selected')
        self.assertTrue(mock_exit.called)
Example #7
0
    def test_path_returned_if_not_alias(self):
        arguments = PropertyMock(return_value={'--template': '/foo/bar/baz'})
        type(self.interface).arguments = arguments

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo/bar/baz')
Example #8
0
    def test_default_template_returned_none_defined(self, mock_exit):
        arguments = PropertyMock(return_value={'--select': False})
        type(self.interface).arguments = arguments

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(Settings.default_template_path, path)
Example #9
0
    def test_path_returned_if_not_alias(self):
        arguments = PropertyMock(return_value={
            '--template': '/foo/bar/baz'})
        type(self.interface).arguments = arguments

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo/bar/baz')
Example #10
0
    def test_default_template_returned_none_defined(self, mock_exit):
        arguments = PropertyMock(return_value={
            '--select': False})
        type(self.interface).arguments = arguments

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(Settings.default_template_path, path)
Example #11
0
    def test_path_retuend_from_alias(self):
        arguments = PropertyMock(return_value={'--template': 'foobar'})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [('foobar', '/foo/bar/baz')]

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo/bar/baz')
Example #12
0
    def test_path_retuend_from_alias(self):
        arguments = PropertyMock(return_value={
            '--template': 'foobar'})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [('foobar', '/foo/bar/baz')]

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo/bar/baz')
Example #13
0
    def test_template_selection_input_success(self, mock_input):
        arguments = PropertyMock(return_value={'--select': True})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [
            ('foo', '/foo'),
            ('bar', '/bar'),
            ('baz', '/baz'),
        ]
        mock_input.return_value = 1

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo')
Example #14
0
    def test_template_selection_input_success(self, mock_input):
        arguments = PropertyMock(return_value={
            '--select': True})
        type(self.interface).arguments = arguments
        self.config.items.return_value = [
            ('foo', '/foo'),
            ('bar', '/bar'),
            ('baz', '/baz'),
        ]
        mock_input.return_value = 1

        s = Settings(self.interface, self.config)
        path = s.get_template_path()

        self.assertEqual(path, '/foo')