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'})
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_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(), [])
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'})
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')
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)
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')
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)
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')
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')
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)
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)
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')
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')
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)
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)
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_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(), [])
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'])
def test_attrs_set_on_init(self): s = Settings(self.interface, self.config) self.assertIsInstance(s.config, MagicMock) self.assertIsInstance(s.interface, MagicMock)