diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2007-12-31 02:10:56 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2007-12-31 02:10:56 +0000 |
commit | 104a1e27cee2d5524460d26c83d3e920cd88b2e9 (patch) | |
tree | 2d5b9fac84ad048508a371541ffc41683fc08327 /src/lib | |
parent | d017662635d02701b952a9757af3569ff1cca19d (diff) | |
download | bcfg2-104a1e27cee2d5524460d26c83d3e920cd88b2e9.tar.gz bcfg2-104a1e27cee2d5524460d26c83d3e920cd88b2e9.tar.bz2 bcfg2-104a1e27cee2d5524460d26c83d3e920cd88b2e9.zip |
Add unit testing for new option parsing library (Full Coverage)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4141 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Options.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/lib/Options.py b/src/lib/Options.py index 4e9a0a494..77e5bd718 100644 --- a/src/lib/Options.py +++ b/src/lib/Options.py @@ -13,6 +13,7 @@ class Option(object): if not self.__cfp: self.__cfp = ConfigParser.ConfigParser() self.__cfp.readfp(open(self.cfpath)) + return self.__cfp cfp = property(getCFP) def getValue(self): @@ -29,7 +30,7 @@ class Option(object): self.cmd = cmd if cmd and (cmd[0] != '-' or len(cmd) != 2): raise OptionFailure("Poorly formed command %s" % cmd) - self.odesg = odesc + self.odesc = odesc self.env = env self.cf = cf self.cook = cook @@ -54,9 +55,9 @@ class Option(object): def parse(self, opts, rawopts): if self.cmd and opts: # processing getopted data - optinfo = [opt[1] for opt in opts if opt[0] == option[0]] + optinfo = [opt[1] for opt in opts if opt[0] == self.cmd] if optinfo: - self._value = optinfo + self._value = optinfo[0] return if self.cmd and self.cmd in rawopts: self._value = rawopts[rawopts.index(self.cmd) + 1] @@ -67,10 +68,8 @@ class Option(object): return if self.cf: try: - if self.cf in locations: - self._value = self.cfp.get(*locations[self.cf]) - else: - self._value = self.cfp.get(*self.cf) + self._value = self.cfp.get(*self.cf) + return except: pass self._value = self.default @@ -94,11 +93,11 @@ class OptionSet(dict): ret = {} if do_getopt: try: - opts, args = getopt.getopt(argv, self.buildHelpGetopt(), []) + opts, args = getopt.getopt(argv, self.buildGetopt(), []) except getopt.GetoptError, err: self.helpExit(err) if '-h' in argv: - self.helpExit(err) + self.helpExit('', 0) for key in self.keys(): option = self[key] if do_getopt: @@ -112,11 +111,11 @@ class OptionSet(dict): class OptionParser(OptionSet): '''OptionParser bootstraps option parsing, getting the value of the config file''' def __init__(self, args): - self.Bootstrap = OptionSet(['configfile', Option('config file path', - '/etc/bcfg2.conf', - cmd='-C')]) + self.Bootstrap = OptionSet([('configfile', Option('config file path', + '/etc/bcfg2.conf', + cmd='-C'))]) self.Bootstrap.parse(sys.argv[1:], do_getopt=False) - if self.Bootstrap['configfile'] != '/etc/bcfg2.conf': + if self.Bootstrap['configfile'] != Option.cfpath: Option.cfpath = self.Bootstrap['configfile'] Option.__cfp = False OptionSet.__init__(self, args) |