Use logger where unit test has coverage

Change-Id: I0a4d16fef3aed6bba0c6015fe861a2f11558e11b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2029114
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Anthony Polito <apolito@google.com>
diff --git a/git_cl.py b/git_cl.py
index a8fa6e3..84f6d54 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -140,9 +140,8 @@
 def SaveDescriptionBackup(change_desc):
   backup_path = os.path.join(DEPOT_TOOLS, DESCRIPTION_BACKUP_FILE)
   print('\nsaving CL description to %s\n' % backup_path)
-  backup_file = open(backup_path, 'w')
-  backup_file.write(change_desc.description)
-  backup_file.close()
+  with open(backup_path, 'w') as backup_file:
+    backup_file.write(change_desc.description)
 
 
 def GetNoGitPagerEnv():
@@ -862,6 +861,7 @@
       cr_settings_file = FindCodereviewSettingsFile()
       if autoupdate != 'false' and cr_settings_file:
         LoadCodereviewSettingsFromFile(cr_settings_file)
+        cr_settings_file.close()
       self.updated = True
 
   @staticmethod
@@ -1344,8 +1344,9 @@
                     'Interpreting it as a local directory.', url)
     if not os.path.isdir(url):
       logging.error(
-          'Remote "%s" for branch "%s" points to "%s", but it doesn\'t exist.',
-          remote, self.GetBranch(), url)
+          'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
+          'but it doesn\'t exist.',
+          {'remote': remote, 'branch': self.GetBranch(), 'url': url})
       return None
 
     cache_path = url
@@ -1703,7 +1704,7 @@
     """Returns Gerrit project name based on remote git URL."""
     remote_url = self.GetRemoteUrl()
     if remote_url is None:
-      logging.warn('can\'t detect Gerrit project.')
+      logging.warning('can\'t detect Gerrit project.')
       return None
     project = urllib.parse.urlparse(remote_url).path.strip('/')
     if project.endswith('.git'):
@@ -1756,11 +1757,14 @@
 
     remote_url = self.GetRemoteUrl()
     if remote_url is None:
-      print('WARNING: invalid remote')
+      logging.warning('invalid remote')
       return
     if urllib.parse.urlparse(remote_url).scheme != 'https':
-      print('WARNING: Ignoring branch %s with non-https remote %s' %
-            (self.branch, self.GetRemoteUrl()))
+      logging.warning('Ignoring branch %(branch)s with non-https remote '
+                      '%(remote)s', {
+                          'branch': self.branch,
+                          'remote': self.GetRemoteUrl()
+                      })
       return
 
     # Lazy-loader to identify Gerrit and Git hosts.