Refactor Test Code for Efficiency and Quality (#1100)

This commit is contained in:
Han Wang
2024-04-21 00:00:31 +01:00
committed by GitHub
parent 1f77254d71
commit 08cb018e11
29 changed files with 188 additions and 218 deletions

View File

@ -50,7 +50,7 @@ def test_parse_qsd():
"utils: parse_qsd() testing """
result = utils.parse_qsd('a=1&b=&c&d=abcd')
assert isinstance(result, dict) is True
assert isinstance(result, dict)
assert len(result) == 4
assert 'qsd' in result
assert 'qsd+' in result
@ -2607,39 +2607,39 @@ def test_apply_templating():
result = utils.apply_template(
template, **{'fname': 'Chris', 'whence': 'this morning'})
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == "Hello Chris, How are you this morning?"
# In this example 'whence' isn't provided, so it isn't swapped
result = utils.apply_template(
template, **{'fname': 'Chris'})
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == "Hello Chris, How are you {{whence}}?"
# white space won't cause any ill affects:
template = "Hello {{ fname }}, How are you {{ whence}}?"
result = utils.apply_template(
template, **{'fname': 'Chris', 'whence': 'this morning'})
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == "Hello Chris, How are you this morning?"
# No arguments won't cause any problems
template = "Hello {{fname}}, How are you {{whence}}?"
result = utils.apply_template(template)
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == template
# Wrong elements are simply ignored
result = utils.apply_template(
template,
**{'fname': 'l2g', 'whence': 'this evening', 'ignore': 'me'})
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == "Hello l2g, How are you this evening?"
# Empty template makes things easy
result = utils.apply_template(
"", **{'fname': 'l2g', 'whence': 'this evening'})
assert isinstance(result, str) is True
assert isinstance(result, str)
assert result == ""
# Regular expressions are safely escapped and act as normal