Best Python code snippet using molecule_python
config_options_tests.py
Source:config_options_tests.py
1import os2import sys3import unittest4from unittest.mock import patch5import mkdocs6from mkdocs.config import config_options7from mkdocs.config.base import Config8class OptionallyRequiredTest(unittest.TestCase):9 def test_empty(self):10 option = config_options.OptionallyRequired()11 value = option.validate(None)12 self.assertEqual(value, None)13 self.assertEqual(option.is_required(), False)14 def test_required(self):15 option = config_options.OptionallyRequired(required=True)16 self.assertRaises(config_options.ValidationError,17 option.validate, None)18 self.assertEqual(option.is_required(), True)19 def test_required_no_default(self):20 option = config_options.OptionallyRequired(required=True)21 value = option.validate(2)22 self.assertEqual(2, value)23 def test_default(self):24 option = config_options.OptionallyRequired(default=1)25 value = option.validate(None)26 self.assertEqual(1, value)27 def test_replace_default(self):28 option = config_options.OptionallyRequired(default=1)29 value = option.validate(2)30 self.assertEqual(2, value)31class TypeTest(unittest.TestCase):32 def test_single_type(self):33 option = config_options.Type(str)34 value = option.validate("Testing")35 self.assertEqual(value, "Testing")36 def test_multiple_types(self):37 option = config_options.Type((list, tuple))38 value = option.validate([1, 2, 3])39 self.assertEqual(value, [1, 2, 3])40 value = option.validate((1, 2, 3))41 self.assertEqual(value, (1, 2, 3))42 self.assertRaises(config_options.ValidationError,43 option.validate, {'a': 1})44 def test_length(self):45 option = config_options.Type(str, length=7)46 value = option.validate("Testing")47 self.assertEqual(value, "Testing")48 self.assertRaises(config_options.ValidationError,49 option.validate, "Testing Long")50class ChoiceTest(unittest.TestCase):51 def test_valid_choice(self):52 option = config_options.Choice(('python', 'node'))53 value = option.validate('python')54 self.assertEqual(value, 'python')55 def test_invalid_choice(self):56 option = config_options.Choice(('python', 'node'))57 self.assertRaises(58 config_options.ValidationError, option.validate, 'go')59 def test_invalid_choices(self):60 self.assertRaises(ValueError, config_options.Choice, '')61 self.assertRaises(ValueError, config_options.Choice, [])62 self.assertRaises(ValueError, config_options.Choice, 5)63class IpAddressTest(unittest.TestCase):64 def test_valid_address(self):65 addr = '127.0.0.1:8000'66 option = config_options.IpAddress()67 value = option.validate(addr)68 self.assertEqual(str(value), addr)69 self.assertEqual(value.host, '127.0.0.1')70 self.assertEqual(value.port, 8000)71 def test_valid_IPv6_address(self):72 addr = '::1:8000'73 option = config_options.IpAddress()74 value = option.validate(addr)75 self.assertEqual(str(value), addr)76 self.assertEqual(value.host, '::1')77 self.assertEqual(value.port, 8000)78 def test_named_address(self):79 addr = 'localhost:8000'80 option = config_options.IpAddress()81 value = option.validate(addr)82 self.assertEqual(str(value), addr)83 self.assertEqual(value.host, 'localhost')84 self.assertEqual(value.port, 8000)85 def test_default_address(self):86 addr = '127.0.0.1:8000'87 option = config_options.IpAddress(default=addr)88 value = option.validate(None)89 self.assertEqual(str(value), addr)90 self.assertEqual(value.host, '127.0.0.1')91 self.assertEqual(value.port, 8000)92 def test_IP_normalization(self):93 addr = '127.000.000.001:8000'94 option = config_options.IpAddress(default=addr)95 value = option.validate(None)96 self.assertEqual(str(value), '127.0.0.1:8000')97 self.assertEqual(value.host, '127.0.0.1')98 self.assertEqual(value.port, 8000)99 def test_invalid_address_range(self):100 option = config_options.IpAddress()101 self.assertRaises(102 config_options.ValidationError,103 option.validate, '277.0.0.1:8000'104 )105 def test_invalid_address_format(self):106 option = config_options.IpAddress()107 self.assertRaises(108 config_options.ValidationError,109 option.validate, '127.0.0.18000'110 )111 def test_invalid_address_type(self):112 option = config_options.IpAddress()113 self.assertRaises(114 config_options.ValidationError,115 option.validate, 123116 )117 def test_invalid_address_port(self):118 option = config_options.IpAddress()119 self.assertRaises(120 config_options.ValidationError,121 option.validate, '127.0.0.1:foo'122 )123 def test_invalid_address_missing_port(self):124 option = config_options.IpAddress()125 self.assertRaises(126 config_options.ValidationError,127 option.validate, '127.0.0.1'128 )129 def test_unsupported_address(self):130 option = config_options.IpAddress()131 value = option.validate('0.0.0.0:8000')132 option.post_validation({'dev_addr': value}, 'dev_addr')133 self.assertEqual(len(option.warnings), 1)134 def test_unsupported_IPv6_address(self):135 option = config_options.IpAddress()136 value = option.validate(':::8000')137 option.post_validation({'dev_addr': value}, 'dev_addr')138 self.assertEqual(len(option.warnings), 1)139 def test_invalid_IPv6_address(self):140 # The server will error out with this so we treat it as invalid.141 option = config_options.IpAddress()142 self.assertRaises(143 config_options.ValidationError,144 option.validate, '[::1]:8000'145 )146class URLTest(unittest.TestCase):147 def test_valid_url(self):148 url = "https://mkdocs.org"149 option = config_options.URL()150 value = option.validate(url)151 self.assertEqual(value, url)152 def test_invalid_url(self):153 option = config_options.URL()154 self.assertRaises(config_options.ValidationError,155 option.validate, "www.mkdocs.org")156 def test_invalid(self):157 option = config_options.URL()158 self.assertRaises(config_options.ValidationError,159 option.validate, 1)160class RepoURLTest(unittest.TestCase):161 def test_repo_name_github(self):162 option = config_options.RepoURL()163 config = {'repo_url': "https://github.com/mkdocs/mkdocs"}164 option.post_validation(config, 'repo_url')165 self.assertEqual(config['repo_name'], "GitHub")166 def test_repo_name_bitbucket(self):167 option = config_options.RepoURL()168 config = {'repo_url': "https://bitbucket.org/gutworth/six/"}169 option.post_validation(config, 'repo_url')170 self.assertEqual(config['repo_name'], "Bitbucket")171 def test_repo_name_gitlab(self):172 option = config_options.RepoURL()173 config = {'repo_url': "https://gitlab.com/gitlab-org/gitlab-ce/"}174 option.post_validation(config, 'repo_url')175 self.assertEqual(config['repo_name'], "GitLab")176 def test_repo_name_custom(self):177 option = config_options.RepoURL()178 config = {'repo_url': "https://launchpad.net/python-tuskarclient"}179 option.post_validation(config, 'repo_url')180 self.assertEqual(config['repo_name'], "Launchpad")181 def test_edit_uri_github(self):182 option = config_options.RepoURL()183 config = {'repo_url': "https://github.com/mkdocs/mkdocs"}184 option.post_validation(config, 'repo_url')185 self.assertEqual(config['edit_uri'], 'edit/master/docs/')186 def test_edit_uri_bitbucket(self):187 option = config_options.RepoURL()188 config = {'repo_url': "https://bitbucket.org/gutworth/six/"}189 option.post_validation(config, 'repo_url')190 self.assertEqual(config['edit_uri'], 'src/default/docs/')191 def test_edit_uri_gitlab(self):192 option = config_options.RepoURL()193 config = {'repo_url': "https://gitlab.com/gitlab-org/gitlab-ce/"}194 option.post_validation(config, 'repo_url')195 self.assertEqual(config['edit_uri'], 'edit/master/docs/')196 def test_edit_uri_custom(self):197 option = config_options.RepoURL()198 config = {'repo_url': "https://launchpad.net/python-tuskarclient"}199 option.post_validation(config, 'repo_url')200 self.assertEqual(config.get('edit_uri'), '')201 def test_repo_name_custom_and_empty_edit_uri(self):202 option = config_options.RepoURL()203 config = {'repo_url': "https://github.com/mkdocs/mkdocs",204 'repo_name': 'mkdocs'}205 option.post_validation(config, 'repo_url')206 self.assertEqual(config.get('edit_uri'), 'edit/master/docs/')207class DirTest(unittest.TestCase):208 def test_valid_dir(self):209 d = os.path.dirname(__file__)210 option = config_options.Dir(exists=True)211 value = option.validate(d)212 self.assertEqual(d, value)213 def test_missing_dir(self):214 d = os.path.join("not", "a", "real", "path", "I", "hope")215 option = config_options.Dir()216 value = option.validate(d)217 self.assertEqual(os.path.abspath(d), value)218 def test_missing_dir_but_required(self):219 d = os.path.join("not", "a", "real", "path", "I", "hope")220 option = config_options.Dir(exists=True)221 self.assertRaises(config_options.ValidationError,222 option.validate, d)223 def test_file(self):224 d = __file__225 option = config_options.Dir(exists=True)226 self.assertRaises(config_options.ValidationError,227 option.validate, d)228 def test_incorrect_type_attribute_error(self):229 option = config_options.Dir()230 self.assertRaises(config_options.ValidationError,231 option.validate, 1)232 def test_incorrect_type_type_error(self):233 option = config_options.Dir()234 self.assertRaises(config_options.ValidationError,235 option.validate, [])236 def test_dir_unicode(self):237 cfg = Config(238 [('dir', config_options.Dir())],239 config_file_path=os.path.join(os.path.abspath('.'), 'mkdocs.yml'),240 )241 test_config = {242 'dir': 'Ñникод'243 }244 cfg.load_dict(test_config)245 fails, warns = cfg.validate()246 self.assertEqual(len(fails), 0)247 self.assertEqual(len(warns), 0)248 self.assertIsInstance(cfg['dir'], str)249 def test_dir_filesystemencoding(self):250 cfg = Config(251 [('dir', config_options.Dir())],252 config_file_path=os.path.join(os.path.abspath('.'), 'mkdocs.yml'),253 )254 test_config = {255 'dir': 'Ãbersicht'.encode(encoding=sys.getfilesystemencoding())256 }257 cfg.load_dict(test_config)258 fails, warns = cfg.validate()259 # str does not include byte strings so validation fails260 self.assertEqual(len(fails), 1)261 self.assertEqual(len(warns), 0)262 def test_dir_bad_encoding_fails(self):263 cfg = Config(264 [('dir', config_options.Dir())],265 config_file_path=os.path.join(os.path.abspath('.'), 'mkdocs.yml'),266 )267 test_config = {268 'dir': 'Ñникод'.encode(encoding='ISO 8859-5')269 }270 cfg.load_dict(test_config)271 fails, warns = cfg.validate()272 self.assertEqual(len(fails), 1)273 self.assertEqual(len(warns), 0)274 def test_config_dir_prepended(self):275 base_path = os.path.abspath('.')276 cfg = Config(277 [('dir', config_options.Dir())],278 config_file_path=os.path.join(base_path, 'mkdocs.yml'),279 )280 test_config = {281 'dir': 'foo'282 }283 cfg.load_dict(test_config)284 fails, warns = cfg.validate()285 self.assertEqual(len(fails), 0)286 self.assertEqual(len(warns), 0)287 self.assertIsInstance(cfg['dir'], str)288 self.assertEqual(cfg['dir'], os.path.join(base_path, 'foo'))289 def test_dir_is_config_dir_fails(self):290 cfg = Config(291 [('dir', config_options.Dir())],292 config_file_path=os.path.join(os.path.abspath('.'), 'mkdocs.yml'),293 )294 test_config = {295 'dir': '.'296 }297 cfg.load_dict(test_config)298 fails, warns = cfg.validate()299 self.assertEqual(len(fails), 1)300 self.assertEqual(len(warns), 0)301class SiteDirTest(unittest.TestCase):302 def validate_config(self, config):303 """ Given a config with values for site_dir and doc_dir, run site_dir post_validation. """304 site_dir = config_options.SiteDir()305 docs_dir = config_options.Dir()306 fname = os.path.join(os.path.abspath('..'), 'mkdocs.yml')307 config['docs_dir'] = docs_dir.validate(config['docs_dir'])308 config['site_dir'] = site_dir.validate(config['site_dir'])309 schema = [310 ('site_dir', site_dir),311 ('docs_dir', docs_dir),312 ]313 cfg = Config(schema, fname)314 cfg.load_dict(config)315 failed, warned = cfg.validate()316 if failed:317 raise config_options.ValidationError(failed)318 return True319 def test_doc_dir_in_site_dir(self):320 j = os.path.join321 # The parent dir is not the same on every system, so use the actual dir name322 parent_dir = mkdocs.__file__.split(os.sep)[-3]323 test_configs = (324 {'docs_dir': j('site', 'docs'), 'site_dir': 'site'},325 {'docs_dir': 'docs', 'site_dir': '.'},326 {'docs_dir': '.', 'site_dir': '.'},327 {'docs_dir': 'docs', 'site_dir': ''},328 {'docs_dir': '', 'site_dir': ''},329 {'docs_dir': j('..', parent_dir, 'docs'), 'site_dir': 'docs'},330 {'docs_dir': 'docs', 'site_dir': '/'}331 )332 for test_config in test_configs:333 self.assertRaises(config_options.ValidationError,334 self.validate_config, test_config)335 def test_site_dir_in_docs_dir(self):336 j = os.path.join337 test_configs = (338 {'docs_dir': 'docs', 'site_dir': j('docs', 'site')},339 {'docs_dir': '.', 'site_dir': 'site'},340 {'docs_dir': '', 'site_dir': 'site'},341 {'docs_dir': '/', 'site_dir': 'site'},342 )343 for test_config in test_configs:344 self.assertRaises(config_options.ValidationError,345 self.validate_config, test_config)346 def test_common_prefix(self):347 """ Legitimate settings with common prefixes should not fail validation. """348 test_configs = (349 {'docs_dir': 'docs', 'site_dir': 'docs-site'},350 {'docs_dir': 'site-docs', 'site_dir': 'site'},351 )352 for test_config in test_configs:353 assert self.validate_config(test_config)354class ThemeTest(unittest.TestCase):355 def test_theme_as_string(self):356 option = config_options.Theme()357 value = option.validate("mkdocs")358 self.assertEqual({'name': 'mkdocs'}, value)359 def test_uninstalled_theme_as_string(self):360 option = config_options.Theme()361 self.assertRaises(config_options.ValidationError,362 option.validate, "mkdocs2")363 def test_theme_default(self):364 option = config_options.Theme(default='mkdocs')365 value = option.validate(None)366 self.assertEqual({'name': 'mkdocs'}, value)367 def test_theme_as_simple_config(self):368 config = {369 'name': 'mkdocs'370 }371 option = config_options.Theme()372 value = option.validate(config)373 self.assertEqual(config, value)374 def test_theme_as_complex_config(self):375 config = {376 'name': 'mkdocs',377 'custom_dir': 'custom',378 'static_templates': ['sitemap.html'],379 'show_sidebar': False380 }381 option = config_options.Theme()382 value = option.validate(config)383 self.assertEqual(config, value)384 def test_theme_name_is_none(self):385 config = {386 'name': None387 }388 option = config_options.Theme()389 value = option.validate(config)390 self.assertEqual(config, value)391 def test_theme_config_missing_name(self):392 config = {393 'custom_dir': 'custom',394 }395 option = config_options.Theme()396 self.assertRaises(config_options.ValidationError,397 option.validate, config)398 def test_uninstalled_theme_as_config(self):399 config = {400 'name': 'mkdocs2'401 }402 option = config_options.Theme()403 self.assertRaises(config_options.ValidationError,404 option.validate, config)405 def test_theme_invalid_type(self):406 config = ['mkdocs2']407 option = config_options.Theme()408 self.assertRaises(config_options.ValidationError,409 option.validate, config)410class NavTest(unittest.TestCase):411 def test_old_format(self):412 option = config_options.Nav()413 self.assertRaises(414 config_options.ValidationError,415 option.validate,416 [['index.md', ], ]417 )418 def test_provided_dict(self):419 option = config_options.Nav()420 value = option.validate([421 'index.md',422 {"Page": "page.md"}423 ])424 self.assertEqual(['index.md', {'Page': 'page.md'}], value)425 option.post_validation({'extra_stuff': []}, 'extra_stuff')426 def test_provided_empty(self):427 option = config_options.Nav()428 value = option.validate([])429 self.assertEqual(None, value)430 option.post_validation({'extra_stuff': []}, 'extra_stuff')431 def test_invalid_type(self):432 option = config_options.Nav()433 self.assertRaises(config_options.ValidationError,434 option.validate, {})435 def test_invalid_config(self):436 option = config_options.Nav()437 self.assertRaises(config_options.ValidationError,438 option.validate, [[], 1])439class PrivateTest(unittest.TestCase):440 def test_defined(self):441 option = config_options.Private()442 self.assertRaises(config_options.ValidationError,443 option.validate, 'somevalue')444class MarkdownExtensionsTest(unittest.TestCase):445 @patch('markdown.Markdown')446 def test_simple_list(self, mockMd):447 option = config_options.MarkdownExtensions()448 config = {449 'markdown_extensions': ['foo', 'bar']450 }451 config['markdown_extensions'] = option.validate(config['markdown_extensions'])452 option.post_validation(config, 'markdown_extensions')453 self.assertEqual({454 'markdown_extensions': ['foo', 'bar'],455 'mdx_configs': {}456 }, config)457 @patch('markdown.Markdown')458 def test_list_dicts(self, mockMd):459 option = config_options.MarkdownExtensions()460 config = {461 'markdown_extensions': [462 {'foo': {'foo_option': 'foo value'}},463 {'bar': {'bar_option': 'bar value'}},464 {'baz': None}465 ]466 }467 config['markdown_extensions'] = option.validate(config['markdown_extensions'])468 option.post_validation(config, 'markdown_extensions')469 self.assertEqual({470 'markdown_extensions': ['foo', 'bar', 'baz'],471 'mdx_configs': {472 'foo': {'foo_option': 'foo value'},473 'bar': {'bar_option': 'bar value'}474 }475 }, config)476 @patch('markdown.Markdown')477 def test_mixed_list(self, mockMd):478 option = config_options.MarkdownExtensions()479 config = {480 'markdown_extensions': [481 'foo',482 {'bar': {'bar_option': 'bar value'}}483 ]484 }485 config['markdown_extensions'] = option.validate(config['markdown_extensions'])486 option.post_validation(config, 'markdown_extensions')487 self.assertEqual({488 'markdown_extensions': ['foo', 'bar'],489 'mdx_configs': {490 'bar': {'bar_option': 'bar value'}491 }492 }, config)493 @patch('markdown.Markdown')494 def test_builtins(self, mockMd):495 option = config_options.MarkdownExtensions(builtins=['meta', 'toc'])496 config = {497 'markdown_extensions': ['foo', 'bar']498 }499 config['markdown_extensions'] = option.validate(config['markdown_extensions'])500 option.post_validation(config, 'markdown_extensions')501 self.assertEqual({502 'markdown_extensions': ['meta', 'toc', 'foo', 'bar'],503 'mdx_configs': {}504 }, config)505 def test_duplicates(self):506 option = config_options.MarkdownExtensions(builtins=['meta', 'toc'])507 config = {508 'markdown_extensions': ['meta', 'toc']509 }510 config['markdown_extensions'] = option.validate(config['markdown_extensions'])511 option.post_validation(config, 'markdown_extensions')512 self.assertEqual({513 'markdown_extensions': ['meta', 'toc'],514 'mdx_configs': {}515 }, config)516 def test_builtins_config(self):517 option = config_options.MarkdownExtensions(builtins=['meta', 'toc'])518 config = {519 'markdown_extensions': [520 {'toc': {'permalink': True}}521 ]522 }523 config['markdown_extensions'] = option.validate(config['markdown_extensions'])524 option.post_validation(config, 'markdown_extensions')525 self.assertEqual({526 'markdown_extensions': ['meta', 'toc'],527 'mdx_configs': {'toc': {'permalink': True}}528 }, config)529 @patch('markdown.Markdown')530 def test_configkey(self, mockMd):531 option = config_options.MarkdownExtensions(configkey='bar')532 config = {533 'markdown_extensions': [534 {'foo': {'foo_option': 'foo value'}}535 ]536 }537 config['markdown_extensions'] = option.validate(config['markdown_extensions'])538 option.post_validation(config, 'markdown_extensions')539 self.assertEqual({540 'markdown_extensions': ['foo'],541 'bar': {542 'foo': {'foo_option': 'foo value'}543 }544 }, config)545 def test_none(self):546 option = config_options.MarkdownExtensions(default=[])547 config = {548 'markdown_extensions': None549 }550 config['markdown_extensions'] = option.validate(config['markdown_extensions'])551 option.post_validation(config, 'markdown_extensions')552 self.assertEqual({553 'markdown_extensions': [],554 'mdx_configs': {}555 }, config)556 @patch('markdown.Markdown')557 def test_not_list(self, mockMd):558 option = config_options.MarkdownExtensions()559 self.assertRaises(config_options.ValidationError,560 option.validate, 'not a list')561 @patch('markdown.Markdown')562 def test_invalid_config_option(self, mockMd):563 option = config_options.MarkdownExtensions()564 config = {565 'markdown_extensions': [566 {'foo': 'not a dict'}567 ]568 }569 self.assertRaises(570 config_options.ValidationError,571 option.validate, config['markdown_extensions']572 )573 @patch('markdown.Markdown')574 def test_invalid_config_item(self, mockMd):575 option = config_options.MarkdownExtensions()576 config = {577 'markdown_extensions': [578 ['not a dict']579 ]580 }581 self.assertRaises(582 config_options.ValidationError,583 option.validate, config['markdown_extensions']584 )585 @patch('markdown.Markdown')586 def test_invalid_dict_item(self, mockMd):587 option = config_options.MarkdownExtensions()588 config = {589 'markdown_extensions': [590 {'key1': 'value', 'key2': 'too many keys'}591 ]592 }593 self.assertRaises(594 config_options.ValidationError,595 option.validate, config['markdown_extensions']596 )597 def test_unknown_extension(self):598 option = config_options.MarkdownExtensions()599 config = {600 'markdown_extensions': ['unknown']601 }602 self.assertRaises(603 config_options.ValidationError,604 option.validate, config['markdown_extensions']...
defaults.py
Source:defaults.py
1from mkdocs.config import config_options2# NOTE: The order here is important. During validation some config options3# depend on others. So, if config option A depends on B, then A should be4# listed higher in the schema.5# Once we drop Python 2.6 support, this could be an OrderedDict, however, it6# isn't really needed either as we always sequentially process the schema other7# than at initialisation when we grab the full set of keys for convenience.8DEFAULT_SCHEMA = (9 # Reserved for internal use, stores the mkdocs.yml config file.10 ('config_file_path', config_options.Type(str)),11 # The title to use for the documentation12 ('site_name', config_options.Type(str, required=True)),13 # Defines the structure of the navigation.14 ('nav', config_options.Nav()),15 # TODO: remove this when the `pages` config setting is fully deprecated.16 ('pages', config_options.Nav()),17 # The full URL to where the documentation will be hosted18 ('site_url', config_options.URL()),19 # A description for the documentation project that will be added to the20 # HTML meta tags.21 ('site_description', config_options.Type(str)),22 # The name of the author to add to the HTML meta tags23 ('site_author', config_options.Type(str)),24 # The MkDocs theme for the documentation.25 ('theme', config_options.Theme(default='mkdocs')),26 # The directory containing the documentation markdown.27 ('docs_dir', config_options.Dir(default='docs', exists=True)),28 # The directory where the site will be built to29 ('site_dir', config_options.SiteDir(default='site')),30 # A copyright notice to add to the footer of documentation.31 ('copyright', config_options.Type(str)),32 # set of values for Google analytics containing the account IO and domain,33 # this should look like, ['UA-27795084-5', 'mkdocs.org']34 ('google_analytics', config_options.Type(list, length=2)),35 # The address on which to serve the live reloading docs server.36 ('dev_addr', config_options.IpAddress(default='127.0.0.1:8000')),37 # If `True`, use `<page_name>/index.hmtl` style files with hyperlinks to38 # the directory.If `False`, use `<page_name>.html style file with39 # hyperlinks to the file.40 # True generates nicer URLs, but False is useful if browsing the output on41 # a filesystem.42 ('use_directory_urls', config_options.Type(bool, default=True)),43 # Specify a link to the project source repo to be included44 # in the documentation pages.45 ('repo_url', config_options.RepoURL()),46 # A name to use for the link to the project source repo.47 # Default, If repo_url is unset then None, otherwise48 # "GitHub", "Bitbucket" or "GitLab" for known url or Hostname49 # for unknown urls.50 ('repo_name', config_options.Type(str)),51 # Specify a URI to the docs dir in the project source repo, relative to the52 # repo_url. When set, a link directly to the page in the source repo will53 # be added to the generated HTML. If repo_url is not set also, this option54 # is ignored.55 ('edit_uri', config_options.Type(str)),56 # Specify which css or javascript files from the docs directory should be57 # additionally included in the site.58 ('extra_css', config_options.Type(list, default=[])),59 ('extra_javascript', config_options.Type(list, default=[])),60 # Similar to the above, but each template (HTML or XML) will be build with61 # Jinja2 and the global context.62 ('extra_templates', config_options.Type(list, default=[])),63 # PyMarkdown extension names.64 ('markdown_extensions', config_options.MarkdownExtensions(65 builtins=['toc', 'tables', 'fenced_code'],66 configkey='mdx_configs', default=[])),67 # PyMarkdown Extension Configs. For internal use only.68 ('mdx_configs', config_options.Private()),69 # enabling strict mode causes MkDocs to stop the build when a problem is70 # encountered rather than display an error.71 ('strict', config_options.Type(bool, default=False)),72 # the remote branch to commit to when using gh-deploy73 ('remote_branch', config_options.Type(74 str, default='gh-pages')),75 # the remote name to push to when using gh-deploy76 ('remote_name', config_options.Type(str, default='origin')),77 # extra is a mapping/dictionary of data that is passed to the template.78 # This allows template authors to require extra configuration that not79 # relevant to all themes and doesn't need to be explicitly supported by80 # MkDocs itself. A good example here would be including the current81 # project version.82 ('extra', config_options.SubConfig()),83 # a list of plugins. Each item may contain a string name or a key value pair.84 # A key value pair should be the string name (as the key) and a dict of config85 # options (as the value).86 ('plugins', config_options.Plugins(default=['search'])),...
config_reader.py
Source:config_reader.py
1from configparser import ConfigParser2import ast3class ConfigReader:4 def __init__(self):5 self.description = "reads configuration from elasticfetch.ini"6 self.config_path = "elasticfetch.ini"7 '''8 Reads in the user input from the configuration file and put them into a config_dict for easy access to 9 user's chosen parameters.10 '''11 def read_config_file(self) -> dict:12 config_dict = {}13 config_options = ConfigParser()14 config_options.read(self.config_path)15 if config_options.has_section("elastic"):16 if config_options.has_option("elastic", "protocol"):17 config_dict["elastic.protocol"] = ast.literal_eval(config_options.get("elastic", "protocol"))18 if config_options.has_option("elastic", "ip"):19 config_dict["elastic.ip"] = ast.literal_eval(config_options.get("elastic", "ip"))20 if config_options.has_option("elastic", "port"):21 config_dict["elastic.port"] = ast.literal_eval(config_options.get("elastic", "port"))22 if config_options.has_section("credentials"):23 if config_options.has_option("credentials", "username"):24 config_dict["credentials.username"] = ast.literal_eval(config_options.get("credentials", "username"))25 if config_options.has_option("credentials", "password"):26 config_dict["credentials.password"] = ast.literal_eval(config_options.get("credentials", "password"))27 if config_options.has_section("interface"):28 if config_options.has_option("interface", "graphical"):29 config_dict["interface.graphical"] = ast.literal_eval(config_options.get("interface", "graphical"))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!