Ejemplo n.º 1
0
def get_affected_testfiles(files_changed):
    """Determine and return list of test files that reference changed files."""
    affected_testfiles = set()
    nontests_changed = set(files_changed)
    manifest_file = os.path.join(wpt_root, "MANIFEST.json")
    skip_dirs = ["conformance-checkers", "docs", "tools"]
    test_types = ["testharness", "reftest", "wdspec"]

    wpt_manifest = manifest.load(wpt_root, manifest_file)

    support_files = {
        os.path.join(wpt_root, path)
        for _, path, _ in wpt_manifest.itertypes("support")
    }
    test_files = {
        os.path.join(wpt_root, path)
        for _, path, _ in wpt_manifest.itertypes(*test_types)
    }

    nontests_changed = nontests_changed.intersection(support_files)

    nontest_changed_paths = set()
    for full_path in nontests_changed:
        rel_path = os.path.relpath(full_path, wpt_root)
        path_components = rel_path.split(os.sep)
        if len(path_components) < 2:
            # This changed file is in the repo root, so skip it
            # (because it's not part of any test).
            continue
        top_level_subdir = path_components[0]
        if top_level_subdir in skip_dirs:
            continue
        repo_path = "/" + os.path.relpath(full_path, wpt_root).replace(
            os.path.sep, "/")
        nontest_changed_paths.add((full_path, repo_path))

    for root, dirs, fnames in os.walk(wpt_root):
        # Walk top_level_subdir looking for test files containing either the
        # relative filepath or absolute filepatch to the changed files.
        if root == wpt_root:
            for dir_name in skip_dirs:
                dirs.remove(dir_name)
        for fname in fnames:
            test_full_path = os.path.join(root, fname)
            # Skip any file that's not a test file.
            if test_full_path not in test_files:
                continue
            with open(test_full_path, "rb") as fh:
                file_contents = fh.read()
                if file_contents.startswith("\xfe\xff"):
                    file_contents = file_contents.decode("utf-16be")
                elif file_contents.startswith("\xff\xfe"):
                    file_contents = file_contents.decode("utf-16le")
                for full_path, repo_path in nontest_changed_paths:
                    rel_path = os.path.relpath(full_path,
                                               root).replace(os.path.sep, "/")
                    if rel_path in file_contents or repo_path in file_contents:
                        affected_testfiles.add(test_full_path)
                        continue
    return affected_testfiles
Ejemplo n.º 2
0
def get_affected_testfiles(files_changed):
    """Determine and return list of test files that reference changed files."""
    affected_testfiles = set()
    nontests_changed = set(files_changed)
    manifest_file = os.path.join(wpt_root, "MANIFEST.json")
    skip_dirs = ["conformance-checkers", "docs", "tools"]
    test_types = ["testharness", "reftest", "wdspec"]

    wpt_manifest = manifest.load(wpt_root, manifest_file)

    support_files = {os.path.join(wpt_root, path)
                     for _, path, _ in wpt_manifest.itertypes("support")}
    test_files = {os.path.join(wpt_root, path)
                  for _, path, _ in wpt_manifest.itertypes(*test_types)}

    nontests_changed = nontests_changed.intersection(support_files)

    nontest_changed_paths = set()
    for full_path in nontests_changed:
        rel_path = os.path.relpath(full_path, wpt_root)
        path_components = rel_path.split(os.sep)
        if len(path_components) < 2:
            # This changed file is in the repo root, so skip it
            # (because it's not part of any test).
            continue
        top_level_subdir = path_components[0]
        if top_level_subdir in skip_dirs:
            continue
        repo_path = "/" + os.path.relpath(full_path, wpt_root).replace(os.path.sep, "/")
        nontest_changed_paths.add((full_path, repo_path))

    for root, dirs, fnames in os.walk(wpt_root):
        # Walk top_level_subdir looking for test files containing either the
        # relative filepath or absolute filepatch to the changed files.
        if root == wpt_root:
            for dir_name in skip_dirs:
                dirs.remove(dir_name)
        for fname in fnames:
            test_full_path = os.path.join(root, fname)
            # Skip any file that's not a test file.
            if test_full_path not in test_files:
                continue
            with open(test_full_path, "rb") as fh:
                file_contents = fh.read()
                if file_contents.startswith("\xfe\xff"):
                    file_contents = file_contents.decode("utf-16be")
                elif file_contents.startswith("\xff\xfe"):
                    file_contents = file_contents.decode("utf-16le")
                for full_path, repo_path in nontest_changed_paths:
                    rel_path = os.path.relpath(full_path, root).replace(os.path.sep, "/")
                    if rel_path in file_contents or repo_path in file_contents:
                        affected_testfiles.add(test_full_path)
                        continue
    return affected_testfiles
Ejemplo n.º 3
0
def get_affected_testfiles(files_changed):
    affected_testfiles = []
    all_tests = set()
    nontests_changed = set(files_changed)
    repo_root = os.path.abspath(
        os.path.join(os.path.abspath(os.curdir), "w3c", "web-platform-tests"))
    manifest_file = os.path.join(repo_root, "MANIFEST.json")
    for test, _ in manifest.load(repo_root, manifest_file):
        test_full_path = os.path.join(repo_root, test)
        all_tests.add(test_full_path)
        if test_full_path in nontests_changed:
            # Reduce the set of changed files to only non-tests.
            nontests_changed.remove(test_full_path)
    for changedfile_pathname in nontests_changed:
        changed_file_repo_path = os.path.join(
            os.path.sep, os.path.relpath(changedfile_pathname, repo_root))
        os.path.normpath(changed_file_repo_path)
        path_components = changed_file_repo_path.split(os.sep)[1:]
        if len(path_components) < 2:
            # This changed file is in the repo root, so skip it
            # (because it's not part of any test).
            continue
        top_level_subdir = path_components[0]
        if top_level_subdir in ["conformance-checkers", "docs"]:
            continue
        # OK, this changed file is the kind we care about: It's something
        # other than a test (e.g., it's a .js or .json file), and it's
        # somewhere down beneath one of the top-level "spec" directories.
        # So now we try to find any tests that reference it.
        for root, dirs, fnames in os.walk(
                os.path.join(repo_root, top_level_subdir)):
            # Walk top_level_subdir looking for test files containing either the
            # relative filepath or absolute filepatch to the changed file.
            for fname in fnames:
                testfile_full_path = os.path.join(root, fname)
                # Skip any test file that's already in files_changed.
                if testfile_full_path in files_changed:
                    continue
                # Skip any file that's not a test file.
                if testfile_full_path not in all_tests:
                    continue
                with open(testfile_full_path, "r") as fh:
                    file_contents = fh.read()
                    changed_file_relpath = os.path.relpath(
                        changedfile_pathname, root).replace(os.path.sep, "/")
                    if changed_file_relpath in file_contents or changed_file_repo_path.replace(
                            os.path.sep, "/") in file_contents:
                        affected_testfiles.append(testfile_full_path)
    return affected_testfiles
Ejemplo n.º 4
0
def get_affected_testfiles(files_changed):
    affected_testfiles = []
    all_tests = set()
    nontests_changed = set(files_changed)
    repo_root = os.path.abspath(os.path.join(os.path.abspath(os.curdir), "w3c", "web-platform-tests"))
    manifest_file = os.path.join(repo_root, "MANIFEST.json")
    for test, _ in manifest.load(repo_root, manifest_file):
        test_full_path = os.path.join(repo_root, test)
        all_tests.add(test_full_path)
        if test_full_path in nontests_changed:
            # Reduce the set of changed files to only non-tests.
            nontests_changed.remove(test_full_path)
    for changedfile_pathname in nontests_changed:
        changed_file_repo_path = os.path.join(os.path.sep, os.path.relpath(changedfile_pathname, repo_root))
        os.path.normpath(changed_file_repo_path)
        path_components = changed_file_repo_path.split(os.sep)[1:]
        if len(path_components) < 2:
            # This changed file is in the repo root, so skip it
            # (because it's not part of any test).
            continue
        top_level_subdir = path_components[0]
        if top_level_subdir in ["conformance-checkers", "docs"]:
            continue
        # OK, this changed file is the kind we care about: It's something
        # other than a test (e.g., it's a .js or .json file), and it's
        # somewhere down beneath one of the top-level "spec" directories.
        # So now we try to find any tests that reference it.
        for root, dirs, fnames in os.walk(os.path.join(repo_root, top_level_subdir)):
            # Walk top_level_subdir looking for test files containing either the
            # relative filepath or absolute filepatch to the changed file.
            for fname in fnames:
                testfile_full_path = os.path.join(root, fname)
                # Skip any test file that's already in files_changed.
                if testfile_full_path in files_changed:
                    continue
                # Skip any file that's not a test file.
                if testfile_full_path not in all_tests:
                    continue
                with open(testfile_full_path, "r") as fh:
                    file_contents = fh.read()
                    changed_file_relpath = os.path.relpath(changedfile_pathname, root).replace(os.path.sep, "/")
                    if (
                        changed_file_relpath in file_contents
                        or changed_file_repo_path.replace(os.path.sep, "/") in file_contents
                    ):
                        affected_testfiles.append(testfile_full_path)
    return affected_testfiles
Ejemplo n.º 5
0
def get_affected_testfiles(files_changed, skip_tests):
    """Determine and return list of test files that reference changed files."""
    affected_testfiles = set()
    # Exclude files that are in the repo root, because
    # they are not part of any test.
    files_changed = [f for f in files_changed if not _in_repo_root(f)]
    nontests_changed = set(files_changed)
    manifest_file = os.path.join(wpt_root, "MANIFEST.json")
    test_types = ["testharness", "reftest", "wdspec"]

    wpt_manifest = manifest.load(wpt_root, manifest_file)

    support_files = {
        os.path.join(wpt_root, path)
        for _, path, _ in wpt_manifest.itertypes("support")
    }
    wdspec_test_files = {
        os.path.join(wpt_root, path)
        for _, path, _ in wpt_manifest.itertypes("wdspec")
    }
    test_files = {
        os.path.join(wpt_root, path)
        for _, path, _ in wpt_manifest.itertypes(*test_types)
    }

    nontests_changed = nontests_changed.intersection(support_files)

    nontest_changed_paths = set()
    for full_path in nontests_changed:
        rel_path = os.path.relpath(full_path, wpt_root)
        path_components = rel_path.split(os.sep)
        top_level_subdir = path_components[0]
        if top_level_subdir in skip_tests:
            continue
        repo_path = "/" + os.path.relpath(full_path, wpt_root).replace(
            os.path.sep, "/")
        nontest_changed_paths.add((full_path, repo_path))

    def affected_by_wdspec(test):
        affected = False
        if test in wdspec_test_files:
            for support_full_path, _ in nontest_changed_paths:
                # parent of support file or of "support" directory
                parent = os.path.dirname(support_full_path)
                if os.path.basename(parent) == "support":
                    parent = os.path.dirname(parent)
                relpath = os.path.relpath(test, parent)
                if not relpath.startswith(os.pardir):
                    # testfile is in subtree of support file
                    affected = True
                    break
        return affected

    for root, dirs, fnames in os.walk(wpt_root):
        # Walk top_level_subdir looking for test files containing either the
        # relative filepath or absolute filepath to the changed files.
        if root == wpt_root:
            for dir_name in skip_tests:
                dirs.remove(dir_name)
        for fname in fnames:
            test_full_path = os.path.join(root, fname)
            # Skip any file that's not a test file.
            if test_full_path not in test_files:
                continue
            if affected_by_wdspec(test_full_path):
                affected_testfiles.add(test_full_path)
                continue

            with open(test_full_path, "rb") as fh:
                file_contents = fh.read()
                if file_contents.startswith("\xfe\xff"):
                    file_contents = file_contents.decode("utf-16be")
                elif file_contents.startswith("\xff\xfe"):
                    file_contents = file_contents.decode("utf-16le")
                for full_path, repo_path in nontest_changed_paths:
                    rel_path = os.path.relpath(full_path,
                                               root).replace(os.path.sep, "/")
                    if rel_path in file_contents or repo_path in file_contents:
                        affected_testfiles.add(test_full_path)
                        continue
    return affected_testfiles
Ejemplo n.º 6
0
def get_affected_testfiles(files_changed, skip_tests):
    """Determine and return list of test files that reference changed files."""
    affected_testfiles = set()
    # Exclude files that are in the repo root, because
    # they are not part of any test.
    files_changed = [f for f in files_changed if not _in_repo_root(f)]
    nontests_changed = set(files_changed)
    manifest_file = os.path.join(wpt_root, "MANIFEST.json")
    test_types = ["testharness", "reftest", "wdspec"]

    wpt_manifest = manifest.load(wpt_root, manifest_file)

    support_files = {os.path.join(wpt_root, path)
                     for _, path, _ in wpt_manifest.itertypes("support")}
    wdspec_test_files = {os.path.join(wpt_root, path)
                         for _, path, _ in wpt_manifest.itertypes("wdspec")}
    test_files = {os.path.join(wpt_root, path)
                  for _, path, _ in wpt_manifest.itertypes(*test_types)}

    nontests_changed = nontests_changed.intersection(support_files)

    nontest_changed_paths = set()
    for full_path in nontests_changed:
        rel_path = os.path.relpath(full_path, wpt_root)
        path_components = rel_path.split(os.sep)
        top_level_subdir = path_components[0]
        if top_level_subdir in skip_tests:
            continue
        repo_path = "/" + os.path.relpath(full_path, wpt_root).replace(os.path.sep, "/")
        nontest_changed_paths.add((full_path, repo_path))

    def affected_by_wdspec(test):
        affected = False
        if test in wdspec_test_files:
            for support_full_path, _ in nontest_changed_paths:
                # parent of support file or of "support" directory
                parent = os.path.dirname(support_full_path)
                if os.path.basename(parent) == "support":
                    parent = os.path.dirname(parent)
                relpath = os.path.relpath(test, parent)
                if not relpath.startswith(os.pardir):
                    # testfile is in subtree of support file
                    affected = True
                    break
        return affected

    for root, dirs, fnames in os.walk(wpt_root):
        # Walk top_level_subdir looking for test files containing either the
        # relative filepath or absolute filepath to the changed files.
        if root == wpt_root:
            for dir_name in skip_tests:
                dirs.remove(dir_name)
        for fname in fnames:
            test_full_path = os.path.join(root, fname)
            # Skip any file that's not a test file.
            if test_full_path not in test_files:
                continue
            if affected_by_wdspec(test_full_path):
                affected_testfiles.add(test_full_path)
                continue

            with open(test_full_path, "rb") as fh:
                file_contents = fh.read()
                if file_contents.startswith("\xfe\xff"):
                    file_contents = file_contents.decode("utf-16be")
                elif file_contents.startswith("\xff\xfe"):
                    file_contents = file_contents.decode("utf-16le")
                for full_path, repo_path in nontest_changed_paths:
                    rel_path = os.path.relpath(full_path, root).replace(os.path.sep, "/")
                    if rel_path in file_contents or repo_path in file_contents:
                        affected_testfiles.add(test_full_path)
                        continue
    return affected_testfiles