1 ### utility to match command-line args to names
3 def __init__ (self, names):
5 # is an input string acceptable for one of the known names?
7 def fits (input, name):
8 return name.find(input)==0
9 # returns one of the names if the input name has a unique match
11 def only_match (self, input):
12 matches=[ name for name in self.names if Candidates.fits(input,name) ]
13 if len(matches)==1: return matches[0]
16 #################### minimal test
18 ('create delete reset resources slices start status stop version',
34 def test_candidates ():
35 for (names, tuples) in candidates_specs:
37 for (input,expected) in tuples:
38 got=Candidates(names).only_match(input)
39 if got==expected: print '.',
40 else: print 'X FAIL','names[',names,'] input',input,'expected',expected,'got',got
42 if __name__ == '__main__':