<commit_before># encoding: utf-8
require 'book_test_helper'

class BookTest < Test::Unit::TestCase
  include BookTestHelper

  def assert_same_path(expected, result, *options)
    require 'pathname'
    ex_path = Pathname(expected).realpath
    re_path = Pathname(result).realpath
    assert_equal ex_path, re_path, *options
  end

  def test_s_load_default
    Dir.mktmpdir do |dir|
      File.open(File.join(dir, 'CHAPS'), 'w') {}
      Dir.chdir(dir) do
        assert_same_path dir, File.expand_path(Book.load_default.basedir), "error in dir CHAPS"
      end
    end

    # tests for ReVIEW.book
    default_book = nil
    Dir.mktmpdir do |dir|
      Dir.chdir(dir) do
        default_book = ReVIEW.book
        assert default_book
      end
    end
    Dir.mktmpdir do |dir|
      Dir.chdir(dir) do
        assert_equal default_book, ReVIEW.book, "chdir mktmpdir"
      end
    end
  end

  def test_s_update_rubyenv
    save_load_path = $LOAD_PATH.dup

    Dir.mktmpdir do |dir|
      Book.update_rubyenv(dir)
      assert_equal save_load_path, $LOAD_PATH
    end

    Dir.mktmpdir do |dir|
      local_lib_path = File.join(dir, 'lib')
      Dir.mkdir(local_lib_path)
      Book.update_rubyenv(dir)
      assert_equal save_load_path, $LOAD_PATH<commit_msg>fix test; ReVIEW.book should not be used<commit_after># encoding: utf-8
require 'book_test_helper'

class BookTest < Test::Unit::TestCase
  include BookTestHelper

  def assert_same_path(expected, result, *options)
    require 'pathname'
    ex_path = Pathname(expected).realpath
    re_path = Pathname(result).realpath
    assert_equal ex_path, re_path, *options
  end

  def test_s_load_default
    Dir.mktmpdir do |dir|
      File.open(File.join(dir, 'CHAPS'), 'w') {}
      Dir.chdir(dir) do
        assert_same_path dir, File.expand_path(Book.load_default.basedir), "error in dir CHAPS"
      end
    end
  end

  def test_s_update_rubyenv
    save_load_path = $LOAD_PATH.dup

    Dir.mktmpdir do |dir|
      Book.update_rubyenv(dir)
      assert_equal save_load_path, $LOAD_PATH
    end

    Dir.mktmpdir do |dir|
      local_lib_path = File.join(dir, 'lib')
      Dir.mkdir(local_lib_path)
      Book.update_rubyenv(dir)
      assert_equal save_load_path, $LOAD_PATH
{'fraction_non_alphanumeric': 0.09038031319910514, 'fraction_numerical': 0.0008948545861297539, 'mean_word_length': 3.1484230055658626, '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': '6298344', 'n_tokens_mistral': 808, 'n_tokens_neox': 784, 'n_words': 169}