Fwd: [PATCH] Added mouse test case. Edited command mouse.py to raise KickstartValueError instead of IndexError when no argument given.

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

 



----- Forwarded Message -----
From: "Martin Gracik" <mgracik@xxxxxxxxxx>
To: kickstart-list@xxxxxxxxxx
Cc: "Martin Gracik" <mgracik@xxxxxxxxxx>
Sent: Monday, February 9, 2009 3:46:06 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: [PATCH] Added mouse test case. Edited command mouse.py to raise KickstartValueError instead of IndexError when no argument given.

---
 pykickstart/commands/mouse.py |   10 ++++++-
 tests/commands/mouse.py       |   49 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 tests/commands/mouse.py

diff --git a/pykickstart/commands/mouse.py b/pykickstart/commands/mouse.py
index 27e248f..b1c3255 100644
--- a/pykickstart/commands/mouse.py
+++ b/pykickstart/commands/mouse.py
@@ -15,11 +15,15 @@
 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
 # trademarks that are incorporated in the source code or documentation are not
 # subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc. 
+# with the express permission of Red Hat, Inc.
 #
 from pykickstart.base import *
+from pykickstart.errors import *
 from pykickstart.options import *
 
+import gettext
+_ = lambda x: gettext.ldgettext("pykickstart", x)
+
 class RHEL3_Mouse(KickstartCommand):
     removedKeywords = KickstartCommand.removedKeywords
     removedAttrs = KickstartCommand.removedAttrs
@@ -39,7 +43,7 @@ class RHEL3_Mouse(KickstartCommand):
         if self.device:
             opts += "--device=%s " % self.device
         if self.emulthree:
-            opts += "--emulthree " 
+            opts += "--emulthree "
 
         if self.mouse:
             retval += "# System mouse\nmouse %s%s\n" % (opts, self.mouse)
@@ -54,6 +58,8 @@ class RHEL3_Mouse(KickstartCommand):
     def parse(self, args):
         (opts, extra) = self.op.parse_args(args=args)
         self._setToSelf(self.op, opts)
+        if len(extra) < 1:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mouse command requires an argument."))
         self.mouse = extra[0]
         return self
 
diff --git a/tests/commands/mouse.py b/tests/commands/mouse.py
new file mode 100644
index 0000000..9c0a9c5
--- /dev/null
+++ b/tests/commands/mouse.py
@@ -0,0 +1,49 @@
+#
+# Martin Gracik <mgracik@xxxxxxxxxx>
+#
+# Copyright 2009 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use, modify,
+# copy, or redistribute it subject to the terms and conditions of the GNU
+# General Public License v.2.  This program is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
+# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
+# trademarks that are incorporated in the source code or documentation are not
+# subject to the GNU General Public License and may only be used or replicated
+# with the express permission of Red Hat, Inc.
+#
+
+import unittest
+from tests.baseclass import *
+
+class RHEL3_TestCase(CommandTest):
+    def runTest(self):
+        # pass
+        self.assert_parse("mouse jerry", "mouse jerry\n")
+        self.assert_parse("mouse --device=/dev/mice --emulthree jerry", "mouse --device=/dev/mice --emulthree jerry\n")
+        self.assert_parse("mouse jerry --device=/dev/mice", "mouse --device=/dev/mice jerry\n")
+        self.assert_parse("mouse jerry --emulthree", "mouse --emulthree jerry\n")
+
+        # fail
+        # empty
+        self.assert_parse_error("mouse", KickstartValueError)
+        # unknown option
+        self.assert_parse_error("mouse jerry --bad-flag", KickstartParseError)
+        # --device requires argument
+        self.assert_parse_error("mouse jerry --device", KickstartParseError)
+
+
+class FC3_TestCase(CommandTest):
+    def runTest(self):
+        # pass
+        # deprecated command
+        pass
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.6.0.6

_______________________________________________
Kickstart-list mailing list
Kickstart-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/kickstart-list

[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux