Index: autopilot/trunk/autopilot/list_tasks.py =================================================================== --- autopilot/trunk/autopilot/list_tasks.py (revision 76) +++ autopilot/trunk/autopilot/list_tasks.py (revision 90) @@ -17,5 +17,128 @@ import ConfigParser as cp -if __name__ == "__main__": +def _main(): + """List all tasks for a glider in the configution file. + + These doctests require write permission to tests/etc. + + Missing configuration file: + + >>> from StringIO import StringIO + >>> cfg = os.path.join(os.path.dirname(__file__), + ... "tests", "etc", "autopilot.cfg") + >>> try: + ... os.remove(cfg) + ... except: + ... pass + >>> sys.argv = ["python", + ... cfg, + ... "cthulhu",] + >>> output = StringIO() + >>> save = sys.stdout + >>> sys.stdout = output + >>> _main() + >>> sys.stdout = save + >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ + ... format(os.path.abspath(cfg)) + True + >>> output.close() + + Empty configuration file: + + >>> from StringIO import StringIO + >>> cfg = os.path.join(os.path.dirname(__file__), + ... "tests", "etc", "autopilot.cfg") + >>> try: + ... os.remove(cfg) + ... open(cfg, 'w').close() + ... except: + ... pass + >>> sys.argv = ["python", + ... cfg, + ... "cthulhu",] + >>> output = StringIO() + >>> save = sys.stdout + >>> sys.stdout = output + >>> _main() + >>> sys.stdout = save + >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ + ... format(os.path.abspath(cfg)) + True + >>> output.close() + + Configuration does not contain glider: + + >>> import shutil + >>> from StringIO import StringIO + >>> cfg = os.path.join(os.path.dirname(__file__), + ... "tests", "etc", "autopilot.cfg") + >>> shutil.copy2(cfg + ".test", cfg) + >>> sys.argv = ["python", + ... cfg, + ... "Cthulhu"] + >>> output = StringIO() + >>> save = sys.stdout + >>> sys.stdout = output + >>> _main() + >>> sys.stdout = save + >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ + ... format(os.path.abspath(cfg)) + True + >>> output.close() + + Glider does not contain task list: + + >>> import shutil + >>> from StringIO import StringIO + >>> cfg = os.path.join(os.path.dirname(__file__), + ... "tests", "etc", "autopilot.cfg") + >>> shutil.copy2(cfg + ".test", cfg) + >>> sys.argv = ["python", + ... cfg, + ... "Ramses"] + >>> output = StringIO() + >>> save = sys.stdout + >>> sys.stdout = output + >>> _main() + >>> sys.stdout = save + >>> output.getvalue() == "No tasks for glider ramses exist in {0}.\\n". \\ + ... format(os.path.abspath(cfg)) + True + >>> output.close() + + Task list for glider is empty: + + >>> import shutil + >>> from StringIO import StringIO + >>> cfg = os.path.join(os.path.dirname(__file__), + ... "tests", "etc", "autopilot.cfg") + >>> shutil.copy2(cfg + ".test", cfg) + >>> sys.argv = ["python", + ... cfg, + ... "Pelagia"] + >>> output = StringIO() + >>> save = sys.stdout + >>> sys.stdout = output + >>> _main() + >>> sys.stdout = save + >>> output.getvalue() == "No tasks for glider pelagia exist in {0}.\\n". \\ + ... format(os.path.abspath(cfg)) + True + >>> output.close() + + Regular configuration file: + + >>> import shutil + >>> shutil.copy2(cfg + ".test", cfg) + >>> sys.argv = ["python", + ... cfg, + ... "Salacia",] + >>> _main() + alert + bearing + track + + """ + num_args = len(sys.argv) - 1 if num_args != 2: @@ -61,2 +184,5 @@ finally: lock.release() + +if __name__ == "__main__": + _main() Index: autopilot/trunk/autopilot/tests/etc/autopilot.cfg.test =================================================================== --- autopilot/trunk/autopilot/tests/etc/autopilot.cfg.test (revision 77) +++ autopilot/trunk/autopilot/tests/etc/autopilot.cfg.test (revision 90) @@ -2,5 +2,7 @@ [pelagia] +tasks = [salacia] +tasks = alert bearing track