<commit_before># A Mixin for the analysis of Python build files. Supports unittest, tox

module PythonLogFileAnalyzer
  attr_reader :tests_failed, :test_duration, :reactor_lines, :pure_build_duration

  def init
    @reactor_lines = Array.new
    @tests_failed_lines = Array.new
    @tests_failed = Array.new
    @analyzer = 'python'
    @verbose = false
    @has_summary = false
  end

  def custom_analyze
    extract_tests
    analyze_tests
  end

  def extract_tests
    test_section_started = false

    # TODO (MMB) Possible future improvement: We could even get all executed tests (also the ones which succeed)
    @folds[@OUT_OF_FOLD].content.each do |line|
      if !(line =~ /Ran .* tests? in /).nil?
        @has_summary = true
      end
    end

    if @test_lines.empty?
      @test_lines = @folds[@OUT_OF_FOLD].content
    end
  end

  def setup_python_tests
    unless @init_tests
      init_tests
      @tests_run = true
    end
  end

  def analyze_tests
    @test_lines.each do |line|
      if !(line =~ /Ran (\d+) tests? in (.+s)/).nil?
        # Matches the test summary, i.e. "Ran 3 tests in 0.000s"
        setup_python_tests
        add_framework 'unittest'
        @num_tests_run = $1.to_i
        @test_duration += convert_plain_time_to_seconds $2
        has_summary = true
      elsif !(line =~ /FAIL: (\S+)/).nil?
        # Matches the likes of FAIL: test_em (__main__.TestMarkdownPy)
        setup_python_tests
        @tests_failed.push($1) unless $1.nil?
      end
    end
    uninit_ok_tests
  end

  def tests_failed?
    return !@tests_failed.empty? || (!@num_tests_failed.nil? && @num_tests_failed > 0)
  end

end<commit_msg>Python: Add forcing passed tests<commit_after># A Mixin for the analysis of Python build files. Supports unittest, tox

module PythonLogFileAnalyzer
  attr_reader :tests_failed, :test_duration, :reactor_lines, :pure_build_duration

  def init
    @reactor_lines = Array.new
    @tests_failed_lines = Array.new
    @tests_failed = Array.new
    @analyzer = 'python'
    @verbose = false
    @has_summary = false
  end

  def custom_analyze
    extract_tests
    analyze_tests
  end

  def extract_tests
    test_section_started = false

    # TODO (MMB) Possible future improvement: We could even get all executed tests (also the ones which succeed)
    @folds[@OUT_OF_FOLD].content.each do |line|
      if !(line =~ /Ran .* tests? in /).nil?
        @has_summary = true
      end
    end

    if @test_lines.empty?
      @test_lines = @folds[@OUT_OF_FOLD].content
    end
  end

  def setup_python_tests
    unless @init_tests
      init_tests
      @tests_run = true
      @force_tests_passed = false
    end
  end

  def analyze_tests
    @test_lines.each do |line|
      if !(line =~ /Ran (\d+) tests? in (.+s)/).nil?
        # Matches the test summary, i.e. "Ran 3 tests in 0.000s"
        setup_python_tests
        add_framework 'unittest'
        @num_tests_run = $1.to_i
        @test_duration += convert_plain_time_to_seconds $2
        @has_summary = true
      elsif !(line =~ /^OK /).nil? and @has_summary
        # This is a somewhat dangerous thing to do as "OK" might be a common line in builds. We mititgate the risk somewhat by having seen a summary
        # TODO we can make this more clever by checking only AFTER a summary
        setup_python_tests
        # If we see this, we know that the overall result was that tests passed
        @force_tests_passed = true
        puts $2
      elsif !(line =~ /FAIL: (\S+)/).nil?
        # Matches the likes of FAIL: test_em (__main__.TestMarkdownPy)
        setup_python_tests
        @tests_failed.push($1) unless $1.nil?
      end
    end
    uninit_ok_tests
  end

  def tests_failed?
    return !@force_tests_passed || !@tests_failed.empty? || (!@num_tests_failed.nil? && @num_tests_failed > 0)
  end

end
{'fraction_non_alphanumeric': 0.08894105372978613, 'fraction_numerical': 0.005477308294209703, 'mean_word_length': 2.701737451737452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2354218', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1251, 'n_words': 369}