from __future__ import print_function
import sys
import os
from os.path import realpath, dirname

try:
    import command
except ImportError:
    print('Unable to import command.  Is it installed?')
    sys.exit(1)

try:
    import py.test
except ImportError:
    print('Unable to import py.test.  Is py.test installed?')
    sys.exit(1)

# figure out the base path to use for file include
test_path = realpath(dirname(__file__))

class TestCommand:
    def test_which_bin_sleep(self):
        command.which('/bin/sleep')

    def test_which_bin_sleep2(self):
        assert command.which('sleep') == '/bin/sleep'


    def test_which_foo(self):
        with py.test.raises(command.CommandException):
            command.which('foo')

    def test_which_full_foo(self):
        with py.test.raises(command.CommandException):
            command.which('/bin/foo')

    def test_which_not_x(self):
        with py.test.raises(command.CommandException):
            command.which('/etc/hosts')

    def test_which_relative_false(self):
        command.which('false')

    def test_which_none(self):
        with py.test.raises(command.CommandException):
            command.which(None)

    def test_run_ls(self):
        response = command.run(['ls', test_path])
        assert response.exit == 0
        assert response.output == """\
__pycache__
test_command.py"""

    def test_run_failure(self):
        with py.test.raises(command.CommandException):
            command.run(['ls', 'blahblah'])

    def test_run_timeout_successs(self):
        command.run(['sleep', '1'], timeout=10)

    def test_run_timeout_failure(self):
        with py.test.raises(command.CommandException):
            command.run(['sleep', '2'], timeout=1)

    def test_run_debug(self, capsys):
        def debug_print(line):
            print(line)

        response = command.run(['ls', test_path], debug=debug_print)
        out, err = capsys.readouterr()

        assert response.exit == 0
        assert response.output == """\
__pycache__
test_command.py"""
        assert out == """\
__pycache__
test_command.py
"""
        assert err == ''
@@ -1314,32 +1314,33 @@
 ponse.output == 
+b
 %22%22%22%5C%0A__pycache__
@@ -1996,24 +1996,25 @@
 e.output == 
+b
 %22%22%22%5C%0A__pycac
@@ -2033,24 +2033,126 @@
 mmand.py%22%22%22%0A
+%0A        # Pyton 2 vs 3 handles strings in different ways%0A        if sys.version_info.major is 2:%0A    
         asse
@@ -2161,16 +2161,17 @@
  out == 
+b
 %22%22%22%5C%0A__p
@@ -2199,16 +2199,124 @@
 .py%0A%22%22%22%0A
+        elif sys.version_info.major is 3:%0A            assert out == %22b'__pycache__'%5Cnb'test_command.py'%5Cn%22%0A%0A
         

Handle the differences in how Python 2 vs 3 handle outputting strings