6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 06:07:56 +00:00

Fix yaml parsing of "null"

This commit is contained in:
Régis Behmo 2019-03-24 14:24:50 -07:00
parent ca8eda839d
commit 288dc12796
2 changed files with 9 additions and 1 deletions

View File

@ -10,3 +10,8 @@ class UtilsTests(unittest.TestCase):
self.assertEqual("sub1.domain.com", utils.common_domain("sub1.domain.com", "sub2.sub1.domain.com"))
self.assertEqual("com", utils.common_domain("domain1.com", "domain2.com"))
self.assertEqual("domain.com", utils.common_domain("sub.domain.com", "ub.domain.com"))
def test_parse_yaml_value(self):
self.assertEqual(True, utils.parse_yaml_value("true"))
self.assertEqual(False, utils.parse_yaml_value("false"))
self.assertEqual(None, utils.parse_yaml_value("null"))

View File

@ -13,10 +13,13 @@ def random_string(length):
def parse_yaml_value(v):
"""
Parse a yaml-formatted string
Parse a yaml-formatted string. This is fairly basic and should only be used
for parsing of elementary values.
"""
if v.isdigit():
v = int(v)
elif v == "null":
v = None
elif v in ["true", "false"]:
v = (v == "true")
return v