From e10b24c2adbc35848a83af97ca48c6142ea95987 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 18:03:04 +0000 Subject: [PATCH 1/9] Added doc amendment to hilight name usage can now be used when using -t --- docs/usage.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/usage.rst b/docs/usage.rst index dc7cf50..0e4168a 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -47,7 +47,8 @@ Template Options -t , --template= Path to your custom template, absolute paths only, git repositories can also be specified by prefixing with git+ - for example: git+git@gitbub.com/path/to/repo.git + for example: git+git@gitbub.com/path/to/repo.git. This can also be the template name you gave a template in the + ``.facio.cfg`` file. -c, --choose_template If you have more than 1 template defined use this flag to override the default template, Note: specifying -t From 112e53f44c94cbf0601c3d7abe430fa1252615c9 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 18:07:40 +0000 Subject: [PATCH 2/9] Test to ensure that the user can reference template names in -t argument --- tests/test_config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index cd52931..dfb8ebb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -131,6 +131,16 @@ def test_fail_if_invalid_template_choice(self): except SystemExit: assert True + @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) + def test_can_refernce_template_by_name_from_cli(self, mock_path): + mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') + try: + self._set_cli_args(self.base_args + ['-t', 'another_template']) + config = Config() + self.assertEquals(config.template, '/path/to/template') + except SystemExit + pass # We allow a pass here because the template path is invalid + def test_value_error_raised_on_zero_template_choice(self): config.input = lambda _: '0' try: From b585f3768d2f50a934d4d6201670c455a7cd6a4a Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 18:11:23 +0000 Subject: [PATCH 3/9] Test to ensure failure on invalid name reference --- tests/test_config.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index dfb8ebb..f4eed14 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -131,6 +131,14 @@ def test_fail_if_invalid_template_choice(self): except SystemExit: assert True + def test_value_error_raised_on_zero_template_choice(self): + config.input = lambda _: '0' + try: + self._set_cli_args(self.base_args + ['-c', ]) + self.config = Config() + except SystemExit: + assert True + @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) def test_can_refernce_template_by_name_from_cli(self, mock_path): mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') @@ -141,11 +149,12 @@ def test_can_refernce_template_by_name_from_cli(self, mock_path): except SystemExit pass # We allow a pass here because the template path is invalid - def test_value_error_raised_on_zero_template_choice(self): - config.input = lambda _: '0' + @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) + def test_can_refernce_template_by_name_from_cli_invalid(self, mock_path): + mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') try: - self._set_cli_args(self.base_args + ['-c', ]) - self.config = Config() + self._set_cli_args(self.base_args + ['-t', 'not_valud_name']) + config = Config() except SystemExit: assert True From fbfbffbc73bfd2a9fd7d6cb81071922c11b6e60e Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 18:12:17 +0000 Subject: [PATCH 4/9] Typo in valid --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index f4eed14..3f55cbb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -153,7 +153,7 @@ def test_can_refernce_template_by_name_from_cli(self, mock_path): def test_can_refernce_template_by_name_from_cli_invalid(self, mock_path): mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') try: - self._set_cli_args(self.base_args + ['-t', 'not_valud_name']) + self._set_cli_args(self.base_args + ['-t', 'not_valid_name']) config = Config() except SystemExit: assert True From de38b1d1f492964da73d69b86b8214de5f5d7275 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 20:37:21 +0000 Subject: [PATCH 5/9] Added another template to the list of templates --- tests/test_cfgs/multiple_templates.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_cfgs/multiple_templates.cfg b/tests/test_cfgs/multiple_templates.cfg index b1c2136..66d03e0 100644 --- a/tests/test_cfgs/multiple_templates.cfg +++ b/tests/test_cfgs/multiple_templates.cfg @@ -1,3 +1,4 @@ [template] default=git+git@github.com:krak3n/Facio-Default-Template.git another_template=/path/to/template +foo=/path/to/template/foo From 4bd7ef38f0b8694bc0f3e2937725772a3a33bfef Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Mon, 3 Jun 2013 20:37:41 +0000 Subject: [PATCH 6/9] Making the test fail - as it should --- tests/test_config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 3f55cbb..621acf4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -143,18 +143,18 @@ def test_value_error_raised_on_zero_template_choice(self): def test_can_refernce_template_by_name_from_cli(self, mock_path): mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') try: - self._set_cli_args(self.base_args + ['-t', 'another_template']) - config = Config() - self.assertEquals(config.template, '/path/to/template') - except SystemExit - pass # We allow a pass here because the template path is invalid + self._set_cli_args(self.base_args + ['-t', 'foo']) + self.config = Config() + self.assertEquals(self.config.template, '/path/to/template/foo') + except SystemExit: + assert False @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) def test_can_refernce_template_by_name_from_cli_invalid(self, mock_path): mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') try: self._set_cli_args(self.base_args + ['-t', 'not_valid_name']) - config = Config() + Config() except SystemExit: assert True From aadd0b715dc9b540554699b4b997a7a639e49b9d Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Tue, 4 Jun 2013 07:51:01 +0000 Subject: [PATCH 7/9] Ensuring test mocks isdir so config does not exit when the fake template is not found --- tests/test_config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 621acf4..3b22394 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -139,8 +139,12 @@ def test_value_error_raised_on_zero_template_choice(self): except SystemExit: assert True + @patch('os.path.isdir', return_value=True) @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) - def test_can_refernce_template_by_name_from_cli(self, mock_path): + def test_can_refernce_template_by_name_from_cli( + self, + mock_path, + mock_isdir): mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') try: self._set_cli_args(self.base_args + ['-t', 'foo']) From b0f7a3a3a31d737163ed6a3e144ce69c522b0a5d Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Tue, 4 Jun 2013 07:51:34 +0000 Subject: [PATCH 8/9] Allow users to select template by name when using -t / --template from the .facio.cfg --- src/facio/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/facio/config.py b/src/facio/config.py index c55df8b..1b789f3 100644 --- a/src/facio/config.py +++ b/src/facio/config.py @@ -105,6 +105,11 @@ def project_name(self): # def _validate_template_options(self): + templates = self.file_args.templates + try: + self._tpl = [t for n, t in templates if n == self._tpl][0] + except IndexError: + pass if (not self._tpl.startswith('git+') and not os.path.isdir(self._tpl)): self._error('The path to your template does not exist.') From afdf95bea6802a8ba6991c0c4fbb968693fd2173 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Tue, 4 Jun 2013 07:53:22 +0000 Subject: [PATCH 9/9] Added comment to add reason for pass in exception --- src/facio/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/facio/config.py b/src/facio/config.py index 1b789f3..720c107 100644 --- a/src/facio/config.py +++ b/src/facio/config.py @@ -109,7 +109,7 @@ def _validate_template_options(self): try: self._tpl = [t for n, t in templates if n == self._tpl][0] except IndexError: - pass + pass # We don't care if this fails, assume it's a path if (not self._tpl.startswith('git+') and not os.path.isdir(self._tpl)): self._error('The path to your template does not exist.')