Skip to content

Commit

Permalink
Minor fixes to Python 3 support. All tests now pass, but that does no…
Browse files Browse the repository at this point in the history
…t mean pbs is currently python 3 enabled.
  • Loading branch information
Dusty Phillips committed Feb 25, 2012
1 parent 2274bdd commit 171caf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 9 additions & 5 deletions pbs.py
Expand Up @@ -38,8 +38,12 @@
__project_url__ = "https://github.com/amoffat/pbs"

IS_PY3 = sys.version_info[0] == 3
if IS_PY3: raw_input = input

if IS_PY3:
import io
raw_input = input
is_file = lambda fd: isinstance(fd, io.IOBase)
else:
is_file = lambda fd: isinstance(fd, file)



Expand Down Expand Up @@ -310,7 +314,7 @@ def _compile_args(self, args, kwargs):
processed_args.append(arg)

try: processed_args = shlex.split(" ".join(processed_args))
except ValueError, e:
except ValueError as e:
if str(e) == "No closing quotation":
exc_msg = """No closing quotation. If you're trying to escape \
double quotes, please note that you need to escape the escape:
Expand Down Expand Up @@ -427,14 +431,14 @@ def __call__(self, *args, **kwargs):
stdout = pipe
out = call_args["out"]
if out:
if isinstance(out, file): stdout = out
if is_file(out): stdout = out
else: stdout = file(str(out), "w")

# stderr redirection
stderr = pipe
err = call_args["err"]
if err:
if isinstance(err, file): stderr = err
if is_file(err): stderr = err
else: stderr = file(str(err), "w")

if call_args["err_to_out"]: stderr = subp.STDOUT
Expand Down
8 changes: 6 additions & 2 deletions test.py
@@ -1,6 +1,10 @@
import os
import unittest
import sys

IS_PY3 = sys.version_info[0] == 3
if IS_PY3:
unicode = str

requires_posix = unittest.skipUnless(os.name == "posix", "Requires POSIX")

Expand Down Expand Up @@ -93,15 +97,15 @@ def test_with_context(self):
from pbs import time, ls
with time:
out = ls().stderr
self.assertTrue("pagefaults" in out)
self.assertTrue("pagefaults" in str(out))


@requires_posix
def test_with_context_args(self):
from pbs import time, ls
with time(verbose=True, _with=True):
out = ls().stderr
self.assertTrue("Voluntary context switches" in out)
self.assertTrue("Voluntary context switches" in str(out))


@requires_posix
Expand Down

0 comments on commit 171caf2

Please sign in to comment.