Add an assert to ensure UTF-8 locale when handling file paths.

- Switch many calls from shutil.rmtree() to file_path.rmtree().
- Add call to fix_encoding.fix_encoding() to fix the locale.

This was silently assumed and may cause problems when the path is not pure
ASCII.

R=vadimsh@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1390773002

Cr-Mirrored-From: https://github.com/luci/luci-py
Cr-Mirrored-Commit: d9a337e2fd5151eac24b3164963e086091d769a3
diff --git a/tests/file_path_test.py b/tests/file_path_test.py
index 7a69bbb..182e769 100755
--- a/tests/file_path_test.py
+++ b/tests/file_path_test.py
@@ -8,7 +8,6 @@
 import os
 import tempfile
 import unittest
-import shutil
 import StringIO
 import subprocess
 import sys
@@ -22,6 +21,7 @@
 FILE_PATH = unicode(os.path.abspath(__file__))
 
 from depot_tools import auto_stub
+from depot_tools import fix_encoding
 import test_utils
 from utils import file_path
 
@@ -37,14 +37,17 @@
     self._tempdir = None
 
   def tearDown(self):
-    if self._tempdir:
-      for dirpath, dirnames, filenames in os.walk(self._tempdir, topdown=True):
-        for filename in filenames:
-          file_path.set_read_only(os.path.join(dirpath, filename), False)
-        for dirname in dirnames:
-          file_path.set_read_only(os.path.join(dirpath, dirname), False)
-      shutil.rmtree(self._tempdir)
-    super(FilePathTest, self).tearDown()
+    try:
+      if self._tempdir:
+        for dirpath, dirnames, filenames in os.walk(
+            self._tempdir, topdown=True):
+          for filename in filenames:
+            file_path.set_read_only(os.path.join(dirpath, filename), False)
+          for dirname in dirnames:
+            file_path.set_read_only(os.path.join(dirpath, dirname), False)
+        file_path.rmtree(self._tempdir)
+    finally:
+      super(FilePathTest, self).tearDown()
 
   @property
   def tempdir(self):
@@ -250,7 +253,7 @@
         # you?
         self.assertEqual([basename], os.listdir(tempdir))
       finally:
-        shutil.rmtree(tempdir)
+        file_path.rmtree(tempdir)
 
     def test_rmtree_win(self):
       # Mock our sleep for faster test case execution.
@@ -355,6 +358,7 @@
 
 
 if __name__ == '__main__':
+  fix_encoding.fix_encoding()
   logging.basicConfig(
       level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
   if '-v' in sys.argv: