]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
tests: add helper function to test enumerations and flags
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 19 Jun 2022 11:38:51 +0000 (20:38 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 19 Jun 2022 11:38:51 +0000 (20:38 +0900)
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 <o-takashi@sakamocchi.jp>
tests/alsactl-enums
tests/alsahwdep-enums
tests/alsarawmidi-enums
tests/alsaseq-enums
tests/alsatimer-enums
tests/helper.py

index 01cf41c0d57b604549248d312b4efda16c7de667..25abdb627a5cc5e759720d504f38447200594ab0 100644 (file)
@@ -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)
index 5ad287bebe2623c97351b16101e2d05278cbdd9a..958234f217bb51ba8d55a649df371e205b1a3670 100644 (file)
@@ -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)
index 5959b3a3ba13a53be5dd9ae14f318bbc2ee3b822..f4971bbe357aafcd4b4d45f2dc1181e9fb98483a 100644 (file)
@@ -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)
index 72b7747dce5917e30eac3c723b32aed91774ba09..0c03d19c7ce5b01d9d66d052a4d1f3117162dd82 100644 (file)
@@ -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)
index 76906cae477712b8e733b7ef441d9d27c6bc0bc8..142a39908bf8f5f949a34d43a37b8d44dcd49028 100644 (file)
@@ -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)
index f67c6cb9e64806128b19e30b6ecb697c2bab0ee5..2ab15dc72c2f55860a11a0d7dec144409a1f39a4 100644 (file)
@@ -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