t_action.py revision 409
409N/A#!/usr/bin/python2.4
305N/A#
305N/A# CDDL HEADER START
305N/A#
305N/A# The contents of this file are subject to the terms of the
305N/A# Common Development and Distribution License (the "License").
305N/A# You may not use this file except in compliance with the License.
305N/A#
305N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
305N/A# or http://www.opensolaris.org/os/licensing.
305N/A# See the License for the specific language governing permissions
305N/A# and limitations under the License.
305N/A#
305N/A# When distributing Covered Code, include this CDDL HEADER in each
305N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
305N/A# If applicable, add the following below this CDDL HEADER, with the
305N/A# fields enclosed by brackets "[]" replaced with your own identifying
305N/A# information: Portions Copyright [yyyy] [name of copyright owner]
305N/A#
305N/A# CDDL HEADER END
305N/A#
305N/A
305N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
305N/A# Use is subject to license terms.
305N/A
305N/Aimport unittest
305N/A
305N/Aimport pkg.actions as action
305N/A
305N/Aclass TestActions(unittest.TestCase):
305N/A
315N/A def test_action_parser(self):
315N/A action.fromstr("file 12345 name=foo")
315N/A action.fromstr("file 12345 name=foo attr=bar")
315N/A action.fromstr("file 12345 name=foo attr=bar attr=bar")
305N/A
315N/A action.fromstr("file 12345 name=foo attr=bar")
315N/A action.fromstr("file 12345 name=foo attr=bar ")
315N/A action.fromstr("file 12345 name=foo attr=bar ")
315N/A
315N/A action.fromstr("file 12345 name=\"foo bar\" attr=\"bar baz\"")
315N/A action.fromstr("file 12345 name=\"foo bar\" attr=\"bar baz\"")
315N/A
381N/A action.fromstr("file 12345 name=foo value=barbaz")
381N/A action.fromstr("file 12345 name=foo value=\"bar baz\"")
381N/A action.fromstr("file 12345 name=\"foo bar\" value=baz")
381N/A
381N/A action.fromstr("file 12345 name=foo value=barbazquux")
381N/A action.fromstr("file 12345 name=foo value=\"bar baz quux\"")
381N/A action.fromstr("file 12345 name=\"foo bar baz\" value=quux")
381N/A
381N/A action.fromstr("file 12345 name=\"foo\" value=\"bar\"")
381N/A action.fromstr("file 12345 name=foo value=\"bar\"")
381N/A action.fromstr("file 12345 name=\"foo\" value=bar")
381N/A
315N/A action.fromstr("driver alias=pci1234,56 alias=pci4567,89 class=scsi name=lsimega")
305N/A
315N/A def test_action_tostr(self):
315N/A str(action.fromstr("file 12345 name=foo"))
315N/A str(action.fromstr("file 12345 name=foo attr=bar"))
315N/A str(action.fromstr("file 12345 name=foo attr=bar attr=bar"))
305N/A
315N/A str(action.fromstr("file 12345 name=foo attr=bar"))
315N/A str(action.fromstr("file 12345 name=foo attr=bar "))
315N/A str(action.fromstr("file 12345 name=foo attr=bar "))
305N/A
315N/A str(action.fromstr("file 12345 name=\"foo bar\" attr=\"bar baz\""))
315N/A str(action.fromstr("file 12345 name=\"foo bar\" attr=\"bar baz\""))
315N/A
381N/A str(action.fromstr("file 12345 name=foo value=barbaz"))
381N/A str(action.fromstr("file 12345 name=foo value=\"bar baz\""))
381N/A str(action.fromstr("file 12345 name=\"foo bar\" value=baz"))
381N/A
381N/A str(action.fromstr("file 12345 name=foo value=barbazquux"))
381N/A str(action.fromstr("file 12345 name=foo value=\"bar baz quux\""))
381N/A str(action.fromstr("file 12345 name=\"foo bar baz\" value=quux"))
381N/A
381N/A str(action.fromstr("file 12345 name=\"foo\" value=\"bar\""))
381N/A str(action.fromstr("file 12345 name=foo value=\"bar\""))
381N/A str(action.fromstr("file 12345 name=\"foo\" value=bar"))
381N/A
315N/A str(action.fromstr("driver alias=pci1234,56 alias=pci4567,89 class=scsi name=lsimega"))
305N/A
315N/A def test_action_errors(self):
315N/A # bogus action
315N/A self.assertRaises(KeyError, action.fromstr, "moop")
305N/A
315N/A # bad quoting
315N/A self.assertRaises(ValueError, action.fromstr,
315N/A "file 12345 name=\"foo bar")
305N/A
315N/A self.assertRaises(ValueError, action.fromstr,
315N/A "file 12345 \"name=foo bar")
315N/A
315N/A #self.assertRaises(ValueError, action.fromstr,
315N/A # "file 12345 na\"me=foo bar")
305N/A
315N/A #self.assertRaises(ValueError, action.fromstr,
315N/A # "file 12345 name=foo\"bar")
315N/A
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 =\"\"")
305N/A
315N/A # bogus attributes
315N/A self.assertRaises(ValueError, action.fromstr, "file =")
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 broken")
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 broken=")
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 =")
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 ==")
315N/A self.assertRaises(ValueError, action.fromstr, "file 1234 ===")
315N/A pass
305N/A
305N/A
305N/Aif __name__ == "__main__":
305N/A unittest.main()