| 3 | import unittest |
| 4 | |
| 5 | class Completion(): |
| 6 | def prepare(self, program, command): |
| 7 | self.program=program |
| 8 | self.COMP_LINE="%s %s" % (program, command) |
| 9 | self.COMP_WORDS=self.COMP_LINE.rstrip() |
| 10 | args=command.split() |
| 11 | self.COMP_CWORD=len(args) |
| 12 | self.COMP_POINT=len(self.COMP_LINE) |
| 13 | if (self.COMP_LINE[-1] == ' '): |
| 14 | self.COMP_WORDS += " " |
| 15 | self.COMP_CWORD += 1 |
| 16 | |
| 17 | def run(self, completion_file, program, command): |
| 18 | self.prepare(program, command) |
| 19 | full_cmdline=r'source {compfile}; COMP_LINE="{COMP_LINE}" COMP_WORDS=({COMP_WORDS}) COMP_CWORD={COMP_CWORD} COMP_POINT={COMP_POINT}; $(complete -p {program} | sed "s/.*-F \\([^ ]*\\) .*/\\1/") && echo ${{COMPREPLY[*]}}'.format( |
| 20 | compfile=completion_file, COMP_LINE=self.COMP_LINE, COMP_WORDS=self.COMP_WORDS, COMP_POINT=self.COMP_POINT, program=self.program, COMP_CWORD=self.COMP_CWORD |
| 21 | ) |
| 22 | out = subprocess.Popen(['bash', '-i', '-c', full_cmdline], stdout=subprocess.PIPE) |
| 23 | return out.communicate() |
| 24 | |
| 25 | class CompletionTestCase(unittest.TestCase): |
| 26 |
no outgoing calls