Change config_options.URL's default from '' to None

This commit is contained in:
Oleh Prypin
2022-09-26 11:31:47 +02:00
parent 51569476c0
commit aeffe61499
3 changed files with 30 additions and 4 deletions

View File

@@ -394,14 +394,14 @@ class URL(OptionallyRequired[str]):
"""
@overload
def __init__(self, default='', *, is_dir: bool = False):
def __init__(self, default=None, *, is_dir: bool = False):
...
@overload
def __init__(self, default='', *, required: bool, is_dir: bool = False):
def __init__(self, default=None, *, required: bool, is_dir: bool = False):
...
def __init__(self, default='', required=None, is_dir: bool = False):
def __init__(self, default=None, required=None, is_dir: bool = False):
self.is_dir = is_dir
super().__init__(default, required=required)

View File

@@ -432,9 +432,22 @@ class URLTest(TestCase):
conf = self.get_config(Schema, {'option': "https://mkdocs.org"})
self.assertEqual(conf['option'], "https://mkdocs.org/")
def test_optional(self):
class Schema:
option = c.URL(is_dir=True)
conf = self.get_config(Schema, {'option': ''})
self.assertEqual(conf['option'], '')
conf = self.get_config(Schema, {'option': None})
self.assertEqual(conf['option'], None)
def test_invalid_url(self):
class Schema:
option = c.URL()
option = c.URL(required=True)
with self.expect_error(option="Required configuration not provided."):
self.get_config(Schema, {'option': None})
for url in "www.mkdocs.org", "//mkdocs.org/test", "http:/mkdocs.org/", "/hello/":
with self.subTest(url=url):

View File

@@ -414,10 +414,23 @@ class URLTest(TestCase):
conf = self.get_config(Schema, {'option': "https://mkdocs.org"})
self.assertEqual(conf.option, "https://mkdocs.org/")
def test_optional(self):
class Schema(Config):
option = c.Optional(c.URL(is_dir=True))
conf = self.get_config(Schema, {'option': ''})
self.assertEqual(conf.option, '')
conf = self.get_config(Schema, {'option': None})
self.assertEqual(conf.option, None)
def test_invalid_url(self) -> None:
class Schema(Config):
option = c.URL()
with self.expect_error(option="Required configuration not provided."):
self.get_config(Schema, {'option': None})
for url in "www.mkdocs.org", "//mkdocs.org/test", "http:/mkdocs.org/", "/hello/":
with self.subTest(url=url):
with self.expect_error(