Skip to content

Instantly share code, notes, and snippets.

@zed zed/prog.py Secret
Last active Dec 17, 2015

Embed
What would you like to do?
#!/usr/bin/env python
"""
Usage:
prog.py -h | -v
prog.py [-f FILE -F FORMAT | -u URL [-V] -F FORMAT]
Options:
-h --help help
-v --version version
-f FILE file
-F FORMAT format
-u URL url
-V --verbose verbose
"""
from docopt import docopt
if __name__ == '__main__':
arguments = docopt(__doc__, version='Prog 0.1')
print(arguments)
#!/usr/bin/env python3
from itertools import combinations
from subprocess import call, DEVNULL, STDOUT
def powerset(seq):
return (c for r in range(len(seq) + 1) for c in combinations(seq, r))
for args in map(list, powerset("-f a -F b -u c -V d --unknown".split())):
rc = call(['./prog.py'] + args, stdin=DEVNULL, stdout=DEVNULL, stderr=STDOUT)
print("{} {}".format("pass" if rc == 0 else "fail", args))
"""$ grep pass
pass []
pass ['-f', 'a', '-F', 'b']
pass ['-f', 'a', '-F', '-u']
pass ['-f', 'a', '-F', 'c']
pass ['-f', 'a', '-F', '-V']
pass ['-f', 'a', '-F', 'd']
pass ['-f', 'a', '-F', '--unknown']
pass ['-F', 'b', '-u', 'c']
pass ['-F', 'b', '-u', '-V']
pass ['-F', 'b', '-u', 'd']
pass ['-F', 'b', '-u', '--unknown']
pass ['-F', 'b', '-u', 'c', '-V']
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.