Skip to content

Commit

Permalink
Merge pull request #2590 from getnikola/remove-asserts
Browse files Browse the repository at this point in the history
Remove all uses of `assert` in the codebase
  • Loading branch information
Kwpolska committed Dec 10, 2016
2 parents 1492963 + 167839c commit 64762d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 6 additions & 4 deletions nikola/nikola.py
Expand Up @@ -1365,8 +1365,8 @@ def render_template(self, template_name, output_name, context, url_type=None, is
if output_name is None:
return data

assert output_name.startswith(
self.config["OUTPUT_FOLDER"])
if not output_name.startswith(self.config["OUTPUT_FOLDER"]):
raise ValueError("Output path for templates must start with OUTPUT_FOLDER")
url_part = output_name[len(self.config["OUTPUT_FOLDER"]) + 1:]

# Treat our site as if output/ is "/" and then make all URLs relative,
Expand Down Expand Up @@ -1528,7 +1528,8 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
if parsed_dst.fragment:
result += "#" + parsed_dst.fragment

assert result, (src, dst, i, src_elems, dst_elems)
if not result:
raise ValueError("Failed to parse link: {0}".format((src, dst, i, src_elems, dst_elems)))

return result

Expand Down Expand Up @@ -1890,7 +1891,8 @@ def flatten(task):
task_dep = []
for pluginInfo in self.plugin_manager.getPluginsOfCategory(plugin_category):
for task in flatten(pluginInfo.plugin_object.gen_tasks()):
assert 'basename' in task
if 'basename' not in task:
raise ValueError("Task {0} does not have a basename".format(task))
task = self.clean_task_paths(task)
if 'task_dep' not in task:
task['task_dep'] = []
Expand Down
3 changes: 2 additions & 1 deletion nikola/plugins/misc/taxonomies_classifier.py
Expand Up @@ -66,7 +66,8 @@ def _do_classification(self, site):
for lang in site.config['TRANSLATIONS'].keys():
# Extract classifications for this language
classifications[lang] = taxonomy.classify(post, lang)
assert taxonomy.more_than_one_classifications_per_post or len(classifications[lang]) <= 1
if not taxonomy.more_than_one_classifications_per_post and len(classifications[lang]) > 1:
raise ValueError("Too many {0} classifications for post {1}".format(taxonomy.classification_name, post.source_path))
# Add post to sets
for classification in classifications[lang]:
while True:
Expand Down
5 changes: 3 additions & 2 deletions nikola/utils.py
Expand Up @@ -922,7 +922,7 @@ def filter_matches(ext):
if ext == key:
return value
else:
assert False, key
raise ValueError("Cannot find filter match for {0}".format(key))

for target in task.get('targets', []):
ext = os.path.splitext(target)[-1].lower()
Expand Down Expand Up @@ -1100,7 +1100,8 @@ def initialize(cls, locales, initial_lang):
locale.setlocale(locale.LC_ALL, locale_n) will succeed
locale_n expressed in the string form, like "en.utf8"
"""
assert initial_lang is not None and initial_lang in locales
if initial_lang is None or initial_lang not in locales:
raise ValueError("Unknown initial language {0}".format(initial_lang))
cls.reset()
cls.locales = locales
cls.month_name_handlers = []
Expand Down

0 comments on commit 64762d7

Please sign in to comment.