<commit_before>require File.dirname(__FILE__) + '/../test_helper'

# Integration tests
class AdapterTest < Test::Unit::TestCase

  # quick hack to load adapter-specific tests - TODO: refactor
  # this also allows to run the same tests for mysql and mysql2
  adapter_tests = ENV['DB']
  raise "Missing DB environment variable" unless adapter_tests
  adapter_tests = 'mysql' if adapter_tests == 'mysql2'
  require File.dirname(__FILE__) + "/#{adapter_tests}_tests"
  include "#{adapter_tests.capitalize}Tests".constantize
  # end of hack

  def setup
    raise "Missing required DB environment variable" unless ENV['DB']
    configs = YAML.load_file(File.dirname(__FILE__)+ '/../config/database.yml')
    raise "Configuration #{ENV['DB']} not in database.yml!" unless configs[ENV['DB']]
    ActiveRecord::Base.configurations = configs
    ActiveRecord::Base.establish_connection(ENV['DB'])

  end

  def select_value(query)
    value = connection.select_value(query)
    value = Integer(value) if ENV['DB'] =~ /postgresql/
    value
  end
  
  def test_add_select_into_table
    new_table_name = 'new_people'
    sql_query = 'select * from people'
    assert_equal "CREATE TABLE #{new_table_name} #{sql_query}",
      connection.add_select_into_table(new_table_name, sql_query)
  end

  def test_truncate
    connection.delete("delete from truncate_test")
    %w|a b c|.each do |value|
      connection.execute("insert into truncate_test (x) values ('#{value}')")
    end
    <commit_msg>First fix to allow LOAD DATA LOCAL INFILE to work.<commit_after>require File.dirname(__FILE__) + '/../test_helper'

# Integration tests
class AdapterTest < Test::Unit::TestCase

  # quick hack to load adapter-specific tests - TODO: refactor
  # this also allows to run the same tests for mysql and mysql2
  adapter_tests = ENV['DB']
  raise "Missing DB environment variable" unless adapter_tests
  adapter_tests = 'mysql' if adapter_tests == 'mysql2'
  require File.dirname(__FILE__) + "/#{adapter_tests}_tests"
  include "#{adapter_tests.capitalize}Tests".constantize
  # end of hack

  def setup
    raise "Missing required DB environment variable" unless ENV['DB']
    configs = YAML.load_file(File.dirname(__FILE__)+ '/../config/database.yml')
    raise "Configuration #{ENV['DB']} not in database.yml!" unless configs[ENV['DB']]
    ActiveRecord::Base.configurations = configs
    ActiveRecord::Base.establish_connection(ENV['DB'])

    # current fix to allow bulk load. this needs more work
    # to enable it only at bulk load time if possible
    Mysql2::Client.default_query_options[:connect_flags] |= Mysql2::Client::LOCAL_FILES
  end

  def select_value(query)
    value = connection.select_value(query)
    value = Integer(value) if ENV['DB'] =~ /postgresql/
    value
  end
  
  def test_add_select_into_table
    new_table_name = 'new_people'
    sql_query = 'select * from people'
    assert_equal "CREATE TABLE #{new_table_name} #{sql_query}",
      connection.add_select_into_table(new_table_name, sql_query)
  end

  def test_truncate
    connection.delete("delete from truncate_test")
    %w|a b c|.each do |value|
      connection.execute("insert into truncate_test (x) values ('#{value}')")
    end
    
{'fraction_non_alphanumeric': 0.11090342679127727, 'fraction_numerical': 0.001869158878504673, 'mean_word_length': 4.298679867986799, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3846465', 'n_tokens_mistral': 993, 'n_tokens_neox': 970, 'n_words': 269}