def test_firebase_device_clean_lint_error_lines_with_valid_lint_line(
        valid_lint_lines, empty_file_path):
    log_parser = FirebaseDeviceLogFileParser(empty_file_path)
    log_parser.lint_errors = [valid_lint_lines.get("firebase_lint")[3]]
    log_parser.clean_lint_error_lines()
    assert valid_lint_lines.get(
        "firebase_lint")[1] == log_parser.lint_errors[0]
def test_firebase_device_log_file_parser_with_valid_file(
        firebase_valid_file_path, valid_lint_lines, mock_file_write_functions):
    log_parser = FirebaseDeviceLogFileParser(
        firebase_valid_file_path.get("firebase_lint_valid_path"))
    log_parser.log_parser()
    assert len(log_parser.formatted_lines) == 2
    assert valid_lint_lines.get(
        "firebase_lint")[8] in log_parser.formatted_lines
    assert valid_lint_lines.get(
        "firebase_lint")[9] in log_parser.formatted_lines
def test_firebase_device_log_file_parser_init_with_valid_values(
        firebase_valid_file_path, firebase_device_log_file_parser_parameters):
    log_parser = FirebaseDeviceLogFileParser(
        firebase_valid_file_path.get("firebase_lint_valid_path"))
    file_parser_parameters = firebase_device_log_file_parser_parameters.get(
        "file_parser")
    assert log_parser.log_file_parser.start_regex == file_parser_parameters.get(
        "start_regex")
    assert log_parser.log_file_parser.stop_regex == file_parser_parameters.get(
        "stop_regex")
    assert log_parser.log_file_parser.parse_regex == file_parser_parameters.get(
        "parse_regex")
def choose_and_run_parser_type(file_path,
                               log_file_type,
                               first_parser_parameter="Target"):
    """Parser manager

    Args:
        file_path (string or None): Path to log file to be parsed
        log_file_type (string or None): Parser to be run against log file
        first_parser_parameter (string): First parameter to be used by parser

    """
    ci_output_parser_cli_help = "ci_output_parser file_path [ android_lint [api_version] | " \
                                "junit_android_lint [api_version] | " \
                                "pre_commit_lint | " \
                                "vale_lint | " \
                                "gtest_lint | " \
                                "firebase_lint | " \
                                "firebase_test_lint [device_name] ] \n " \
                                "The default value of the first parser parameter is 'Target' "
    if file_path is None:
        raise ValueError(ci_output_parser_cli_help)
    elif log_file_type is None:
        raise ValueError(ci_output_parser_cli_help)
    elif log_file_type == "android_lint":
        log_file_parser = AndroidAppLogFileParser(file_path,
                                                  first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = AndroidModelsLogFileParser(file_path,
                                                     first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = AndroidBuildLogFileParser(file_path,
                                                    first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = AndroidKotlinLogFileParser(file_path,
                                                     first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = AndroidDebugJavacLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = AndroidReleaseJavacLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "junit_android_lint":
        log_file_parser = JUnitAndroidDebugLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = JUnitAndroidReleaseLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "pre_commit_lint":
        log_file_parser = PreCommitLogLogFileParser(file_path)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "vale_lint":
        log_file_parser = ValeLogFileParser(file_path)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "gtest_lint":
        log_file_parser = GTestLogFileParser(file_path)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "firebase_lint":
        log_file_parser = FirebaseBucketLogFileParser(file_path)
        log_file_parser.log_parser()
        log_file_parser = FirebaseDeviceLogFileParser(file_path)
        log_file_parser.log_parser()
        exit(0)
    elif log_file_type == "firebase_test_lint":
        log_file_parser = FirebaseTestLogFileParser(file_path,
                                                    first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = FirebaseTestCrashLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        log_file_parser = FirebaseTestTimeoutLogFileParser(
            file_path, first_parser_parameter)
        log_file_parser.log_parser()
        exit(0)
    else:
        raise ValueError(ci_output_parser_cli_help)
def test_firebase_device_clean_lint_error_lines_with_empty_lines(
        empty_file_path):
    log_parser = FirebaseDeviceLogFileParser(empty_file_path)
    log_parser.clean_lint_error_lines()
    assert not log_parser.lint_errors
def test_firebase_device_log_file_parser_with_empty_file(
        empty_file_path, mock_file_write_functions):
    log_parser = FirebaseDeviceLogFileParser(empty_file_path)
    log_parser.log_parser()
    assert not log_parser.formatted_lines
def test_firebase_device_log_file_parser_with_invalid_file(invalid_file_path):
    log_parser = FirebaseDeviceLogFileParser(invalid_file_path)
    with pytest.raises(FileNotFoundError):
        log_parser.log_parser()
def test_firebase_device_log_file_parser_with_clean_file(
        firebase_valid_file_path, mock_file_write_functions):
    log_parser = FirebaseDeviceLogFileParser(
        firebase_valid_file_path.get("firebase_lint_clean_valid_path"))
    log_parser.log_parser()
    assert not log_parser.formatted_lines