Fix git cl on windows for git-numberer repos.

Git cl decides if git-numberer is enabled on a repository by writing
Gerrit's project.config from refs/meta/config into a tempfile, which is
then queried using `git config -f tempfile --get ...`.  The file itself
is only flushed, but not closed after writing because Python's
tempfile.NamedTemporaryFile is deleted on closing. This worked fine on
Linix/Mac, but not on Windows, where `git config` apparently doesn't see
file or its contents.

This CL rewrites the above using yet another contexmanager temp
directory into which a file is written and closed before git config is
ran.

R=machenbach@chromium.org,grt@chromium.org
BUG=683202

Change-Id: I7974d66b1b2b0478ab4b6f7ac04e547a4981c46c
Reviewed-on: https://chromium-review.googlesource.com/430719
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: Vadim Shtayura <vadimsh@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 3a0acc1..2800e3f 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -1102,13 +1102,15 @@
     self.assertEqual(res.should_add_git_number, False)
 
   def test_GitNumbererState_valid_configs(self):
-    class NamedTempFileStab(StringIO.StringIO):
-      @classmethod
+    with git_cl.gclient_utils.temporary_directory() as tempdir:
       @contextlib.contextmanager
-      def create(cls, *_, **__):
-        yield cls()
-      name = 'tempfile'
-    self.mock(git_cl.tempfile, 'NamedTemporaryFile', NamedTempFileStab.create)
+      def fake_temporary_directory(**kwargs):
+        yield tempdir
+      self.mock(git_cl.gclient_utils, 'temporary_directory',
+                fake_temporary_directory)
+      self._test_GitNumbererState_valid_configs_inner(tempdir)
+
+  def _test_GitNumbererState_valid_configs_inner(self, tempdir):
     self.calls = [
         ((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src',
            '+refs/meta/config:refs/git_cl/meta/config',
@@ -1130,12 +1132,12 @@
             validate-disabled-refglob = refs/heads/disabled
             validate-disabled-refglob = refs/branch-heads/*
          '''),
-        ((['git', 'config', '-f', 'tempfile', '--get-all',
-           'plugin.git-numberer.validate-enabled-refglob'],),
+        ((['git', 'config', '-f', os.path.join(tempdir, 'project.config') ,
+           '--get-all', 'plugin.git-numberer.validate-enabled-refglob'],),
          'refs/else/*\n'
          'refs/heads/*\n'),
-        ((['git', 'config', '-f', 'tempfile', '--get-all',
-           'plugin.git-numberer.validate-disabled-refglob'],),
+        ((['git', 'config', '-f', os.path.join(tempdir, 'project.config') ,
+           '--get-all', 'plugin.git-numberer.validate-disabled-refglob'],),
          'refs/heads/disabled\n'
          'refs/branch-heads/*\n'),
     ] * 4  # 4 tests below have exactly same IO.