[tests:results] enable 'extension' and ':?' in format tests

This commit is contained in:
Mike Fährmann
2025-05-26 13:48:46 +02:00
parent e4d139c3ce
commit 456e93d489
2 changed files with 21 additions and 17 deletions

View File

@@ -150,9 +150,9 @@ __tests__ = (
"#category": ("", "facebook", "video"), "#category": ("", "facebook", "video"),
"#class" : facebook.FacebookVideoExtractor, "#class" : facebook.FacebookVideoExtractor,
"#count" : 2, "#count" : 2,
"#archive": False,
"filename" : "1514198129001376", "filename" : str,
"extension": {"mp4", "m4a"},
"id" : "644342003942740", "id" : "644342003942740",
"url" : str, "url" : str,
"user_id" : "100064860875397", "user_id" : "100064860875397",

View File

@@ -402,27 +402,31 @@ class TestPathfmt():
class TestFormatter(formatter.StringFormatter): class TestFormatter(formatter.StringFormatter):
@staticmethod
def _noop(_):
return ""
def _apply_simple(self, key, fmt): def _apply_simple(self, key, fmt):
if key == "extension" or "_parse_optional." in repr(fmt): if key == "extension" or "_parse_optional." in repr(fmt):
return self._noop def wrap(obj):
try:
def wrap(obj): return fmt(obj[key])
return fmt(obj[key]) except KeyError:
return ""
else:
def wrap(obj):
return fmt(obj[key])
return wrap return wrap
def _apply(self, key, funcs, fmt): def _apply(self, key, funcs, fmt):
if key == "extension" or "_parse_optional." in repr(fmt): if key == "extension" or "_parse_optional." in repr(fmt):
return self._noop def wrap(obj):
obj = obj[key] if key in obj else ""
def wrap(obj): for func in funcs:
obj = obj[key] obj = func(obj)
for func in funcs: return fmt(obj)
obj = func(obj) else:
return fmt(obj) def wrap(obj):
obj = obj[key]
for func in funcs:
obj = func(obj)
return fmt(obj)
return wrap return wrap