def VerifyTarball(tarball, dir_struct): """Compare the contents of a tarball against a directory structure. Arguments: tarball: Path to the tarball. dir_struct: See CreateOnDiskHierarchy() Raises: AssertionError when there is any divergence between the tarball and the structure specified by 'dir_struct'. """ contents = cros_build_lib.RunCommandCaptureOutput(['tar', '-tf', tarball ]).output.splitlines() normalized = set() for p in contents: norm = os.path.normpath(p) if p.endswith('/'): norm += '/' if norm in normalized: raise AssertionError('Duplicate entry %r found in %r!' % (norm, tarball)) normalized.add(norm) expected = _FlattenStructure('', dir_struct) _VerifyDirectoryIterables(normalized, expected)
def FindTests(directory, module_namespace=''): """Find all *_unittest.py, and return their python namespaces. Args: directory: The directory to scan for tests. module_namespace: What namespace to prefix all found tests with. Returns: A list of python unittests in python namespace form. """ results = cros_build_lib.RunCommandCaptureOutput( ['find', '.', '-name', '*_unittest.py', '-printf', '%P\n'], cwd=directory, print_cmd=False).output.splitlines() # Drop the trailing .py, inject in the name if one was given. if module_namespace: module_namespace += '.' return [module_namespace + x[:-3].replace('/', '.') for x in results]