コード例 #1
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    def test_get_variables_from_cli(self):
        arguments = PropertyMock(return_value={'--vars': 'foo=bar'})
        type(self.interface).arguments = arguments

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

        self.assertEqual(s.get_variables(), {'foo': 'bar'})
コード例 #2
0
ファイル: run.py プロジェクト: 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')
コード例 #3
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    def test_empty_render_ignore_no_option(self):
        self.config.get.side_effect = ConfigParser.NoOptionError(
            'files', 'render_ignore')

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

        self.assertEqual(s.render_ignore_globs(), [])
コード例 #4
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    def test_empty_render_ignore_no_option(self):
        self.config.get.side_effect = ConfigParser.NoOptionError(
            'files',
            'render_ignore')

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

        self.assertEqual(s.render_ignore_globs(), [])
コード例 #5
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    def test_get_variables_from_cli(self):
        arguments = PropertyMock(return_value={
            '--vars': 'foo=bar'})
        type(self.interface).arguments = arguments

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

        self.assertEqual(s.get_variables(), {'foo': 'bar'})
コード例 #6
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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')
コード例 #7
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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)
コード例 #8
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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')
コード例 #9
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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)
コード例 #10
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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')
コード例 #11
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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')
コード例 #12
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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)
コード例 #13
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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)
コード例 #14
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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')
コード例 #15
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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')
コード例 #16
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    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)
コード例 #17
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    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)
コード例 #18
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')
コード例 #19
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    def test_empty_copy_ignore_no_files_section(self):
        self.config.get.side_effect = ConfigParser.NoSectionError('files')

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

        self.assertEqual(s.copy_ignore_globs(), [])
コード例 #20
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    def test_empty_copy_ignore_no_files_section(self):
        self.config.get.side_effect = ConfigParser.NoSectionError('files')

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

        self.assertEqual(s.copy_ignore_globs(), [])
コード例 #21
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    def test_render_ignore_returned_as_list(self):
        self.config.get.return_value = 'foo=bar,baz=foo'

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

        self.assertEqual(s.render_ignore_globs(), ['foo=bar', 'baz=foo'])
コード例 #22
0
ファイル: test_config.py プロジェクト: jackqu7/Facio
    def test_render_ignore_returned_as_list(self):
        self.config.get.return_value = 'foo=bar,baz=foo'

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

        self.assertEqual(s.render_ignore_globs(), ['foo=bar', 'baz=foo'])
コード例 #23
0
ファイル: test_config.py プロジェクト: krak3n/Facio
    def test_attrs_set_on_init(self):
        s = Settings(self.interface, self.config)

        self.assertIsInstance(s.config, MagicMock)
        self.assertIsInstance(s.interface, MagicMock)