Fix crash in PRESUBMIT.py when moving dirs.

If you deleted or moved a directory containing a PRESUBMIT.py file,
then the presubmit checks would crash trying to run tests in a
directory that no longer existed.

[email protected]
BUG=834077

Change-Id: I8deb59c2d00b80f6b5215597076bba34ff1f0872
Reviewed-on: https://chromium-review.googlesource.com/1015976
Reviewed-by: Aaron Gable <[email protected]>
Commit-Queue: Dirk Pranke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#551542}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index ad5dfe7..a34c03e6 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -2824,9 +2824,13 @@
     path, name = input_api.os_path.split(f.LocalPath())
     if name == 'PRESUBMIT.py':
       full_path = input_api.os_path.join(input_api.PresubmitLocalPath(), path)
-      results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
-          input_api, output_api, full_path,
-          whitelist=[r'^PRESUBMIT_test\.py$']))
+      if f.Action() != 'D':
+        # The PRESUBMIT.py file (and the directory containing it) might
+        # have been affected by being moved or removed, so only try to
+        # run the tests if they still exist.
+        results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
+            input_api, output_api, full_path,
+            whitelist=[r'^PRESUBMIT_test\.py$']))
   return results