Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: PRESUBMIT_test.py

Issue 1846103005: Reland of Include isolate.py in data for Android unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: even more cautious Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | PRESUBMIT_test_mocks.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT_test.py
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 7c528c57175b599a02e401c0c2f7694b71d1cd6c..d2eb524df94888ea878bc33e8939dd49d209f91e 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -3,12 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import glob
-import json
-import os
import re
import subprocess
-import sys
import unittest
import PRESUBMIT
@@ -835,6 +831,103 @@ class UserMetricsActionTest(unittest.TestCase):
output[0].message)
+class PydepsNeedsUpdatingTest(unittest.TestCase):
+
+ class MockSubprocess(object):
+ CalledProcessError = subprocess.CalledProcessError
+
+ def setUp(self):
+ mock_all_pydeps = ['A.pydeps', 'B.pydeps']
+ self.old_ALL_PYDEPS_FILES = PRESUBMIT._ALL_PYDEPS_FILES
+ PRESUBMIT._ALL_PYDEPS_FILES = mock_all_pydeps
+ self.mock_input_api = MockInputApi()
+ self.mock_output_api = MockOutputApi()
+ self.mock_input_api.subprocess = PydepsNeedsUpdatingTest.MockSubprocess()
+ self.checker = PRESUBMIT.PydepsChecker(self.mock_input_api, mock_all_pydeps)
+ self.checker._file_cache = {
+ 'A.pydeps': '# Generated by:\n# CMD A\nA.py\nC.py\n',
+ 'B.pydeps': '# Generated by:\n# CMD B\nB.py\nC.py\n',
+ }
+
+ def tearDown(self):
+ PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES
+
+ def _RunCheck(self):
+ return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api,
+ self.mock_output_api,
+ checker_for_tests=self.checker)
+
+ def testAddedPydep(self):
+ self.mock_input_api.files = [
+ MockAffectedFile('new.pydeps', [], action='A'),
+ ]
+
+ results = self._RunCheck()
+ self.assertEqual(1, len(results))
+ self.assertTrue('PYDEPS_FILES' in str(results[0]))
+
+ def testRemovedPydep(self):
+ self.mock_input_api.files = [
+ MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'),
+ ]
+
+ results = self._RunCheck()
+ self.assertEqual(1, len(results))
+ self.assertTrue('PYDEPS_FILES' in str(results[0]))
+
+ def testRandomPyIgnored(self):
+ self.mock_input_api.files = [
+ MockAffectedFile('random.py', []),
+ ]
+
+ results = self._RunCheck()
+ self.assertEqual(0, len(results), 'Unexpected results: %r' % results)
+
+ def testRelevantPyNoChange(self):
+ self.mock_input_api.files = [
+ MockAffectedFile('A.py', []),
+ ]
+
+ def mock_check_output(cmd, shell=False):
+ self.assertEqual('CMD A --output ""', cmd)
+ return self.checker._file_cache['A.pydeps']
+
+ self.mock_input_api.subprocess.check_output = mock_check_output
+
+ results = self._RunCheck()
+ self.assertEqual(0, len(results), 'Unexpected results: %r' % results)
+
+ def testRelevantPyOneChange(self):
+ self.mock_input_api.files = [
+ MockAffectedFile('A.py', []),
+ ]
+
+ def mock_check_output(cmd, shell=False):
+ self.assertEqual('CMD A --output ""', cmd)
+ return 'changed data'
+
+ self.mock_input_api.subprocess.check_output = mock_check_output
+
+ results = self._RunCheck()
+ self.assertEqual(1, len(results))
+ self.assertTrue('File is stale' in str(results[0]))
+
+ def testRelevantPyTwoChanges(self):
+ self.mock_input_api.files = [
+ MockAffectedFile('C.py', []),
+ ]
+
+ def mock_check_output(cmd, shell=False):
+ return 'changed data'
+
+ self.mock_input_api.subprocess.check_output = mock_check_output
+
+ results = self._RunCheck()
+ self.assertEqual(2, len(results))
+ self.assertTrue('File is stale' in str(results[0]))
+ self.assertTrue('File is stale' in str(results[1]))
+
+
class LogUsageTest(unittest.TestCase):
def testCheckAndroidCrLogUsage(self):
« no previous file with comments | « PRESUBMIT.py ('k') | PRESUBMIT_test_mocks.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698