Skip to content

Commit

Permalink
Merge 1bfe8d7 into 85fd6a4
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzundel committed Apr 22, 2015
2 parents 85fd6a4 + 1bfe8d7 commit d402fe9
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions tests/python/pants_test/base/context_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io
import logging
import os
import sys
from contextlib import contextmanager

from twitter.common.collections import maybe_list
Expand Down Expand Up @@ -72,23 +73,25 @@ class TestContext(Context):
isolate the parts of the interface that a Task is allowed to use vs. the parts that the
task-running machinery is allowed to use.
"""
class DummyWorkunit(object):
"""A workunit stand-in that sends all output to /dev/null.
class StderrWorkunit(object):
"""A workunit stand-in that sends all output to stderr
These outputs are typically only used by subprocesses spawned by code under test, not
the code under test itself, and would otherwise go into some reporting black hole anyway.
These outputs are typically only used by subprocesses spawned by code under test, not
the code under test itself, and would otherwise go into some reporting black hole. The
testing framework will only display the stderr output when a test fails.
Provides no other tracking/labeling/reporting functionality. Does not require "opening"
or "closing".
"""
def __init__(self, devnull):
self._devnull = devnull
Provides no other tracking/labeling/reporting functionality. Does not require "opening"
or "closing".
"""
def __init__(self):
self._stderr = sys.stderr

def output(self, name):
return self._devnull
return self._stderr

def set_outcome(self, outcome):
pass
return self._stderr.write('Outcome: {}'.format(outcome))


def __init__(self, options, target_roots, build_graph=None, build_file_parser=None,
address_mapper=None, console_outstream=None, workspace=None):
Expand All @@ -99,15 +102,10 @@ def __init__(self, options, target_roots, build_graph=None, build_file_parser=No
super(TestContext, self).__init__(config=empty_config, options=options, run_tracker=None,
target_roots=target_roots, build_graph=build_graph, build_file_parser=build_file_parser,
address_mapper=address_mapper, console_outstream=console_outstream, workspace=workspace)
try:
from subprocess import DEVNULL # Python 3.
except ImportError:
DEVNULL = open(os.devnull, 'wb')
self._devnull = DEVNULL

@contextmanager
def new_workunit(self, name, labels=None, cmd=''):
yield TestContext.DummyWorkunit(self._devnull)
yield TestContext.StderrWorkunit()

@property
def log(self):
Expand Down

0 comments on commit d402fe9

Please sign in to comment.