<commit_before>require File.dirname(__FILE__) + '/../lib/data_mapper'
require File.dirname(__FILE__) + '/mock_adapter'
require 'yaml'
require 'pp'

log_path = File.dirname(__FILE__) + '/../spec.log'

require 'fileutils'
FileUtils::rm log_path if File.exists?(log_path)

adapter = ENV['ADAPTER'] || 'sqlite3'
configuration_options = {
  :adapter => adapter,
  :log_stream => 'spec.log',
  :log_level => Logger::DEBUG,
  :database =>  ENV['DATABASE'] || (adapter == 'sqlite3' ? ':memory:' : 'data_mapper_1'),
  :single_threaded => false
}

case adapter
  when 'postgresql' then
    configuration_options[:username] = ENV['USERNAME'] || 'postgres'
  when 'mysql' then
    configuration_options[:username] = 'root'
  when 'sqlite3' then
    configuration_options[:database] << '.db'
end

def load_models
  Dir[File.dirname(__FILE__) + '/models/*.rb'].sort.each do |path|
    load path
  end
end

DataMapper::Database.setup(:default, configuration_options)

database do |db|
  load_models
  DataMapper::Base::auto_migrate!
end

mock_db = DataMapper::Database.setup(:mock, {})
mock_db.adapter = MockAdapter.new(mock_db)
database(:mock) { load_models }

at_exit do
  database do |db|
    db.schema.each do |table|
      db.drop_table(table.klass)
    end
  end
end if ENV['DROP'] == '1'

# Define a fixtures helper method to load up our test data.
def fixtures(name, force = false)
  entry = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{name}.yaml")<commit_msg>default spec runner now uses in-memory database:<commit_after>require File.dirname(__FILE__) + '/../lib/data_mapper'
require File.dirname(__FILE__) + '/mock_adapter'
require 'yaml'
require 'pp'

log_path = File.dirname(__FILE__) + '/../spec.log'

require 'fileutils'
FileUtils::rm log_path if File.exists?(log_path)

adapter = ENV['ADAPTER'] || 'sqlite3'
configuration_options = {
  :adapter => adapter,
  :log_stream => 'spec.log',
  :log_level => Logger::DEBUG,
  :database =>  ENV['DATABASE'] || (adapter == 'sqlite3' ? ':memory:' : 'data_mapper_1'),
  :single_threaded => false
}

case adapter
  when 'postgresql' then
    configuration_options[:username] = ENV['USERNAME'] || 'postgres'
  when 'mysql' then
    configuration_options[:username] = 'root'
  when 'sqlite3' then
    configuration_options[:database] << '.db' if configuration_options[:database] != ':memory:'
end

def load_models
  Dir[File.dirname(__FILE__) + '/models/*.rb'].sort.each do |path|
    load path
  end
end

DataMapper::Database.setup(:default, configuration_options)

database do |db|
  load_models
  DataMapper::Base::auto_migrate!
end

mock_db = DataMapper::Database.setup(:mock, {})
mock_db.adapter = MockAdapter.new(mock_db)
database(:mock) { load_models }

at_exit do
  database do |db|
    db.schema.each do |table|
      db.drop_table(table.klass)
    end
  end
end if ENV['DROP'] == '1'

# Define a fixtures helper method to load up our test data.
def fixtures(name, force = false)
  entry = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{name}.yaml")
{'fraction_non_alphanumeric': 0.15244104948522086, 'fraction_numerical': 0.0033211557622052474, 'mean_word_length': 4.837209302325581, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1636018', 'n_tokens_mistral': 1018, 'n_tokens_neox': 1014, 'n_words': 234}