def testSingleGlobToDirectory(self): """Glob matching one element and dest directory provided.""" src_struct = [Dir(self.DIR_SRC_NAME, [self.ELEMENT_SRC])] dest_struct = [Dir(self.DIR_DEST_NAME, [self.ELEMENT_SRC])] path = chrome_util.Path(os.path.join(self.DIR_SRC_NAME, self.ELEMENTS_GLOB), dest=(self.DIR_DEST_NAME + os.sep)) self._CopyAndVerify(path, src_struct, dest_struct)
def testGlobReturnsMultipleError(self): """Glob returns multiple results but dest does not end with '/'.""" src_struct = self.ELEMENTS_SRC path = chrome_util.Path(self.ELEMENTS_GLOB, dest=self.DIR_DEST_NAME) self._CopyAndVerify(path, src_struct, None, error=chrome_util.MultipleMatchError)
def testMultiGlob(self): """Glob matching one file and dest directory provided.""" src_struct = [Dir(self.DIR_SRC_NAME, self.ELEMENTS_SRC)] dest_struct = [Dir(self.DIR_SRC_NAME, self.ELEMENTS_DEST)] path = chrome_util.Path( os.path.join(self.DIR_SRC_NAME, self.ELEMENTS_GLOB)) self._CopyAndVerify(path, src_struct, dest_struct)
def testNonDirError(self): """Test case where a file pattern matches a directory.""" src_struct = ['file1/'] dest_struct = [] path = chrome_util.Path('file1') self._CopyAndVerify(path, src_struct, dest_struct, error=chrome_util.MustNotBeDirError)
def testOneLevelDeepDirRename(self): """Renaming of an element and its containing directory.""" src_struct = [Dir(self.DIR_SRC_NAME, self.ELEMENTS_SRC)] dest_struct = [Dir(self.DIR_DEST_NAME, [self.ELEMENT_DEST])] path = chrome_util.Path(os.path.join(self.DIR_SRC_NAME, self.ELEMENT_SRC_NAME), dest=os.path.join(self.DIR_DEST_NAME, self.ELEMENT_DEST_NAME)) self._CopyAndVerify(path, src_struct, dest_struct)
def testStrictAndSloppy(self): """Test that strict and sloppy copies fail with an AssertionError.""" src_struct = self.ELEMENTS_SRC dest_struct = [self.ELEMENT_SRC] path = chrome_util.Path(self.ELEMENT_SRC_NAME) self._CopyAndVerify(path, src_struct, dest_struct, error=AssertionError, sloppy=True, strict=True)
def testElementOptional(self, cond=None, strict=False, error=None, optional=True): """A path cannot be found but is optional.""" src_struct = self.BAD_ELEMENTS dest_struct = [] path = chrome_util.Path(self.ELEMENT_SRC_NAME, cond=cond, optional=optional) self._CopyAndVerify(path, src_struct, dest_struct, error=error, strict=strict)
def testSurfaceCopy(self): """Copying an element from the root.""" src_struct = self.ELEMENTS_SRC dest_struct = [self.ELEMENT_SRC] path = chrome_util.Path(self.ELEMENT_SRC_NAME) self._CopyAndVerify(path, src_struct, dest_struct)
def testOptionalGlob(self): """A glob matches nothing but is optional.""" src_struct = self.ELEMENTS_SRC dest_struct = [] path = chrome_util.Path(self.MATCH_NOTHING_GLOB, optional=True) self._CopyAndVerify(path, src_struct, dest_struct)
def testSingleGlob(self): """Glob matching one element.""" src_struct = dest_struct = [Dir(self.DIR_SRC_NAME, [self.ELEMENT_SRC])] path = chrome_util.Path( os.path.join(self.DIR_SRC_NAME, self.ELEMENTS_GLOB)) self._CopyAndVerify(path, src_struct, dest_struct)
def testElementOptional(self): """A path cannot be found but is optional.""" src_struct = self.BAD_ELEMENTS dest_struct = [] path = chrome_util.Path(self.ELEMENT_SRC_NAME, optional=True) self._CopyAndVerify(path, src_struct, dest_struct)
def testNoElementSloppy(self): """No error raised when a non optional path cannot be found with --sloppy""" src_struct = self.BAD_ELEMENTS path = chrome_util.Path(self.ELEMENT_SRC_NAME) self._CopyAndVerify(path, src_struct, [], sloppy=True)
def _RunDeviceCmd(self): """Run a command on the device. Copy src files to /usr/local/cros_test/, change working directory to self.cwd, run the command in self.args, and cleanup. Returns: cros_build_lib.CommandResult object. """ DEST_BASE = '/usr/local/cros_test' files = FileList(self.files, self.files_from) # Copy files, preserving the directory structure. copy_paths = [] for f in files: is_exe = os.path.isfile(f) and os.access(f, os.X_OK) has_exe = False if os.path.isdir(f): if not f.endswith('/'): f += '/' for sub_dir, _, sub_files in os.walk(f): for sub_file in sub_files: if os.access(os.path.join(sub_dir, sub_file), os.X_OK): has_exe = True break if has_exe: break copy_paths.append(chrome_util.Path(f, exe=is_exe or has_exe)) if copy_paths: self._DeployCopyPaths(os.getcwd(), DEST_BASE, copy_paths) # Make cwd an absolute path (if it isn't one) rooted in DEST_BASE. cwd = self.cwd if files and not (cwd and os.path.isabs(cwd)): cwd = os.path.join(DEST_BASE, cwd) if cwd else DEST_BASE self._device.remote_run(['mkdir', '-p', cwd]) if self.as_chronos: # This authorizes the test ssh keys with chronos. self._device.remote_run(['cp', '-r', '/root/.ssh/', '/home/chronos/user/']) if files: # The trailing ':' after the user also changes the group to the user's # primary group. self._device.remote_run(['chown', '-R', 'chronos:', DEST_BASE]) user = '******' if self.as_chronos else None if cwd: # Run the remote command with cwd. cmd = 'cd %s && %s' % (cwd, ' '.join(self.args)) # Pass shell=True because of && in the cmd. result = self._device.remote_run(cmd, stream_output=True, shell=True, remote_user=user) else: result = self._device.remote_run(self.args, stream_output=True, remote_user=user) # Cleanup. if files: self._device.remote_run(['rm', '-rf', DEST_BASE]) return result