forked from openlp/openlp
Return None instead of raising an error when converting path objects
This commit is contained in:
parent
5e3c3f55d2
commit
3e5eb698d9
@ -206,7 +206,8 @@ def str_to_path(string):
|
|||||||
:rtype: openlp.core.common.path.Path | None
|
:rtype: openlp.core.common.path.Path | None
|
||||||
"""
|
"""
|
||||||
if not isinstance(string, str):
|
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 == '':
|
if string == '':
|
||||||
return None
|
return None
|
||||||
return Path(string)
|
return Path(string)
|
||||||
|
@ -271,13 +271,12 @@ class TestPath(TestCase):
|
|||||||
|
|
||||||
def test_str_to_path_type_error(self):
|
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
|
# GIVEN: The `str_to_path` function
|
||||||
# WHEN: Calling `str_to_path` with an invalid Type
|
# WHEN: Calling `str_to_path` with an invalid Type
|
||||||
# THEN: A TypeError should have been raised
|
# THEN: None is returned
|
||||||
with self.assertRaises(TypeError):
|
assert str_to_path(Path()) is None
|
||||||
str_to_path(Path())
|
|
||||||
|
|
||||||
def test_str_to_path_empty_str(self):
|
def test_str_to_path_empty_str(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user