1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

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

View File

@ -21,6 +21,11 @@ from binascii import unhexlify
from distutils.version import LooseVersion
from testcommon import TmpCwd
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)
@ -634,7 +639,7 @@ class UpdateTest(unittest.TestCase):
# yaml.dump(apk, f, default_flow_style=False)
with open(savepath, 'r') as f:
from_yaml = yaml.load(f)
from_yaml = yaml.load(f, Loader=SafeLoader)
self.maxDiff = None
self.assertEqual(apk, from_yaml)
@ -844,7 +849,7 @@ class UpdateTest(unittest.TestCase):
self.assertEqual('Internet', app['Categories'][0])
break
with open(testfile) as fp:
data = yaml.load(fp)
data = yaml.load(fp, Loader=SafeLoader)
self.assertEqual('urzip', data['Name'])
self.assertEqual('urzip', data['Summary'])
@ -943,7 +948,7 @@ class UpdateTest(unittest.TestCase):
'''))
fdroidserver.update.create_metadata_from_template(apk)
with open(os.path.join('metadata', 'rocks.janicerand.yml')) as f:
metadata_content = yaml.load(f)
metadata_content = yaml.load(f, Loader=SafeLoader)
self.maxDiff = None
self.assertDictEqual(metadata_content,
{'ArchivePolicy': '',
@ -1050,7 +1055,7 @@ class UpdateTest(unittest.TestCase):
apps = {app.id: app}
with open(os.path.join('build', app.id, 'FUNDING.yml'), 'w') as fp:
fp.write(line)
data = yaml.load(line)
data = yaml.load(line, Loader=SafeLoader)
fdroidserver.update.insert_funding_yml_donation_links(apps)
if 'liberapay' in data:
self.assertEqual(data['liberapay'], app.get('Liberapay'))
@ -1080,7 +1085,7 @@ class UpdateTest(unittest.TestCase):
def test_sanitize_funding_yml(self):
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:
if k in 'custom':