Nir Soffer has posted comments on this change.
Change subject: utils: add CommandStream class ......................................................................
Patch Set 7:
(4 comments)
https://gerrit.ovirt.org/#/c/33909/7/tests/utilsTests.py File tests/utilsTests.py:
Line 754: @expandPermutations Line 755: class CommandStreamTests(TestCaseBase): Line 756: Line 757: @contextlib.contextmanager Line 758: def assertElapsed(self, expected, tolerance=0.5): This seems like a general utility that should be in testlib. Line 759: start = utils.monotonic_time() Line 760: Line 761: yield Line 762:
Line 773: Line 774: @permutations((('stdout',), ('stderr',))) Line 775: def test_receive(self, output): Line 776: text = bytes("Hello World") Line 777: received = bytearray() We can use
received = [bytearray()]
or
self.received = bytearray() Line 778: Line 779: def recv_stdout(buffer): Line 780: # cannot use received += buffer with a variable Line 781: # defined in the parent function.
Line 775: def test_receive(self, output): Line 776: text = bytes("Hello World") Line 777: received = bytearray() Line 778: Line 779: def recv_stdout(buffer): This should be now recv_data - can come from stderr in the stderr permutation. Line 780: # cannot use received += buffer with a variable Line 781: # defined in the parent function. Line 782: operator.iadd(received, buffer) Line 783:
Line 778: Line 779: def recv_stdout(buffer): Line 780: # cannot use received += buffer with a variable Line 781: # defined in the parent function. Line 782: operator.iadd(received, buffer) But we can use received[0] += buffer, or self.received += bufffer Line 783: Line 784: if output == 'stdout': Line 785: c = self._startCommand(["echo", "-n", text]) Line 786: p = utils.CommandStream(c, recv_stdout, self.assertUnexpectedCall)