github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/python_helpers.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package main
    12  
    13  import (
    14  	"bufio"
    15  	"bytes"
    16  	"fmt"
    17  	"regexp"
    18  )
    19  
    20  var pythonUnitTestOutputRegex = regexp.MustCompile(`(?P<name>.*) \((?P<class>.*)\) \.\.\. (?P<result>[^ ']*)(?: u?['"](?P<reason>.*)['"])?`)
    21  
    22  func (r *ormTestsResults) parsePythonUnitTestOutput(
    23  	input []byte, expectedFailures blacklist, ignoredList blacklist,
    24  ) {
    25  	scanner := bufio.NewScanner(bytes.NewReader(input))
    26  	for scanner.Scan() {
    27  		match := pythonUnitTestOutputRegex.FindStringSubmatch(scanner.Text())
    28  		if match != nil {
    29  			groups := map[string]string{}
    30  			for i, name := range match {
    31  				groups[pythonUnitTestOutputRegex.SubexpNames()[i]] = name
    32  			}
    33  			test := fmt.Sprintf("%s.%s", groups["class"], groups["name"])
    34  			var skipReason string
    35  			if groups["result"] == "skipped" {
    36  				skipReason = groups["reason"]
    37  			}
    38  			pass := groups["result"] == "ok"
    39  			r.allTests = append(r.allTests, test)
    40  
    41  			ignoredIssue, expectedIgnored := ignoredList[test]
    42  			issue, expectedFailure := expectedFailures[test]
    43  			switch {
    44  			case expectedIgnored:
    45  				r.results[test] = fmt.Sprintf("--- SKIP: %s due to %s (expected)", test, ignoredIssue)
    46  				r.ignoredCount++
    47  			case len(skipReason) > 0 && expectedFailure:
    48  				r.results[test] = fmt.Sprintf("--- SKIP: %s due to %s (unexpected)", test, skipReason)
    49  				r.unexpectedSkipCount++
    50  			case len(skipReason) > 0:
    51  				r.results[test] = fmt.Sprintf("--- SKIP: %s due to %s (expected)", test, skipReason)
    52  				r.skipCount++
    53  			case pass && !expectedFailure:
    54  				r.results[test] = fmt.Sprintf("--- PASS: %s (expected)", test)
    55  				r.passExpectedCount++
    56  			case pass && expectedFailure:
    57  				r.results[test] = fmt.Sprintf("--- PASS: %s - %s (unexpected)",
    58  					test, maybeAddGithubLink(issue),
    59  				)
    60  				r.passUnexpectedCount++
    61  			case !pass && expectedFailure:
    62  				r.results[test] = fmt.Sprintf("--- FAIL: %s - %s (expected)",
    63  					test, maybeAddGithubLink(issue),
    64  				)
    65  				r.failExpectedCount++
    66  				r.currentFailures = append(r.currentFailures, test)
    67  			case !pass && !expectedFailure:
    68  				r.results[test] = fmt.Sprintf("--- FAIL: %s (unexpected)", test)
    69  				r.failUnexpectedCount++
    70  				r.currentFailures = append(r.currentFailures, test)
    71  			}
    72  			r.runTests[test] = struct{}{}
    73  		}
    74  	}
    75  }