def test_begin_with_stdout_parser(self): class TestParser(Base): def __init__(self): super(TestParser, self).__init__(self.__parse) def __parse(self, data=None): pass streams = Streams(TestParser(), Stdout) stdout, stderr = streams.begin() self.assertTrue(isinstance(stdout, (int, long))) self.assertEqual(stderr, subprocess.STDOUT)
def test_begin_different_parsers(self): class TestParser(Base): def __init__(self): super(TestParser, self).__init__(self.__parse) def __parse(self, data=None): pass streams = Streams(TestParser(), TestParser()) stdout, stderr = streams.begin() self.assertTrue(isinstance(stdout, (int, long))) self.assertTrue(isinstance(stderr, (int, long))) self.assertNotEqual(stdout, stderr)
def test_process_all_descriptors(self): streams = Streams() streams.begin() def descriptors(): return streams._Streams__descriptors streams._Streams__wait_for_descriptors = descriptors streams.process()
class Runner(object): def __init__(self, stdout=Null, stderr=Stdout, environment=None): self.__environment = dict(environment) if environment else {} self.__streams = Streams(stdout, stderr) def run(self, command): try: stdout, stderr = self.__streams.begin() process = subprocess.Popen(command, stdout=stdout, stderr=stderr, env=self.__environment) while True: self.__streams.process() if process.poll() is not None: self.__streams.finalize() return process.returncode finally: self.__streams.clean()
def test_process(self): streams = Streams() streams.begin() streams.process()
def test_clean(self): streams = Streams() streams.begin() streams.clean()
def test_begin(self): streams = Streams() stdout, stderr = streams.begin() self.assertTrue(isinstance(stdout, (int, long))) self.assertEqual(stderr, subprocess.STDOUT)
def test_creation(self): Streams()
def __init__(self, stdout=Null, stderr=Stdout, environment=None): self.__environment = dict(environment) if environment else {} self.__streams = Streams(stdout, stderr)