Repository: servo/servo
File: etc/blink-perf-test-runner/main.py (Python)

Code before:
        return AbortReason.NotFound
    except:  # noqa: E722
        print("Some other exception for this test case")
        return AbortReason.Panic
    return AbortReason.NotFound


def canonical_test_path(filePath: str) -> str:
    """Make the filepath into just the directory and name"""
    p = PurePath(filePath)
    parts = p.parts
    index = parts.index("perf_tests")
    return "/".join(parts[index:])


def test_file(file_name: str) -> bool:
    return ".html" in file_name and (file_name not in IGNORE_TESTS)


def write_file(results):
    with open("results.json", "w") as f:
        json.dump(results, f)


def main():
    parser = argparse.ArgumentParser(description="Run Chrome Tests on Servo Instance.")
    parser.add_argument("servo_path", type=str, help="the servo binary")
    parser.add_argument("test_dir", type=str, help="The directory for the chromium tests.")
    args = parser.parse_args()

    webdriver = start_servo(args.servo_path)
    final_result = {}
    time.sleep(2)
    if webdriver:
        webdriver.implicitly_wait(30)
        for root, dir, files in os.walk(args.test_dir):
            for file in files:
                if test_file(file):
                    filePath = os.path.join(os.path.abspath(root), file)
                    result = test("file://" + filePath, webdriver)
                    if result == AbortReason.Panic:
                        print("Restarting servo")
                        start_servo(args.servo_path)
                    elif result == AbortReason.NotFound:
                        pass
                    else:
                        combined_result = {}
                        combined_result["value"] = result[0]
                        combined_result["lower_value"] = result[1]
                        combined_result["upper_value"] = result[2]


Review comment (suggestion):
```suggestion
    parser = argparse.ArgumentParser(description="Run Blink Perf Tests on Servo Instance.")
```

Code after:
            avg_line = next(filter(lambda x: "avg" in x, result_lines), None)
            min_line = next(filter(lambda x: "min" in x, result_lines), None)
            max_line = next(filter(lambda x: "max" in x, result_lines), None)
            if avg_line is not None and min_line is not None and max_line is not None:
                return (avg_line.split()[1], min_line.split()[1], max_line.split()[1])
            time.sleep(1)
    except NoSuchElementException:
        print("Could not find log?")
        return AbortReason.NotFound
    except Exception as e:
        print(f"Some other exception for this test case: {e}")
        return AbortReason.Panic
    return AbortReason.NotFound


def canonical_test_path(filePath: str, prepend: str | None) -> str:
    """Make the filepath into just the directory and name"""
    p = PurePath(filePath)
    parts = p.parts
    index = parts.index("perf_tests")
    if prepend:
        return prepend + "/" + "/".join(parts[index:])
    else:
        return "/".join(parts[index:])


def test_file(file_name: str) -> bool:
    return ".html" in file_name and (file_name not in IGNORE_TESTS)


def write_file(results):
    with open("results.json", "w") as f:
        json.dump(results, f)


def oswalk_error(error: OSError):
    print(error)
    sys.exit(1)


def main():
    parser = argparse.ArgumentParser(description="Run Blink Perf Tests on Servo Instance.")
    parser.add_argument("servo_path", type=str, help="the servo binary")
    parser.add_argument(
        "-w", "--webdriver", default=7000, type=int, action="store", help="The webdriver port servo will listen on."
    )
    parser.add_argument(
        "-p",
        "--prepend",
        action="store",
        help="A value prepended to all results. Useful to distinguish between profiles.",