From 3e5eb698d927361d0d71a3c572618e18ee118253 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 12 Aug 2018 13:12:03 +0200 Subject: [PATCH 1/2] Return None instead of raising an error when converting path objects --- openlp/core/common/path.py | 3 ++- tests/functional/openlp_core/common/test_path.py | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/core/common/path.py b/openlp/core/common/path.py index ec251c5f1..dd242475f 100644 --- a/openlp/core/common/path.py +++ b/openlp/core/common/path.py @@ -206,7 +206,8 @@ def str_to_path(string): :rtype: openlp.core.common.path.Path | None """ if not isinstance(string, str): - raise TypeError('parameter \'string\' must be of type str') + log.debug('parameter \'string\' must be of type str, got {} which is a {} instead'.format(string, type(string))) + return None if string == '': return None return Path(string) diff --git a/tests/functional/openlp_core/common/test_path.py b/tests/functional/openlp_core/common/test_path.py index 39bb68f92..8581d9b49 100644 --- a/tests/functional/openlp_core/common/test_path.py +++ b/tests/functional/openlp_core/common/test_path.py @@ -271,13 +271,12 @@ class TestPath(TestCase): def test_str_to_path_type_error(self): """ - Test that `str_to_path` raises a type error when called with an invalid type + Test that `str_to_path` returns None if called with invalid information """ # GIVEN: The `str_to_path` function # WHEN: Calling `str_to_path` with an invalid Type - # THEN: A TypeError should have been raised - with self.assertRaises(TypeError): - str_to_path(Path()) + # THEN: None is returned + assert str_to_path(Path()) is None def test_str_to_path_empty_str(self): """ From 3ae978e4bede38343b93f7da33f55f2934d7ea27 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 12 Aug 2018 13:14:47 +0200 Subject: [PATCH 2/2] Log an error instead of debug output --- openlp/core/common/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/common/path.py b/openlp/core/common/path.py index dd242475f..64ec64a94 100644 --- a/openlp/core/common/path.py +++ b/openlp/core/common/path.py @@ -206,7 +206,7 @@ def str_to_path(string): :rtype: openlp.core.common.path.Path | None """ if not isinstance(string, str): - log.debug('parameter \'string\' must be of type str, got {} which is a {} instead'.format(string, type(string))) + log.error('parameter \'string\' must be of type str, got {} which is a {} instead'.format(string, type(string))) return None if string == '': return None