Nir Soffer has posted comments on this change.
Change subject: utils: add CommandStream class ......................................................................
Patch Set 7:
(2 comments)
https://gerrit.ovirt.org/#/c/33909/7/tests/utilsTests.py File tests/utilsTests.py:
Line 770: Line 771: def _startCommand(self, command): Line 772: return cpopen.CPopen(command) Line 773: Line 774: @permutations((('stdout',), ('stderr',))) Lets put the command and cb spec here:
@permutations([ # command, recv_out, recv_err (["echo", "-n", "%s"], True, False), (["sh", "-c", 'echo -n "%s" >&2'], False, True), ]) def test_receive(self, cmd, recv_out, recv_err):
So the code is more generic, and we don't need error handling for unsupported output:
cmd[-1] = cmd[-1] % text
c = self._startCommand(cmd)
p = utils.CommandStream(c, recv_data if recv_out else self.assertUnexpectedCall, recv_data if recv_err else self.assertUnexpectedCall)
And later we can easily add more tests, for example, receiving multiple lines, large amount of data, no data, without changing the code. Line 775: def test_receive(self, output): Line 776: text = bytes("Hello World") Line 777: received = bytearray() Line 778:
Line 797: Line 798: self.assertEqual(retcode, 0) Line 799: self.assertEqual(text, received) Line 800: Line 801: @permutations((('stdout',), ('stderr',))) Same as for test_receive Line 802: def test_write(self, output): Line 803: text = "Hello World" Line 804: received = bytearray() Line 805: