From 9a9705a667f3284c6cb7989915a31c37d744b42a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 2 May 2023 10:59:53 +0200 Subject: [PATCH] update test_read_metadata to use ruamel.yaml and YAML 1.2 I tried to get this to indent the .yaml files properly so yamllint defaults work with tests/metadata/dump/*.yaml, but it didn't take for some reason: yaml.indent(mapping=4, sequence=4, offset=2) --- fdroidserver/metadata.py | 4 ++ tests/metadata.TestCase | 18 +++--- tests/metadata/dump/com.politedroid.yaml | 5 +- tests/metadata/dump/org.adaway.yaml | 58 +++++++++---------- .../dump/org.smssecure.smssecure.yaml | 16 ++--- tests/metadata/dump/org.videolan.vlc.yaml | 2 +- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 5f16beac..a97da7ae 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -297,6 +297,10 @@ class Build(dict): else: raise AttributeError("No such attribute: " + name) + @classmethod + def to_yaml(cls, representer, node): + return representer.represent_dict(node) + def build_method(self): for f in ['maven', 'gradle']: if self.get(f): diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index a60841b2..b4301fba 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -6,6 +6,7 @@ import logging import optparse import os import random +import ruamel.yaml import shutil import sys import unittest @@ -15,9 +16,6 @@ from collections import OrderedDict from pathlib import Path from testcommon import TmpCwd -from ruamel.yaml import YAML - -yaml = YAML(typ='safe') localmodule = Path(__file__).resolve().parent.parent print('localmodule: ' + str(localmodule)) @@ -203,6 +201,7 @@ class MetadataTest(unittest.TestCase): def test_valid_funding_yml_regex(self): """Check the regex can find all the cases""" with (self.basedir / 'funding-usernames.yaml').open() as fp: + yaml = ruamel.yaml.YAML(typ='safe') data = yaml.load(fp) for k, entries in data.items(): @@ -220,10 +219,7 @@ class MetadataTest(unittest.TestCase): ) def test_read_metadata(self): - def _build_yaml_representer(dumper, data): - '''Creates a YAML representation of a Build instance''' - return dumper.represent_dict(data) - + """Read specified metadata files included in tests/, compare to stored output""" self.maxDiff = None config = dict() @@ -231,6 +227,7 @@ class MetadataTest(unittest.TestCase): fdroidserver.common.config = config fdroidserver.metadata.warnings_action = None + yaml = ruamel.yaml.YAML(typ='safe') apps = fdroidserver.metadata.read_metadata() for appid in ( 'org.smssecure.smssecure', @@ -246,9 +243,10 @@ class MetadataTest(unittest.TestCase): self.assertEqual(frommeta, from_yaml) # comment above assert and uncomment below to update test # files when new metadata fields are added - # with savepath.open('w') as f: - # yaml.add_representer(fdroidserver.metadata.Build, _build_yaml_representer) - # yaml.dump(frommeta, f, default_flow_style=False) + # with savepath.open('w') as fp: + # yaml.default_flow_style = False + # yaml.register_class(metadata.Build) + # yaml.dump(frommeta, fp) def test_rewrite_yaml_fakeotaupdate(self): with tempfile.TemporaryDirectory() as testdir: diff --git a/tests/metadata/dump/com.politedroid.yaml b/tests/metadata/dump/com.politedroid.yaml index acde9299..783308b7 100644 --- a/tests/metadata/dump/com.politedroid.yaml +++ b/tests/metadata/dump/com.politedroid.yaml @@ -1,5 +1,6 @@ AllowedAPKSigningKeys: [] -AntiFeatures: ['NonFreeNet'] +AntiFeatures: +- NonFreeNet ArchivePolicy: 4 versions AuthorEmail: null AuthorName: null @@ -130,7 +131,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null diff --git a/tests/metadata/dump/org.adaway.yaml b/tests/metadata/dump/org.adaway.yaml index 57fab70c..d9b26cb9 100644 --- a/tests/metadata/dump/org.adaway.yaml +++ b/tests/metadata/dump/org.adaway.yaml @@ -15,7 +15,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: ea5378a94ee0dc1d99d2cec95fae7e6d81afb2b9 disable: '' encoding: null @@ -51,7 +51,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 4128e59da2eac5c2904c7c7568d298ca51e79540 disable: '' encoding: null @@ -88,7 +88,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 0b9985398b9eef7baf6aadd0dbb12002bc199d2e disable: '' encoding: null @@ -125,7 +125,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: ab27f4dab5f3ea5e228cfb4a6b0e1fbf53695f22 disable: '' encoding: null @@ -162,7 +162,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 695e3801e4081026c8f7213a2345fc451d5eb89c disable: '' encoding: null @@ -199,7 +199,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 65138c11cc8b6affd28b68e125fbc1dff0886a4e disable: '' encoding: null @@ -271,7 +271,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: f811e53e1e1d2ee047b18715fd7d2072b90ae76b disable: '' encoding: null @@ -308,7 +308,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: ff97932761cdee68638dc2550751a64b2cbe18e7 disable: '' encoding: null @@ -345,7 +345,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 33d4d80998f30bafc88c04c80cbae00b03916f99 disable: '' encoding: null @@ -382,7 +382,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: 743d25a7e287505461f33f4b8e57e4cf988fffea disable: '' encoding: null @@ -419,7 +419,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: eaa07f4 disable: '' encoding: null @@ -688,7 +688,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.1 disable: '' encoding: null @@ -738,7 +738,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.3 disable: '' encoding: null @@ -784,7 +784,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.6 disable: '' encoding: null @@ -792,7 +792,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -822,7 +822,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.7 disable: '' encoding: null @@ -830,7 +830,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -860,7 +860,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.8 disable: '' encoding: null @@ -868,7 +868,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -898,7 +898,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.8.1 disable: '' encoding: null @@ -906,7 +906,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -936,7 +936,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.9 disable: '' encoding: null @@ -944,7 +944,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -974,7 +974,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.9.1 disable: '' encoding: null @@ -982,7 +982,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -1012,7 +1012,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v2.9.2 disable: '' encoding: null @@ -1020,7 +1020,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -1050,7 +1050,7 @@ Builds: binary: null build: '' buildjni: - - 'yes' + - yes commit: v3.0 disable: '' encoding: null @@ -1058,7 +1058,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null diff --git a/tests/metadata/dump/org.smssecure.smssecure.yaml b/tests/metadata/dump/org.smssecure.smssecure.yaml index a88a6a6a..af864923 100644 --- a/tests/metadata/dump/org.smssecure.smssecure.yaml +++ b/tests/metadata/dump/org.smssecure.smssecure.yaml @@ -22,7 +22,7 @@ Builds: forcevercode: true forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -83,7 +83,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -126,7 +126,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -167,7 +167,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -208,7 +208,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -248,7 +248,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -288,7 +288,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null @@ -328,7 +328,7 @@ Builds: forcevercode: false forceversion: false gradle: - - 'yes' + - yes gradleprops: [] init: '' maven: null diff --git a/tests/metadata/dump/org.videolan.vlc.yaml b/tests/metadata/dump/org.videolan.vlc.yaml index 290dbabe..b1679ab9 100644 --- a/tests/metadata/dump/org.videolan.vlc.yaml +++ b/tests/metadata/dump/org.videolan.vlc.yaml @@ -2640,7 +2640,7 @@ UpdateCheckIgnore: null UpdateCheckMode: Tags UpdateCheckName: null VercodeOperation: - - '%c + 5' +- '%c + 5' WebSite: http://www.videolan.org/vlc/download-android.html added: null id: org.videolan.vlc