1 from __future__ import print_function
3 # utility to match command-line args to names
8 def __init__(self, names):
10 # is an input string acceptable for one of the known names?
13 def fits(input, name):
14 return name.find(input) == 0
15 # returns one of the names if the input name has a unique match
18 def only_match(self, input):
19 if input in self.names:
21 matches = [name for name in self.names if Candidates.fits(input, name)]
29 ('create delete reset resources slices start status stop version create_gid',
36 ('reso', 'resources'),
44 ('create_', 'create_gid'),
45 ('create_g', 'create_gid'),
46 ('create_gi', 'create_gid'),
47 ('create_gid', 'create_gid'),
52 def test_candidates():
53 for (names, tuples) in candidates_specs:
55 for (input, expected) in tuples:
56 got = Candidates(names).only_match(input)
60 print('X FAIL', 'names[', names, '] input',
61 input, 'expected', expected, 'got', got)
63 if __name__ == '__main__':