Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
PRESUBMIT_test_mocks.MockInputApi Class Reference
Inheritance diagram for PRESUBMIT_test_mocks.MockInputApi:

Public Member Functions

def __init__ (self)
 
def CreateMockFileInPath (self, f_list)
 
def AffectedFiles (self, file_filter=None, include_deletes=True)
 
def RightHandSideLines (self, source_file_filter=None)
 
def AffectedSourceFiles (self, file_filter=None)
 
def FilterSourceFile (self, file, files_to_check=(), files_to_skip=())
 
def LocalPaths (self)
 
def PresubmitLocalPath (self)
 
def ReadFile (self, filename, mode='r')
 

Public Attributes

 canned_checks
 
 fnmatch
 
 json
 
 re
 
 os_path
 
 platform
 
 python_executable
 
 python3_executable
 
 subprocess
 
 sys
 
 files
 
 is_committing
 
 change
 
 presubmit_local_path
 
 is_windows
 
 no_diffs
 
 verbose
 

Static Public Attributes

tuple DEFAULT_FILES_TO_SKIP = ()
 

Detailed Description

Mock class for the InputApi class.

This class can be used for unittests for presubmit by initializing the files
attribute as the list of changed files.

Definition at line 59 of file PRESUBMIT_test_mocks.py.

Constructor & Destructor Documentation

◆ __init__()

def PRESUBMIT_test_mocks.MockInputApi.__init__ (   self)

Definition at line 68 of file PRESUBMIT_test_mocks.py.

68 def __init__(self):
69 self.canned_checks = MockCannedChecks()
70 self.fnmatch = fnmatch
71 self.json = json
72 self.re = re
73 self.os_path = os.path
74 self.platform = sys.platform
75 self.python_executable = sys.executable
76 self.python3_executable = sys.executable
77 self.platform = sys.platform
78 self.subprocess = subprocess
79 self.sys = sys
80 self.files = []
81 self.is_committing = False
82 self.change = MockChange([])
83 self.presubmit_local_path = os.path.dirname(__file__)
84 self.is_windows = sys.platform == 'win32'
85 self.no_diffs = False
86 # Although this makes assumptions about command line arguments used by test
87 # scripts that create mocks, it is a convenient way to set up the verbosity
88 # via the input api.
89 self.verbose = '--verbose' in sys.argv
90

Member Function Documentation

◆ AffectedFiles()

def PRESUBMIT_test_mocks.MockInputApi.AffectedFiles (   self,
  file_filter = None,
  include_deletes = True 
)

Definition at line 94 of file PRESUBMIT_test_mocks.py.

94 def AffectedFiles(self, file_filter=None, include_deletes=True):
95 for file in self.files:
96 if file_filter and not file_filter(file):
97 continue
98 if not include_deletes and file.Action() == 'D':
99 continue
100 yield file
101

◆ AffectedSourceFiles()

def PRESUBMIT_test_mocks.MockInputApi.AffectedSourceFiles (   self,
  file_filter = None 
)

Definition at line 109 of file PRESUBMIT_test_mocks.py.

109 def AffectedSourceFiles(self, file_filter=None):
110 return self.AffectedFiles(file_filter=file_filter)
111

◆ CreateMockFileInPath()

def PRESUBMIT_test_mocks.MockInputApi.CreateMockFileInPath (   self,
  f_list 
)

Definition at line 91 of file PRESUBMIT_test_mocks.py.

91 def CreateMockFileInPath(self, f_list):
92 self.os_path.exists = lambda x: x in f_list
93

◆ FilterSourceFile()

def PRESUBMIT_test_mocks.MockInputApi.FilterSourceFile (   self,
  file,
  files_to_check = (),
  files_to_skip = () 
)

Definition at line 112 of file PRESUBMIT_test_mocks.py.

113 files_to_check=(), files_to_skip=()):
114 local_path = file.LocalPath()
115 found_in_files_to_check = not files_to_check
116 if files_to_check:
117 if type(files_to_check) is str:
118 raise TypeError(
119 'files_to_check should be an iterable of strings')
120 for pattern in files_to_check:
121 compiled_pattern = re.compile(pattern)
122 if compiled_pattern.match(local_path):
123 found_in_files_to_check = True
124 break
125 if files_to_skip:
126 if type(files_to_skip) is str:
127 raise TypeError(
128 'files_to_skip should be an iterable of strings')
129 for pattern in files_to_skip:
130 compiled_pattern = re.compile(pattern)
131 if compiled_pattern.match(local_path):
132 return False
133 return found_in_files_to_check
134
GLenum type

◆ LocalPaths()

def PRESUBMIT_test_mocks.MockInputApi.LocalPaths (   self)

Definition at line 135 of file PRESUBMIT_test_mocks.py.

135 def LocalPaths(self):
136 return [file.LocalPath() for file in self.files]
137

◆ PresubmitLocalPath()

def PRESUBMIT_test_mocks.MockInputApi.PresubmitLocalPath (   self)

Definition at line 138 of file PRESUBMIT_test_mocks.py.

138 def PresubmitLocalPath(self):
139 return self.presubmit_local_path
140

◆ ReadFile()

def PRESUBMIT_test_mocks.MockInputApi.ReadFile (   self,
  filename,
  mode = 'r' 
)

Definition at line 141 of file PRESUBMIT_test_mocks.py.

141 def ReadFile(self, filename, mode='r'):
142 if hasattr(filename, 'AbsoluteLocalPath'):
143 filename = filename.AbsoluteLocalPath()
144 for file_ in self.files:
145 if file_.LocalPath() == filename:
146 return '\n'.join(file_.NewContents())
147 # Otherwise, file is not in our mock API.
148 raise IOError("No such file or directory: '%s'" % filename)
149
150
void ReadFile(uint8_t **data, intptr_t *file_len, void *stream)
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ RightHandSideLines()

def PRESUBMIT_test_mocks.MockInputApi.RightHandSideLines (   self,
  source_file_filter = None 
)

Definition at line 102 of file PRESUBMIT_test_mocks.py.

102 def RightHandSideLines(self, source_file_filter=None):
103 affected_files = self.AffectedSourceFiles(source_file_filter)
104 for af in affected_files:
105 lines = af.ChangedContents()
106 for line in lines:
107 yield (af, line[0], line[1])
108

Member Data Documentation

◆ canned_checks

PRESUBMIT_test_mocks.MockInputApi.canned_checks

Definition at line 69 of file PRESUBMIT_test_mocks.py.

◆ change

PRESUBMIT_test_mocks.MockInputApi.change

Definition at line 82 of file PRESUBMIT_test_mocks.py.

◆ DEFAULT_FILES_TO_SKIP

tuple PRESUBMIT_test_mocks.MockInputApi.DEFAULT_FILES_TO_SKIP = ()
static

Definition at line 66 of file PRESUBMIT_test_mocks.py.

◆ files

PRESUBMIT_test_mocks.MockInputApi.files

Definition at line 80 of file PRESUBMIT_test_mocks.py.

◆ fnmatch

PRESUBMIT_test_mocks.MockInputApi.fnmatch

Definition at line 70 of file PRESUBMIT_test_mocks.py.

◆ is_committing

PRESUBMIT_test_mocks.MockInputApi.is_committing

Definition at line 81 of file PRESUBMIT_test_mocks.py.

◆ is_windows

PRESUBMIT_test_mocks.MockInputApi.is_windows

Definition at line 84 of file PRESUBMIT_test_mocks.py.

◆ json

PRESUBMIT_test_mocks.MockInputApi.json

Definition at line 71 of file PRESUBMIT_test_mocks.py.

◆ no_diffs

PRESUBMIT_test_mocks.MockInputApi.no_diffs

Definition at line 85 of file PRESUBMIT_test_mocks.py.

◆ os_path

PRESUBMIT_test_mocks.MockInputApi.os_path

Definition at line 73 of file PRESUBMIT_test_mocks.py.

◆ platform

PRESUBMIT_test_mocks.MockInputApi.platform

Definition at line 74 of file PRESUBMIT_test_mocks.py.

◆ presubmit_local_path

PRESUBMIT_test_mocks.MockInputApi.presubmit_local_path

Definition at line 83 of file PRESUBMIT_test_mocks.py.

◆ python3_executable

PRESUBMIT_test_mocks.MockInputApi.python3_executable

Definition at line 76 of file PRESUBMIT_test_mocks.py.

◆ python_executable

PRESUBMIT_test_mocks.MockInputApi.python_executable

Definition at line 75 of file PRESUBMIT_test_mocks.py.

◆ re

PRESUBMIT_test_mocks.MockInputApi.re

Definition at line 72 of file PRESUBMIT_test_mocks.py.

◆ subprocess

PRESUBMIT_test_mocks.MockInputApi.subprocess

Definition at line 78 of file PRESUBMIT_test_mocks.py.

◆ sys

PRESUBMIT_test_mocks.MockInputApi.sys

Definition at line 79 of file PRESUBMIT_test_mocks.py.

◆ verbose

PRESUBMIT_test_mocks.MockInputApi.verbose

Definition at line 89 of file PRESUBMIT_test_mocks.py.


The documentation for this class was generated from the following file: