| OLD | NEW | 
| (Empty) |  | 
 |   1 # disable camel case warning | 
 |   2 # pylint: disable=C0103 | 
 |   3 import PRESUBMIT | 
 |   4  | 
 |   5 import mock | 
 |   6 import subprocess | 
 |   7 import unittest | 
 |   8  | 
 |   9 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockAffectedFile  
    # pylint: disable=F0401 | 
 |  10  | 
 |  11  | 
 |  12 class Capture(object): | 
 |  13     """ | 
 |  14     Class to capture a call argument that can be tested later on. | 
 |  15     """ | 
 |  16     def __init__(self): | 
 |  17         self.value = None | 
 |  18  | 
 |  19     def __eq__(self, other): | 
 |  20         self.value = other | 
 |  21         return True | 
 |  22  | 
 |  23  | 
 |  24 class PresubmitTest(unittest.TestCase): | 
 |  25  | 
 |  26     @mock.patch('subprocess.Popen') | 
 |  27     def testCheckChangeOnUploadWithWebKitAndChromiumFiles(self, _): | 
 |  28         """ | 
 |  29         This verifies that CheckChangeOnUpload will only call check-webkit-style | 
 |  30         on WebKit files. | 
 |  31         """ | 
 |  32         diff_file_webkit_h = ['some diff'] | 
 |  33         diff_file_chromium_h = ['another diff'] | 
 |  34         mock_input_api = MockInputApi() | 
 |  35         mock_input_api.files = [MockAffectedFile('FileWebkit.h', | 
 |  36                                                  diff_file_webkit_h), | 
 |  37                                 MockAffectedFile('file_chromium.h', | 
 |  38                                                  diff_file_chromium_h)] | 
 |  39         # Access to a protected member _CheckStyle | 
 |  40         # pylint: disable=W0212 | 
 |  41         PRESUBMIT._CheckStyle(mock_input_api, MockOutputApi()) | 
 |  42         capture = Capture() | 
 |  43         # pylint: disable=E1101 | 
 |  44         subprocess.Popen.assert_called_with(capture, stderr=-1) | 
 |  45         self.assertEqual(4, len(capture.value)) | 
 |  46         self.assertEqual('../../FileWebkit.h', capture.value[3]) | 
 |  47  | 
 |  48     @mock.patch('subprocess.Popen') | 
 |  49     def testCheckChangeOnUploadWithEmptyAffectedFileList(self, _): | 
 |  50         """ | 
 |  51         This verifies that CheckChangeOnUpload will skip calling | 
 |  52         check-webkit-style if the affected file list is empty. | 
 |  53         """ | 
 |  54         diff_file_chromium1_h = ['some diff'] | 
 |  55         diff_file_chromium2_h = ['another diff'] | 
 |  56         mock_input_api = MockInputApi() | 
 |  57         mock_input_api.files = [MockAffectedFile('first_file_chromium.h', | 
 |  58                                                  diff_file_chromium1_h), | 
 |  59                                 MockAffectedFile('second_file_chromium.h', | 
 |  60                                                  diff_file_chromium2_h)] | 
 |  61         # Access to a protected member _CheckStyle | 
 |  62         # pylint: disable=W0212 | 
 |  63         PRESUBMIT._CheckStyle(mock_input_api, MockOutputApi()) | 
 |  64         # pylint: disable=E1101 | 
 |  65         subprocess.Popen.assert_not_called() | 
 |  66  | 
 |  67  | 
 |  68 if __name__ == '__main__': | 
 |  69     unittest.main() | 
| OLD | NEW |