<commit_before>def use_fixtures
  copy_fixtures_to_tmp
  stub_directories
end

# copy files to a temporary directory and use this directory as a
# fixtures directory, so were are sure that the fixtures are 'reset'.
def copy_fixtures_to_tmp
  FileUtils.rm_r  "#{ETSource.root}/tmp/fixtures" , force: true
  FileUtils.mkdir "#{ETSource.root}/tmp/fixtures"
  FileUtils.cp_r  "#{ETSource.root}/spec/fixtures", "#{ETSource.root}/tmp"
end

# Stub out all the directories of classes that have a DIRECTORY constant
# to use the fixtures directory.
def stub_directories
  ETSource.constants.each do |constant_name|
    if defined?(ETSource.const_get(constant_name)::DIRECTORY)
      directory = ETSource.const_get(constant_name)::DIRECTORY.gsub(/^data\//,'')
      unless directory.match /tmp\/fixtures/
        stub_const("ETSource::#{constant_name}::DIRECTORY",
                   "tmp/fixtures/#{directory}")
      end
    end
  end
end<commit_msg>Create the tmp/ directory when running tests.<commit_after>def use_fixtures
  copy_fixtures_to_tmp
  stub_directories
end

# copy files to a temporary directory and use this directory as a
# fixtures directory, so were are sure that the fixtures are 'reset'.
def copy_fixtures_to_tmp
  FileUtils.rm_r    "#{ETSource.root}/tmp/fixtures" , force: true
  FileUtils.mkdir_p "#{ETSource.root}/tmp/fixtures"
  FileUtils.cp_r    "#{ETSource.root}/spec/fixtures", "#{ETSource.root}/tmp"
end

# Stub out all the directories of classes that have a DIRECTORY constant
# to use the fixtures directory.
def stub_directories
  ETSource.constants.each do |constant_name|
    if defined?(ETSource.const_get(constant_name)::DIRECTORY)
      directory = ETSource.const_get(constant_name)::DIRECTORY.gsub(/^data\//,'')
      unless directory.match /tmp\/fixtures/
        stub_const("ETSource::#{constant_name}::DIRECTORY",
                   "tmp/fixtures/#{directory}")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10718002081165452, 'fraction_numerical': 0.0, 'mean_word_length': 4.073878627968337, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2453750', 'n_tokens_mistral': 608, 'n_tokens_neox': 611, 'n_words': 155}