<commit_before># -*- coding: utf-8 -*-
#damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
# Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
# zum Testen eignete.
#
#--
# these test cases were developed to run under Linux OS, some commands
# (like 'diff') must be changed (or commented out ;-)) if you want to run
# the tests under another OS
#


#TODO
# Look at formulas in excel - does not work with date/time


# Dump warnings that come from the test to open files
# with the wrong spreadsheet class
STDERR.reopen "/dev/null","w" unless $0 == __FILE__

TESTDIR =  File.dirname(__FILE__) 
require TESTDIR + '/test_helper.rb'
#require 'soap/rpc/driver'
require 'fileutils'
require 'timeout'
require 'logger'
$log = Logger.new(File.join(ENV['HOME'],"roo.log"))
$log.level = Logger::WARN
#$log.level = Logger::DEBUG

DISPLAY_LOG = false
DB_LOG = false

if DB_LOG
  require 'activerecord'
end

include FileUtils

if DB_LOG
  def activerecord_connect
    ActiveRecord::Base.establish_connection(:adapter => "mysql",
      :database => "test_runs",
      :host => "localhost",
      :username => "root",
      :socket => "/var/run/mysqld/mysqld.sock")
  end

  class Testrun < ActiveRecord::Base
  end
end

class Test::Unit::TestCase
  def key_of(spreadsheetname)
    begin
      
      return {
        'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
        "write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
        'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
        'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
        'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
        'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
        "only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
        'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
        'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
        'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ"
      }[spreadsheetname]
        # 'numbers1' => "o10837434939102457526.4784396906364855777",
        # 'borders' => "o10837434939102457526.664868920231926255",
        # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
        # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
        # "only_one_sheet" => "o10837434939102457526.762705759906130135",
        # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
        # 'formula' => 'o10837434939102457526.3022866619437760118',
        # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
        # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
    rescue
      raise "unknown spreadsheetname: #{spreadsheetname}"
    end
  end

  if DB_LOG
    if ! (defined?(@connected) and @connected)
      activerecord_connect
    else
      @connected = true
    end
  end
  alias unlogged_run run
  def run(result, &block)
    t1 = Time.now
    #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
    if DISPLAY_LOG
      print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
      STDOUT.flush
    end
    unlogged_run result, &block
    t2 = Time.now
    if DISPLAY_LOG
      puts "\t#{t2-t1} seconds"
    end
    if DB_LOG
      domain = Testrun.create(
        :class_name => self.class.to_s,
        :test_name => @method_name,
        :start => t1,
        :duration => t2-t1
      )
    end
  end
end

class File
  def File.delete_if_exist(filename)
    if File.exist?(filename)
      File.delete(filename)
    end
  end
end

# :nodoc
class Fixnum
  def minutes
    self * 60
  end
end

class TestRoo < Test::Unit::TestCase

  OPENOFFICE   = true  	# do Openoffice-Spreadsheet Tests?
  EXCEL        = true	  # do Excel Tests?
  GOOGLE       = false 	  # do Google-Spreadsheet Tests?
  EXCELX       = true  	# do Excel-X Tests? (.xlsx-files)
  EXCEL2003XML = true     # do MS2003 XML tests

  ONLINE = true
  LONG_RUN = true

  def test_internal_minutes
    assert_equal 42*60, 42.minutes
  end
  
  # call a block of code for each spreadsheet type 
  # and yield a reference to the roo object
  def with_each_spreadsheet(options)
     options[:format] ||= [:excel, :excelx, :excel2003xml, :openoffice, :google]
     options[:format] = [options[:format]] if Symbol === options[:format]
     if options[:ignore]
       if Symbol === options[:ignore]
         options[:format] = (options[:format] - [options[:ignore]]) 
       else
         options[:format] = (options[:format] - options[:ignore]) 
       end
     end
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xml')) if EXCEL2003XML && options[:format].include?(:excel2003xml)
     yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
  end

  def with_public_google_spreadsheet(&block)
    user = ENV['GOOGLE_MAIL']
    pass = ENV['<PASSWORD>']
    ENV['GOOGLE_MAIL'] = ''
    ENV['GOOGLE_PASSWORD'] = ''<commit_msg>Drop minutes test helper, which we're no longer using<commit_after># -*- coding: utf-8 -*-
#damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
# Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
# zum Testen eignete.
#
#--
# these test cases were developed to run under Linux OS, some commands
# (like 'diff') must be changed (or commented out ;-)) if you want to run
# the tests under another OS
#


#TODO
# Look at formulas in excel - does not work with date/time


# Dump warnings that come from the test to open files
# with the wrong spreadsheet class
STDERR.reopen "/dev/null","w" unless $0 == __FILE__

TESTDIR =  File.dirname(__FILE__) 
require TESTDIR + '/test_helper.rb'
#require 'soap/rpc/driver'
require 'fileutils'
require 'timeout'
require 'logger'
$log = Logger.new(File.join(ENV['HOME'],"roo.log"))
$log.level = Logger::WARN
#$log.level = Logger::DEBUG

DISPLAY_LOG = false
DB_LOG = false

if DB_LOG
  require 'activerecord'
end

include FileUtils

if DB_LOG
  def activerecord_connect
    ActiveRecord::Base.establish_connection(:adapter => "mysql",
      :database => "test_runs",
      :host => "localhost",
      :username => "root",
      :socket => "/var/run/mysqld/mysqld.sock")
  end

  class Testrun < ActiveRecord::Base
  end
end

class Test::Unit::TestCase
  def key_of(spreadsheetname)
    begin
      
      return {
        'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
        "write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
        'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
        'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
        'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
        'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
        "only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
        'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
        'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
        'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ"
      }[spreadsheetname]
        # 'numbers1' => "o10837434939102457526.4784396906364855777",
        # 'borders' => "o10837434939102457526.664868920231926255",
        # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
        # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
        # "only_one_sheet" => "o10837434939102457526.762705759906130135",
        # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
        # 'formula' => 'o10837434939102457526.3022866619437760118',
        # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
        # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
    rescue
      raise "unknown spreadsheetname: #{spreadsheetname}"
    end
  end

  if DB_LOG
    if ! (defined?(@connected) and @connected)
      activerecord_connect
    else
      @connected = true
    end
  end
  alias unlogged_run run
  def run(result, &block)
    t1 = Time.now
    #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
    if DISPLAY_LOG
      print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
      STDOUT.flush
    end
    unlogged_run result, &block
    t2 = Time.now
    if DISPLAY_LOG
      puts "\t#{t2-t1} seconds"
    end
    if DB_LOG
      domain = Testrun.create(
        :class_name => self.class.to_s,
        :test_name => @method_name,
        :start => t1,
        :duration => t2-t1
      )
    end
  end
end

class File
  def File.delete_if_exist(filename)
    if File.exist?(filename)
      File.delete(filename)
    end
  end
end

class TestRoo < Test::Unit::TestCase

  OPENOFFICE   = true  	# do Openoffice-Spreadsheet Tests?
  EXCEL        = true	  # do Excel Tests?
  GOOGLE       = false 	  # do Google-Spreadsheet Tests?
  EXCELX       = true  	# do Excel-X Tests? (.xlsx-files)
  EXCEL2003XML = true     # do MS2003 XML tests

  ONLINE = true
  LONG_RUN = true

  # call a block of code for each spreadsheet type 
  # and yield a reference to the roo object
  def with_each_spreadsheet(options)
     options[:format] ||= [:excel, :excelx, :excel2003xml, :openoffice, :google]
     options[:format] = [options[:format]] if Symbol === options[:format]
     if options[:ignore]
       if Symbol === options[:ignore]
         options[:format] = (options[:format] - [options[:ignore]]) 
       else
         options[:format] = (options[:format] - options[:ignore]) 
       end
     end
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
     yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xml')) if EXCEL2003XML && options[:format].include?(:excel2003xml)
     yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
  end

  def with_public_google_spreadsheet(&block)
    user = ENV['GOOGLE_MAIL']
    pass = ENV['<PASSWORD>']
    ENV['GOOGLE_MAIL'] = ''
    ENV['GOOGLE_PASSWORD'] = ''
{'fraction_non_alphanumeric': 0.12913563955132434, 'fraction_numerical': 0.0433594118201527, 'mean_word_length': 3.4598570828079023, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '5957049', 'n_tokens_mistral': 4186, 'n_tokens_neox': 3827, 'n_words': 823}