19 | | if __name__ == "__main__": |
---|
| 19 | def _main(): |
---|
| 20 | """List all tasks for a glider in the configution file. |
---|
| 21 | |
---|
| 22 | These doctests require write permission to tests/etc. |
---|
| 23 | |
---|
| 24 | Missing configuration file: |
---|
| 25 | |
---|
| 26 | >>> from StringIO import StringIO |
---|
| 27 | >>> cfg = os.path.join(os.path.dirname(__file__), |
---|
| 28 | ... "tests", "etc", "autopilot.cfg") |
---|
| 29 | >>> try: |
---|
| 30 | ... os.remove(cfg) |
---|
| 31 | ... except: |
---|
| 32 | ... pass |
---|
| 33 | >>> sys.argv = ["python", |
---|
| 34 | ... cfg, |
---|
| 35 | ... "cthulhu",] |
---|
| 36 | >>> output = StringIO() |
---|
| 37 | >>> save = sys.stdout |
---|
| 38 | >>> sys.stdout = output |
---|
| 39 | >>> _main() |
---|
| 40 | >>> sys.stdout = save |
---|
| 41 | >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ |
---|
| 42 | ... format(os.path.abspath(cfg)) |
---|
| 43 | True |
---|
| 44 | >>> output.close() |
---|
| 45 | |
---|
| 46 | Empty configuration file: |
---|
| 47 | |
---|
| 48 | >>> from StringIO import StringIO |
---|
| 49 | >>> cfg = os.path.join(os.path.dirname(__file__), |
---|
| 50 | ... "tests", "etc", "autopilot.cfg") |
---|
| 51 | >>> try: |
---|
| 52 | ... os.remove(cfg) |
---|
| 53 | ... open(cfg, 'w').close() |
---|
| 54 | ... except: |
---|
| 55 | ... pass |
---|
| 56 | >>> sys.argv = ["python", |
---|
| 57 | ... cfg, |
---|
| 58 | ... "cthulhu",] |
---|
| 59 | >>> output = StringIO() |
---|
| 60 | >>> save = sys.stdout |
---|
| 61 | >>> sys.stdout = output |
---|
| 62 | >>> _main() |
---|
| 63 | >>> sys.stdout = save |
---|
| 64 | >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ |
---|
| 65 | ... format(os.path.abspath(cfg)) |
---|
| 66 | True |
---|
| 67 | >>> output.close() |
---|
| 68 | |
---|
| 69 | Configuration does not contain glider: |
---|
| 70 | |
---|
| 71 | >>> import shutil |
---|
| 72 | >>> from StringIO import StringIO |
---|
| 73 | >>> cfg = os.path.join(os.path.dirname(__file__), |
---|
| 74 | ... "tests", "etc", "autopilot.cfg") |
---|
| 75 | >>> shutil.copy2(cfg + ".test", cfg) |
---|
| 76 | >>> sys.argv = ["python", |
---|
| 77 | ... cfg, |
---|
| 78 | ... "Cthulhu"] |
---|
| 79 | >>> output = StringIO() |
---|
| 80 | >>> save = sys.stdout |
---|
| 81 | >>> sys.stdout = output |
---|
| 82 | >>> _main() |
---|
| 83 | >>> sys.stdout = save |
---|
| 84 | >>> output.getvalue() == "Glider cthulhu does not exist in {0}.\\n". \\ |
---|
| 85 | ... format(os.path.abspath(cfg)) |
---|
| 86 | True |
---|
| 87 | >>> output.close() |
---|
| 88 | |
---|
| 89 | Glider does not contain task list: |
---|
| 90 | |
---|
| 91 | >>> import shutil |
---|
| 92 | >>> from StringIO import StringIO |
---|
| 93 | >>> cfg = os.path.join(os.path.dirname(__file__), |
---|
| 94 | ... "tests", "etc", "autopilot.cfg") |
---|
| 95 | >>> shutil.copy2(cfg + ".test", cfg) |
---|
| 96 | >>> sys.argv = ["python", |
---|
| 97 | ... cfg, |
---|
| 98 | ... "Ramses"] |
---|
| 99 | >>> output = StringIO() |
---|
| 100 | >>> save = sys.stdout |
---|
| 101 | >>> sys.stdout = output |
---|
| 102 | >>> _main() |
---|
| 103 | >>> sys.stdout = save |
---|
| 104 | >>> output.getvalue() == "No tasks for glider ramses exist in {0}.\\n". \\ |
---|
| 105 | ... format(os.path.abspath(cfg)) |
---|
| 106 | True |
---|
| 107 | >>> output.close() |
---|
| 108 | |
---|
| 109 | Task list for glider is empty: |
---|
| 110 | |
---|
| 111 | >>> import shutil |
---|
| 112 | >>> from StringIO import StringIO |
---|
| 113 | >>> cfg = os.path.join(os.path.dirname(__file__), |
---|
| 114 | ... "tests", "etc", "autopilot.cfg") |
---|
| 115 | >>> shutil.copy2(cfg + ".test", cfg) |
---|
| 116 | >>> sys.argv = ["python", |
---|
| 117 | ... cfg, |
---|
| 118 | ... "Pelagia"] |
---|
| 119 | >>> output = StringIO() |
---|
| 120 | >>> save = sys.stdout |
---|
| 121 | >>> sys.stdout = output |
---|
| 122 | >>> _main() |
---|
| 123 | >>> sys.stdout = save |
---|
| 124 | >>> output.getvalue() == "No tasks for glider pelagia exist in {0}.\\n". \\ |
---|
| 125 | ... format(os.path.abspath(cfg)) |
---|
| 126 | True |
---|
| 127 | >>> output.close() |
---|
| 128 | |
---|
| 129 | Regular configuration file: |
---|
| 130 | |
---|
| 131 | >>> import shutil |
---|
| 132 | >>> shutil.copy2(cfg + ".test", cfg) |
---|
| 133 | >>> sys.argv = ["python", |
---|
| 134 | ... cfg, |
---|
| 135 | ... "Salacia",] |
---|
| 136 | >>> _main() |
---|
| 137 | alert |
---|
| 138 | bearing |
---|
| 139 | track |
---|
| 140 | |
---|
| 141 | """ |
---|
| 142 | |
---|