speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Raise exceptions on invalid inputs in speechd_config


From: Hynek Hanke
Subject: [PATCH] Raise exceptions on invalid inputs in speechd_config
Date: Wed, 1 Sep 2010 16:43:38 +0200

Since speechd_config can now be used as a library,
it is important to check parameters on function
entries.

Formerly, asserts were used to check internal code consistency
of the configuration type argument and checking of the correct
value was done on user's input.
---
 src/python/speechd_config/config.py |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/python/speechd_config/config.py 
b/src/python/speechd_config/config.py
index 08a9489..26bdccd 100644
--- a/src/python/speechd_config/config.py
+++ b/src/python/speechd_config/config.py
@@ -75,6 +75,8 @@ def question(text, default):
             return int(str_inp)
         elif isinstance(default, str):
             return str_inp
+        else:
+            raise TypeError("Invalid type for the default value")
 
 def question_with_suggested_answers(text, default, suggest):
     """Ask a question with suggested answers. If the answer typed is not
@@ -346,8 +348,8 @@ Search for package like python-speechd, download and 
install it""")
             cmd = "aplay" + " " + wavfile
         elif type == 'pulse':
             cmd = "paplay" + " " + wavfile
-        elif type == 'oss':
-            raise NotImplementedError
+        else:
+            raise NotImplementedError("Test for this audio system is not 
implemented")
 
         try:
             ret = os.system(cmd)
@@ -722,7 +724,7 @@ Do you want to keep it?""", False)
             report("Warning: You must be root or under sudo to do this.")
             report("Configuring system settings for Speech Dispatcher")
         else:
-            assert(0)
+            raise ValueError("Invalid configuration type")
 
         # Now determine the most important config option
         self.default_output_module = question_with_suggested_answers(
@@ -834,7 +836,7 @@ you have to start it manually to continue.""")
         elif speechd_type == 'system':
             self.configure_basic_settings(type='system')
         else:
-            assert(False)
+            raise ValueError("Invalid configuration type")
 
         reply = question("Do you want to start/restart Speech Dispatcher now 
and run some tests?", True)
         if not reply:
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]