Skip to content
This repository
Browse code

Test command line wrapper handling of stdout/stderr

  • Loading branch information...
commit 3f5d4c442424a7ca33ae0bafa60c840e80ae2fda 1 parent 38b366a
Peter Cock authored March 28, 2013

Showing 1 changed file with 64 additions and 0 deletions. Show diff stats Hide diff stats

  1. 64  Tests/test_Application.py
64  Tests/test_Application.py
... ...
@@ -0,0 +1,64 @@
  1
+# Copyright 2013 by Peter Cock.  All rights reserved.
  2
+# This code is part of the Biopython distribution and governed by its
  3
+# license.  Please see the LICENSE file that should have been included
  4
+# as part of this package.
  5
+
  6
+"""Bio.Application related tests for command line application wrappers.
  7
+
  8
+This is intended to check generic things like argument parsing, and
  9
+stdin/stdout/stderr handling.
  10
+"""
  11
+
  12
+import os
  13
+import unittest
  14
+
  15
+from Bio.Application import AbstractCommandline, _Argument
  16
+
  17
+class EchoApp(AbstractCommandline):
  18
+    def __init__(self, cmd="echo", **kwargs):
  19
+        self.parameters = [_Argument(["text"], "Text to echo")]
  20
+        AbstractCommandline.__init__(self, cmd, **kwargs)
  21
+
  22
+class TestApp(unittest.TestCase):
  23
+    def test_echo(self):
  24
+        cline = EchoApp(text="Hello World")
  25
+        stdout, stderr = cline()
  26
+        self.assertEqual(stderr, "")
  27
+        self.assertEqual(stdout, "Hello World\n")
  28
+
  29
+    def test_echo_capture_both(self):
  30
+        cline = EchoApp(text="Hello World")
  31
+        stdout, stderr = cline(stdout=True, stderr=True)
  32
+        self.assertEqual(stderr, "")
  33
+        self.assertEqual(stdout, "Hello World\n")
  34
+
  35
+    def test_echo_capture_stdout(self):
  36
+        cline = EchoApp(text="Hello World")
  37
+        stdout, stderr = cline(stdout=True, stderr=False)
  38
+        self.assertEqual(stderr, None)
  39
+        self.assertEqual(stdout, "Hello World\n")
  40
+
  41
+    #Same failure on Linux, Mac OS X:
  42
+    # ApplicationError: Command 'echo Hello World' returned non-zero exit status 1,
  43
+    # '/bin/sh: line 0: echo: write error: Bad file descriptor'
  44
+    #And on Windows XP (with cygwin):
  45
+    # ApplicationError: Command 'echo Hello World' returned non-zero exit status 1,
  46
+    # 'echo: write error: Bad file descriptor' 
  47
+    #def test_echo_capture_stderr(self):
  48
+    #    cline = EchoApp(text="Hello World")
  49
+    #    stdout, stderr = cline(stdout=False, stderr=True)
  50
+    #    self.assertEqual(stderr, "")
  51
+    #    self.assertEqual(stdout, None)
  52
+
  53
+    #Same failure on Linux, Mac OS X, and Windows XP (with cygwin):
  54
+    # ApplicationError: Command 'echo Hello World' returned non-zero exit status 1
  55
+    #def test_echo_capture_neither(self):
  56
+    #    cline = EchoApp(text="Hello World")
  57
+    #    stdout, stderr = cline(stdout=False, stderr=False)
  58
+    #    self.assertEqual(stderr, None)
  59
+    #    self.assertEqual(stdout, None)
  60
+
  61
+
  62
+if __name__ == "__main__":
  63
+    runner = unittest.TextTestRunner(verbosity = 2)
  64
+    unittest.main(testRunner=runner)

0 notes on commit 3f5d4c4

Please sign in to comment.
Something went wrong with that request. Please try again.