#!/usr/bin/env python

"""Test output of various incantations of example.sh

"""

import unittest
from subprocess import check_output
from textwrap import dedent


def run(*args):
    return check_output(['./example.sh'] + list(args),
                        universal_newlines=True).strip()


def strip(val):
    return dedent(val).strip()


class TestEverything(unittest.TestCase):

    def test01(self):
        output = run('infile', 'outfile')

        expected = strip("""
        required infile: infile
        required outfile: outfile
        the answer: 42
        do the thing? no, do not do it
        arg with multiple values: []
        """)

        self.assertEqual(output, expected)

    def test02(self):
        output = run('infile', 'outfile', '-m', 'one fish', 'two fish')
        self.assertIn('arg with multiple values: [one fish] [two fish]', output)

    def test03(self):
        output = run('infile', 'outfile', '-d')
        self.assertIn('yes, do it', output)

    def test04(self):
        output = run('infile', 'outfile', '-a', '0')
        self.assertIn('the answer: 0', output)


if __name__ == '__main__':
    unittest.main()

@@ -91,20 +91,22 @@
 nittest%0A
-from
+import
  subproc
@@ -112,28 +112,8 @@
 cess
- import check_output
 %0Afro
@@ -163,28 +163,14 @@
     
-return check_output(
+cmd = 
 %5B'./
@@ -198,66 +198,291 @@
 rgs)
-,
 %0A    
-                    universal_newlines=True).strip()
+if hasattr(subprocess, 'check_output'):%0A        # python 2.7+%0A        output = subprocess.check_output(cmd, universal_newlines=True).strip()%0A    else:%0A        # python 2.6%0A        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()%5B0%5D.strip()%0A%0A    return output
 %0A%0A%0Ad

replace subprocess.check_output with subprocess.Popen in python2.6