1 from __future__ import print_function
3 ### utility to match command-line args to names
5 def __init__ (self, names):
7 # is an input string acceptable for one of the known names?
9 def fits (input, name):
10 return name.find(input)==0
11 # returns one of the names if the input name has a unique match
13 def only_match (self, input):
14 if input in self.names: return input
15 matches=[ name for name in self.names if Candidates.fits(input,name) ]
16 if len(matches)==1: return matches[0]
19 #################### minimal test
21 ('create delete reset resources slices start status stop version create_gid',
36 ('create_','create_gid'),
37 ('create_g','create_gid'),
38 ('create_gi','create_gid'),
39 ('create_gid','create_gid'),
43 def test_candidates ():
44 for (names, tuples) in candidates_specs:
46 for (input,expected) in tuples:
47 got=Candidates(names).only_match(input)
48 if got==expected: print('.', end=' ')
49 else: print('X FAIL','names[',names,'] input',input,'expected',expected,'got',got)
51 if __name__ == '__main__':