Skip to content

Commit

Permalink
ADD check_confs test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaume Florez committed Jun 1, 2018
1 parent 27109e4 commit 99225c8
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ install:
- "pip install -r requirements.txt"
script:
- python tests/check_titles.py
- python tests/check_confs.py
- mkdocs build -f mkdocs.yml
- mkdocs build -f mkdocs_es.yml --clean
- python tests/check_strings.py -v -l
93 changes: 93 additions & 0 deletions tests/check_confs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from __future__ import division, print_function, unicode_literals
from os.path import abspath, normpath, dirname, join, isfile
import yaml
import os


red = "\033[0;31m"
green = "\033[0;32m"
yellow = "\033[0;33m"
endcl = "\033[0m"
cross = u"\U00002717"
check = u"\U00002713"

alt_configs = [
'es'
]

NOT_CHECK = [
'pages', 'language', 'markdown_i18n', 'google_analytics'
]

anyerr = 0
err = 0

with open('mkdocs.yml', 'r') as mkdocs_conf:
default_conf = [data for data in yaml.load_all(mkdocs_conf)][0]
for key in NOT_CHECK:
if default_conf.get(key):
default_conf.pop(key)


def check_conf(key, src, dest):
if key in NOT_CHECK:
return {key: 0}
if key not in src:
return {key: -1}
if key not in dest:
return {key: -2}
if isinstance(src[key], dict):
errs = 0
for k in src[key].keys():
errs = check_conf(k, src[key], dest[key])
if errs < 0:
return errs
elif isinstance(src[key], str):
if src[key] != dest[key]:
return {key: -2}
elif isinstance(src[key], (tuple, list)):
errs = 0
for elem in src[key]:
if len(dest) < src[key].index(elem):
return {key: -2}
elem2 = dest[key][src[key].index(elem)]
if isinstance(elem, dict):
for k in elem.keys():
errs = check_conf(k, elem, elem2)
if errs < 0:
return errs
elif isinstance(elem, str):
if elem != elem2:
return {key: -2}
return {key: 0}


for suffix in alt_configs:
with open('mkdocs_{}.yml'.format(suffix)) as mkdocs_conf:
alt_conf = [data for data in yaml.load_all(mkdocs_conf)][0]
for conf, value in default_conf.items():
if conf not in alt_conf.keys():
print('{red}{cross} [mkdocs_{suffix}.yml] Conf missing:'
' {conf}{endcl}'.format(**locals()))
err += 1
if conf in NOT_CHECK:
continue
errs = {
k: v for k, v in check_conf(conf, default_conf, alt_conf).items()
if v < 0
}
if errs:
print('{red}{cross} [mkdocs_{suffix}.yml] Conf missmatch:'
' {conf}{endcl}'.format(**locals()))
for k in errs.keys():
print('{red}\t- {{{k}}}{endcl}'.format(**locals()))
err += 1
if not err:
print('{green}{check} "mkdocs_{suffix}.yml" passed!{endcl}'
''.format(**locals()))
anyerr += err
err = 0

if NOT_CHECK:
print('{yellow}(IGNORED):\t{NOT_CHECK}{endcl}'.format(**locals()))
exit(anyerr)

0 comments on commit 99225c8

Please sign in to comment.