Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    def test_process_all_descriptors(self):
        streams = Streams()
        streams.begin()

        def descriptors():
            return streams._Streams__descriptors
        streams._Streams__wait_for_descriptors = descriptors

        streams.process()
Example #4
0
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()
Example #5
0
 def test_process(self):
     streams = Streams()
     streams.begin()
     streams.process()
Example #6
0
 def test_clean(self):
     streams = Streams()
     streams.begin()
     streams.clean()
Example #7
0
 def test_begin(self):
     streams = Streams()
     stdout, stderr = streams.begin()
     self.assertTrue(isinstance(stdout, (int, long)))
     self.assertEqual(stderr, subprocess.STDOUT)
Example #8
0
 def test_creation(self):
     Streams()
Example #9
0
    def __init__(self, stdout=Null, stderr=Stdout, environment=None):
        self.__environment = dict(environment) if environment else {}

        self.__streams = Streams(stdout, stderr)