Francesco Romani has uploaded a new change for review. Change subject: tests: improve miscTests::ReadSpeed ......................................................................
tests: improve miscTests::ReadSpeed miscTests::ReadSpeed where meant to test the storage.misc.readspeed() function, but they where testing against an implementation detail, rather than the interface. This patch modifies the tests, using monkeypatching, to test against the interface, preparing the ground for more tests and for future patch to enhance the compatibility with the new dd output (coreutils >= 8.25.5). We also add few more test cases, taken from real environment and not made up. Change-Id: I5aef61848b0d237c2250fd8b8e6b4ee9ee88e299 Signed-off-by: Francesco Romani <from...@redhat.com> --- M tests/miscTests.py 1 file changed, 21 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/56159/1 diff --git a/tests/miscTests.py b/tests/miscTests.py index 74f5636..638326a 100644 --- a/tests/miscTests.py +++ b/tests/miscTests.py @@ -43,7 +43,7 @@ import storage.misc as misc import storage.fileUtils as fileUtils -from monkeypatch import MonkeyPatch +from monkeypatch import MonkeyPatch, MonkeyPatchScope from testValidation import checkSudo EXT_CHMOD = "/bin/chmod" @@ -844,6 +844,7 @@ class ReadSpeed(TestCaseBase): @permutations([ + # output line, bytes read, seconds ("1 byte (1 B) copied, 1 s, 1 B/s", "1", "1"), ("1024 bytes (1 kB) copied, 1 s, 1 kB/s", @@ -859,14 +860,27 @@ ("524288 bytes (512e3 B) copied, 1 s, 512e3 B/s", "524288", "1"), ("517 bytes (517 B) copied, 0 s, Infinity B/s", - "517", "0") + "517", "0"), + ("4096 bytes (4.1 kB) copied, 0.00135703 s, 3.0 MB/s", + "4096", "0.00135703"), + ("30 bytes (30 B) copied, 0.0033204 s, 9.0 kB/s", + "30", "0.0033204"), ]) - def testReadSpeedRegExp(self, output, bytes, seconds): - m = misc._readspeed_regex.match(output) - self.assertNotEqual(m, None) + def test_readspeed(self, output_line, bytes_read, seconds): + output = ( + "0+1 records in", + "0+1 records out", + output_line, + ) - self.assertEqual(m.group("bytes"), bytes) - self.assertEqual(m.group("seconds"), seconds) + def _fake_exec_cmd(*args): + return 0, None, output + + with MonkeyPatchScope([(misc, 'execCmd', _fake_exec_cmd)]): + speed = misc.readspeed('useless') + + self.assertEquals(speed["bytes"], int(bytes_read)) + self.assertAlmostEqual(speed["seconds"], float(seconds)) class PidExists(TestCaseBase): -- To view, visit https://gerrit.ovirt.org/56159 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5aef61848b0d237c2250fd8b8e6b4ee9ee88e299 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <from...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches