mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Change config_options.URL's default from '' to None
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user