URL: https://github.com/freeipa/freeipa/pull/676
Author: Akasurde
 Title: #676: Use with statement for opening file
Action: opened

PR body:
"""
Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/676/head:pr676
git checkout pr676
From c3bfbd34c8383aadc05b6976e54c9a033b67dc8a Mon Sep 17 00:00:00 2001
From: Abhijeet Kasurde <akasu...@redhat.com>
Date: Thu, 30 Mar 2017 13:21:04 +0530
Subject: [PATCH] Use with statement for opening file

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
---
 ipatests/test_ipaserver/test_ldap.py     | 10 ++++------
 ipatests/test_pkcs10/test_pkcs10.py      |  5 ++---
 ipatests/test_xmlrpc/test_cert_plugin.py | 10 ++++------
 3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/ipatests/test_ipaserver/test_ldap.py b/ipatests/test_ipaserver/test_ldap.py
index e7ba867..d409efb 100644
--- a/ipatests/test_ipaserver/test_ldap.py
+++ b/ipatests/test_ipaserver/test_ldap.py
@@ -88,9 +88,8 @@ def test_simple(self):
         """
         pwfile = api.env.dot_ipa + os.sep + ".dmpw"
         if ipautil.file_exists(pwfile):
-            fp = open(pwfile, "r")
-            dm_password = fp.read().rstrip()
-            fp.close()
+            with open(pwfile, "r") as fp:
+                dm_password = fp.read().rstrip()
         else:
             raise nose.SkipTest("No directory manager password in %s" % pwfile)
         self.conn = ldap2(api, ldap_uri=self.ldapuri)
@@ -115,9 +114,8 @@ def test_Backend(self):
 
         pwfile = api.env.dot_ipa + os.sep + ".dmpw"
         if ipautil.file_exists(pwfile):
-            fp = open(pwfile, "r")
-            dm_password = fp.read().rstrip()
-            fp.close()
+            with open(pwfile, "r") as fp:
+                dm_password = fp.read().rstrip()
         else:
             raise nose.SkipTest("No directory manager password in %s" % pwfile)
         myapi.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')), bind_pw=dm_password)
diff --git a/ipatests/test_pkcs10/test_pkcs10.py b/ipatests/test_pkcs10/test_pkcs10.py
index 850ed91..df50df0 100644
--- a/ipatests/test_pkcs10/test_pkcs10.py
+++ b/ipatests/test_pkcs10/test_pkcs10.py
@@ -41,9 +41,8 @@ def setup(self):
             raise nose.SkipTest("Unable to find test update files")
 
     def read_file(self, filename):
-        fp = open(os.path.join(self.testdir, filename), "r")
-        data = fp.read()
-        fp.close()
+        with open(os.path.join(self.testdir, filename), "r") as fp:
+            data = fp.read()
         return data
 
     def test_0(self):
diff --git a/ipatests/test_xmlrpc/test_cert_plugin.py b/ipatests/test_xmlrpc/test_cert_plugin.py
index 0b8277b..51c20b6 100644
--- a/ipatests/test_xmlrpc/test_cert_plugin.py
+++ b/ipatests/test_xmlrpc/test_cert_plugin.py
@@ -103,9 +103,8 @@ def setup(self):
         self.certfile = self.reqdir + "/cert.crt"
 
         # Create an empty password file
-        fp = open(self.pwname, "w")
-        fp.write("\n")
-        fp.close()
+        with open(self.pwname, "w") as fp:
+            fp.write("\n")
 
         # Create our temporary NSS database
         self.run_certutil(["-N", "-f", self.pwname])
@@ -122,9 +121,8 @@ def generateCSR(self, subject):
                            "-f", self.pwname,
                            "-a",
                            ])
-        fp = open(self.reqfile, "r")
-        data = fp.read()
-        fp.close()
+        with open(self.reqfile, "r") as fp:
+            data = fp.read()
         return data
 
     host_fqdn = u'ipatestcert.%s' % api.env.domain
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to