Francesco Romani has uploaded a new change for review.

Change subject: tests: split SampleWindow tests
......................................................................

tests: split SampleWindow tests

Reorganize and rationalize the unit tests after
the introduction of SampleWindow class.

Change-Id: I74f0005eae5466e083002f0d871bcf1fbec54fef
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M tests/samplingTests.py
1 file changed, 32 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/12/34512/1

diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index a58e06b..31b0011 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -27,6 +27,7 @@
 from vdsm import ipwrapper
 import virt.sampling as sampling
 
+from testlib import permutations, expandPermutations
 from testlib import VdsmTestCase as TestCaseBase
 from monkeypatch import MonkeyPatchScope
 
@@ -115,23 +116,39 @@
         self.assertEquals('operstate:x', s1.connlog_diff(s0))
 
 
+@expandPermutations
+class SampleWindowTests(TestCaseBase):
+    @permutations([[-1], [0]])
+    def test_window_size_bad_values(self, size):
+        self.assertRaises(
+            ValueError,
+            sampling.SampleWindow, size)
+
+    def test_last(self):
+        value = 42
+        win = sampling.SampleWindow(size=2)
+        win.append(value)
+        self.assertEqual(value, win.last())
+
+    def test_stats(self):
+        step = 1
+        counter = itertools.count(0, step)
+        win = sampling.SampleWindow(
+            size=2, timefn=lambda: next(counter))
+        # random values, no meaning
+        first, last = 42, 19
+        win.append(first)
+        win.append(last)
+        self.assertEqual(win.stats(), (first, last, step))
+
+
+@expandPermutations
 class AdvancedStatsFunctionTests(TestCaseBase):
-    def testIntervalBadValues(self):
+    @permutations([[None], [-1], [0], [1.333], ['foo']])
+    def testIntervalBadValues(self, interval):
         self.assertRaises(
             ValueError,
-            sampling.AdvancedStatsFunction, random.randint, 0)
-        self.assertRaises(
-            ValueError,
-            sampling.AdvancedStatsFunction, random.randint, -1)
-        self.assertRaises(
-            ValueError,
-            sampling.AdvancedStatsFunction, random.randint, None)
-        self.assertRaises(
-            ValueError,
-            sampling.AdvancedStatsFunction, random.randint, 1.333)
-        self.assertRaises(
-            ValueError,
-            sampling.AdvancedStatsFunction, random.randint, 'foo')
+            sampling.AdvancedStatsFunction, lambda x: x, interval)
 
     def testIntervalGoodValue(self):
         interval = 42
@@ -152,7 +169,7 @@
         self.assertEqual(stat.getStats(), (None, None, None))
         self.assertEqual(stat.getLastSample(), value)
 
-    def testWindowSizeTwo(self):
+    def testGetStats(self):
         values = range(42)
         stat = sampling.AdvancedStatsFunction(
             lambda x: x, interval=1, window=2)


-- 
To view, visit http://gerrit.ovirt.org/34512
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74f0005eae5466e083002f0d871bcf1fbec54fef
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

Reply via email to