<commit_before>module Maximus
  # @since 0.1.0
  class Wraith < Maximus::Statistic

    # Generates screenshots for visual regression testing
    # @see Statistic#initialize
    def result

      return if @settings[:wraith].blank?

      node_module_exists('phantomjs', 'brew install')

      puts 'Starting visual regression tests with wraith...'.color(:blue)

      # Run history or latest depending on the existence of a history directory as defined
      #   in each wraith config file.
      #
      # @todo this doesn't work very well. It puts the new shots in the history folder,
      #   even with absolute paths. Could be a bug in wraith
      #
      # @yieldparam browser [String] headless browser name
      # @yieldparam configpath [String] path to temp config file (see Config#wraith_setup)
      @settings[:wraith].each do |browser, configpath|
        wraith_yaml = YAML.load_file(configpath)
        if File.directory?("#{@settings[:root_dir]}/#{wraith_yaml['history_dir']}")
          puts `wraith latest #{configpath}`
        else
          puts `wraith history #{configpath}`
        end
        File.write('said.yml', wraith_yaml.to_yaml)
        File.delete(configpath)
        wraith_parse browser
      end

    end


    private

      # Get a diff percentage of all changes by label and screensize
      #
      # @example {:statistics=>{:/=>{:percent_changed=>[{1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}] } }}
      # @param browser [String] headless browser used to generate the gallery
      # @return [Hash] { path: { percent_changed: [{ size: percent_diff }] } }
      def wraith_parse(browser)
        Dir.glob("#{@settings[:root_dir]}/maximus_wraith_#{browser}/**/*.txt").select { |f| File.file? f }.each do |file|
          file_object = File.open(file, 'rb')
          orig_label = File.dirname(file).split('/').last
          label = @settings[:paths][orig_label]
          @output[:statistics][browser.to_sym] ||= {}
          @output[:statistics][browser.to_sym][label.to_sym] ||= {}
          browser_output = @output[:statistics][browser.to_sym][label.to_sym]
          browser_output ||= {}
          browser_output[:name] = orig_label
          browser_output[:percent_changed] ||= []
          browser_output[:percent_changed] << { File.basename(file).split('_')[0].to_i => file_object.read.to_f }
          file_object.close
        end
        @output
      end

  end
end
<commit_msg>remove test file write<commit_after>module Maximus
  # @since 0.1.0
  class Wraith < Maximus::Statistic

    # Generates screenshots for visual regression testing
    # @see Statistic#initialize
    def result

      return if @settings[:wraith].blank?

      node_module_exists('phantomjs', 'brew install')

      puts 'Starting visual regression tests with wraith...'.color(:blue)

      # Run history or latest depending on the existence of a history directory as defined
      #   in each wraith config file.
      #
      # @todo this doesn't work very well. It puts the new shots in the history folder,
      #   even with absolute paths. Could be a bug in wraith
      #
      # @yieldparam browser [String] headless browser name
      # @yieldparam configpath [String] path to temp config file (see Config#wraith_setup)
      @settings[:wraith].each do |browser, configpath|
        wraith_yaml = YAML.load_file(configpath)
        if File.directory?("#{@settings[:root_dir]}/#{wraith_yaml['history_dir']}")
          puts `wraith latest #{configpath}`
        else
          puts `wraith history #{configpath}`
        end
        File.delete(configpath)
        wraith_parse browser
      end

    end


    private

      # Get a diff percentage of all changes by label and screensize
      #
      # @example {:statistics=>{:/=>{:percent_changed=>[{1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}, {1024=>0.0}, {767=>0.0}] } }}
      # @param browser [String] headless browser used to generate the gallery
      # @return [Hash] { path: { percent_changed: [{ size: percent_diff }] } }
      def wraith_parse(browser)
        Dir.glob("#{@settings[:root_dir]}/maximus_wraith_#{browser}/**/*.txt").select { |f| File.file? f }.each do |file|
          file_object = File.open(file, 'rb')
          orig_label = File.dirname(file).split('/').last
          label = @settings[:paths][orig_label]
          @output[:statistics][browser.to_sym] ||= {}
          @output[:statistics][browser.to_sym][label.to_sym] ||= {}
          browser_output = @output[:statistics][browser.to_sym][label.to_sym]
          browser_output ||= {}
          browser_output[:name] = orig_label
          browser_output[:percent_changed] ||= []
          browser_output[:percent_changed] << { File.basename(file).split('_')[0].to_i => file_object.read.to_f }
          file_object.close
        end
        @output
      end

  end
end

{'fraction_non_alphanumeric': 0.13576494427558258, 'fraction_numerical': 0.019452887537993922, 'mean_word_length': 2.823392718822618, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '3929962', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1506, 'n_words': 371}