use yaml safeloader in tests

Try to use CSafeLoader when possible because its significantly faster.
Use the normal Safeloader otherwise. (This mirrors the non-test code
behaviour)
This commit is contained in:
Marcus Hoffmann 2020-09-10 02:37:05 +02:00
parent 06766ba48b
commit 4cd96d4a9f
2 changed files with 17 additions and 7 deletions

View file

@ -18,6 +18,11 @@ import textwrap
from collections import OrderedDict
from unittest import mock
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
print('localmodule: ' + localmodule)
@ -103,7 +108,7 @@ class MetadataTest(unittest.TestCase):
def test_valid_funding_yml_regex(self):
"""Check the regex can find all the cases"""
with open(os.path.join(self.basedir, 'funding-usernames.yaml')) as fp:
data = yaml.safe_load(fp)
data = yaml.load(fp, Loader=SafeLoader)
for k, entries in data.items():
for entry in entries:
@ -135,7 +140,7 @@ class MetadataTest(unittest.TestCase):
frommeta = dict(apps[appid])
self.assertTrue(appid in apps)
with open(savepath, 'r') as f:
frompickle = yaml.load(f)
frompickle = yaml.load(f, Loader=SafeLoader)
self.assertEqual(frommeta, frompickle)
# comment above assert and uncomment below to update test
# files when new metadata fields are added