Nir Soffer has uploaded a new change for review. Change subject: tests: Use multiple context expressions ......................................................................
tests: Use multiple context expressions Since Python 2.7, multiple context expressions are supported in with statement, eliminating the need for nesting or using the deprecated nested() helper. This patch simplify with usage the DirectFile tests. See https://docs.python.org/2/reference/compound_stmts.html#the-with-statement Change-Id: I84a41c2de29715fa253d0c9af9a8d257e79f36dd Signed-off-by: Nir Soffer <[email protected]> --- M tests/fileUtilTests.py 1 file changed, 16 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/76/54676/1 diff --git a/tests/fileUtilTests.py b/tests/fileUtilTests.py index add36c2..310b6e9 100644 --- a/tests/fileUtilTests.py +++ b/tests/fileUtilTests.py @@ -37,10 +37,9 @@ platea lacus morbi nisl montes ve. Ac. A, consectetuer erat, justo eu. Elementum et, phasellus fames et rutrum donec magnis eu bibendum. Arcu, ante aliquam ipsum ut facilisis ad.""" - with temporaryPath(data=data) as srcPath: - # two nested withs to be py2.6 friendly. - with fileUtils.open_ex(srcPath, "dr") as f: - self.assertEquals(f.read(), data) + with temporaryPath(data=data) as srcPath, \ + fileUtils.open_ex(srcPath, "dr") as f: + self.assertEquals(f.read(), data) def testSeekRead(self): data = """ @@ -60,20 +59,18 @@ quam. """ self.assertTrue(len(data) > 512) - with temporaryPath(data=data) as srcPath: - # two nested withs to be py2.6 friendly. - with fileUtils.open_ex(srcPath, "dr") as f: - f.seek(512) - self.assertEquals(f.read(), data[512:]) + with temporaryPath(data=data) as srcPath, \ + fileUtils.open_ex(srcPath, "dr") as f: + f.seek(512) + self.assertEquals(f.read(), data[512:]) def testWrite(self): data = """In ut non platea egestas, quisque magnis nunc nostra ac etiam suscipit nec integer sociosqu. Fermentum. Ante orci luctus, ipsum ullamcorper enim arcu class neque inceptos class. Ut, sagittis torquent, commodo facilisi.""" - with temporaryPath() as srcPath: - with fileUtils.open_ex(srcPath, "dw") as f: - f.write(data) + with temporaryPath() as srcPath, fileUtils.open_ex(srcPath, "dw") as f: + f.write(data) with fileUtils.open_ex(srcPath, "r") as f: self.assertEquals(f.read(len(data)), data) @@ -100,10 +97,10 @@ """ self.assertTrue(len(data) > 512) - with temporaryPath() as srcPath: - with fileUtils.open_ex(srcPath, "dw") as f: - f.write(data[:512]) - f.write(data[512:]) + with temporaryPath() as srcPath, \ + fileUtils.open_ex(srcPath, "dw") as f: + f.write(data[:512]) + f.write(data[512:]) with fileUtils.open_ex(srcPath, "r") as f: self.assertEquals(f.read(len(data)), data) @@ -126,9 +123,9 @@ """ self.assertTrue(len(data) > 512) - with temporaryPath() as srcPath: - with fileUtils.open_ex(srcPath, "wd") as f: - f.write(data[:512]) + with temporaryPath() as srcPath, \ + fileUtils.open_ex(srcPath, "wd") as f: + f.write(data[:512]) with fileUtils.open_ex(srcPath, "r+d") as f: f.seek(512) -- To view, visit https://gerrit.ovirt.org/54676 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I84a41c2de29715fa253d0c9af9a8d257e79f36dd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Nir Soffer <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
