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')
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')
def test_render(self, mock_get_source, mock_walk): # Mock Setups - Fake file contents and open renderer files_map = { 'bar.py': '{{PROJECT_NAME}}', 'foo.bah': 'PNGIHDRÄIDATxÚcøûýhúÌIEND®B`', 'baz.html': '<h1>{{UNKNOWN|default(\'Hello World\')}}</h1>', 'baz.gif': 'I am a gif' } def get_source(environmet, template): """ Overriding Jinja2 FileSystemLoader get_source function so we can return our own source. """ if template == 'foo.bah': raise Exception('\'utf8\' codec can\'t decode byte ' '0x89 in position 0: invalid start ' 'byte') contents = files_map[template] return contents, template, True mock_get_source.side_effect = get_source mock_walk.return_value = [ ('/foo', [], [k for k, v in six.iteritems(files_map)]) ] open_mock = mock_open() open_patcher = patch('facio.template.open', open_mock, create=True) open_patcher.start() # Call the renderer method on facio.Template instance = Template('/foo/bar') instance.update_render_ignore_globs(['*.gif', ]) instance.render() # Assertions handle = open_mock() self.assertEqual(handle.write.call_count, 2) handle.write.assert_any_call('foo') handle.write.assert_any_call('<h1>Hello World</h1>') self.mocked_facio_template_Template_warning.assert_called_with( 'Failed to render /foo/foo.bah: \'utf8\' codec can\'t ' 'decode byte 0x89 in position 0: invalid start byte') # Stop the open patch open_patcher.stop()