From: Takashi Sakamoto Date: Sun, 19 Jun 2022 11:38:51 +0000 (+0900) Subject: tests: add helper function to test enumerations and flags X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=bf803590f24abf220cf09777b94991e1407e3a41;p=alsa-gobject.git tests: add helper function to test enumerations and flags This commit adds helper function for enumerations and flags. All of available enumerations and flags are available via object attributes. Signed-off-by: Takashi Sakamoto --- diff --git a/tests/alsactl-enums b/tests/alsactl-enums index 01cf41c..25abdb6 100644 --- a/tests/alsactl-enums +++ b/tests/alsactl-enums @@ -1,10 +1,13 @@ #!/usr/bin/env python3 from sys import exit + import gi gi.require_version('ALSACtl', '0.0') from gi.repository import ALSACtl +from helper import test_enums + elem_types = ( 'NONE', 'BOOLEAN', @@ -70,8 +73,6 @@ types = { ALSACtl.CardError: card_error_types, } -for obj, types in types.items(): - for t in types: - if not hasattr(obj, t): - print('Enumerator {0} is not produced.'.format(t)) - exit(1) +for target_type, enumerations in types.items(): + if not test_enums(target_type, enumerations): + exit(1) diff --git a/tests/alsahwdep-enums b/tests/alsahwdep-enums index 5ad287b..958234f 100644 --- a/tests/alsahwdep-enums +++ b/tests/alsahwdep-enums @@ -1,10 +1,13 @@ #!/usr/bin/env python3 from sys import exit + import gi gi.require_version('ALSAHwdep', '0.0') from gi.repository import ALSAHwdep +from helper import test_enums + iface_types = ( 'OPL2', 'OPL3', @@ -49,8 +52,6 @@ types = { ALSAHwdep.DeviceCommonError: device_common_error_types, } -for obj, types in types.items(): - for t in types: - if not hasattr(obj, t): - print('Enumerator {0} is not produced.'.format(t)) - exit(1) +for target_type, enumerations in types.items(): + if not test_enums(target_type, enumerations): + exit(1) diff --git a/tests/alsarawmidi-enums b/tests/alsarawmidi-enums index 5959b3a..f4971bb 100644 --- a/tests/alsarawmidi-enums +++ b/tests/alsarawmidi-enums @@ -1,10 +1,13 @@ #!/usr/bin/env python3 from sys import exit + import gi gi.require_version('ALSARawmidi', '0.0') from gi.repository import ALSARawmidi +from helper import test_enums + stream_direction_types = ( 'OUTPUT', 'INPUT', @@ -27,8 +30,6 @@ types = { ALSARawmidi.StreamPairError: stream_pair_error_types, } -for obj, types in types.items(): - for t in types: - if not hasattr(obj, t): - print('Enumerator {0} is not produced.'.format(t)) - exit(1) +for target_type, enumerations in types.items(): + if not test_enums(target_type, enumerations): + exit(1) diff --git a/tests/alsaseq-enums b/tests/alsaseq-enums index 72b7747..0c03d19 100644 --- a/tests/alsaseq-enums +++ b/tests/alsaseq-enums @@ -1,17 +1,20 @@ #!/usr/bin/env python3 from sys import exit + import gi gi.require_version('ALSASeq', '0.0') from gi.repository import ALSASeq +from helper import test_enums + specific_address_types = ( 'UNKNOWN', 'SUBSCRIBERS', 'BROADCAST', ) -specific_client_id_types= ( +specific_client_id_types = ( 'SYSTEM', 'DUMMY', 'OSS', @@ -193,8 +196,6 @@ types = { ALSASeq.EventError: event_error_types, } -for obj, types in types.items(): - for t in types: - if not hasattr(obj, t): - print('Enumerator {0} is not produced.'.format(t)) - exit(1) +for target_type, enumerations in types.items(): + if not test_enums(target_type, enumerations): + exit(1) diff --git a/tests/alsatimer-enums b/tests/alsatimer-enums index 76906ca..142a399 100644 --- a/tests/alsatimer-enums +++ b/tests/alsatimer-enums @@ -5,6 +5,8 @@ import gi gi.require_version('ALSATimer', '0.0') from gi.repository import ALSATimer +from helper import test_enums + class_types = ( 'NONE', 'GLOBAL', @@ -74,8 +76,6 @@ types = { ALSATimer.UserInstanceError: user_instance_error_types, } -for obj, types in types.items(): - for t in types: - if not hasattr(obj, t): - print('Enumerator {0} is not produced.'.format(t)) - exit(1) +for target_type, enumerations in types.items(): + if not test_enums(target_type, enumerations): + exit(1) diff --git a/tests/helper.py b/tests/helper.py index f67c6cb..2ab15dc 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -18,3 +18,12 @@ def test_object(target, props, methods, signals) ->bool: print('Signal {0} is not produced.'.format(signal)) return False return True + + +def test_enums(target_type: object, enumerations: tuple[str]) -> bool: + for enumeration in enumerations: + if not hasattr(target_type, enumeration): + print('Enumeration {0} is not produced for {1}.'.format( + enumeration, target_type)) + return False + return True