Nir Soffer has uploaded a new change for review.

Change subject: tests: refactor remoteFileHandler truncateFile tests
......................................................................

tests: refactor remoteFileHandler truncateFile tests

Old test was too big, causing one test to fail if the other failed. Now
there are 2 separated tests, sharing setup, teardown and check methods.

Additionally, creation of test file is more correct, and code is
hopefully more readable.

Change-Id: I0c23482e5d25651dc6090c7acfaa0ae221a562fe
Signed-off-by: Nir Soffer <nsof...@redhat.com>
---
M tests/remoteFileHandlerTests.py
1 file changed, 26 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/20084/1

diff --git a/tests/remoteFileHandlerTests.py b/tests/remoteFileHandlerTests.py
index a2ca574..0eeca3a 100644
--- a/tests/remoteFileHandlerTests.py
+++ b/tests/remoteFileHandlerTests.py
@@ -73,27 +73,32 @@
         utils.retry(test, AssertionError, timeout=4, sleep=0.1)
 
 
-class RemoteFileHandlerFunctionTests(TestCaseBase):
-    def testTruncateFile(self):
-        fd, path = tempfile.mkstemp()
+class RemoteFileHandlerTruncateTests(TestCaseBase):
+
+    def setUp(self):
+        fd, self.path = tempfile.mkstemp(self.__class__.__name__)
         try:
             os.write(fd, string.ascii_uppercase)
-            os.close(fd)
-
-            # Verifying content
-            data = string.ascii_uppercase
-            self.assertEquals(data, file(path).read())
-
-            # Testing truncate to a larger size
-            data = string.ascii_uppercase + chr(0) * 16
-
-            rhandler.truncateFile(path, len(data))
-            self.assertEquals(data, file(path).read())
-
-            # Testing truncate to a smaller size
-            data = string.ascii_uppercase
-
-            rhandler.truncateFile(path, len(data))
-            self.assertEquals(data, file(path).read())
+            os.fsync(fd)
         finally:
-            os.unlink(path)
+            os.close(fd)
+        self.checkData(string.ascii_uppercase)
+
+    def tearDown(self):
+        os.unlink(self.path)
+
+    def testEnlarge(self):
+        data = string.ascii_uppercase + '\0' * 16
+        rhandler.truncateFile(self.path, len(data))
+        self.checkData(data)
+
+    def testShrink(self):
+        data = string.ascii_uppercase[:10]
+        rhandler.truncateFile(self.path, len(data))
+        self.checkData(data)
+
+    def checkData(self, expected):
+        actual = open(self.path).read()
+        print '%r == %r' % (expected, actual)
+        self.assertEquals(expected, actual)
+


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c23482e5d25651dc6090c7acfaa0ae221a562fe
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsof...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to