<commit_before># This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2011, <NAME>

require 'fixtures'
require 'helper'

class TestGitHub < Test::Unit::TestCase

  context 'The GitHub implementation' do

    should 'not support file stats' do
      assert_not Metior::GitHub.supports? :file_stats
    end

    should 'not support line stats' do
      assert_not Metior::GitHub.supports? :line_stats
    end

  end

  context 'A GitHub repository' do

    setup do
      @repo = Metior::GitHub::Repository.new 'mojombo', 'grit'

      api_response = Fixtures.commits_as_rashies(''..'master')
      @commits_stub = Octokit.stubs :commits
      14.times { @commits_stub.returns api_response.shift(35) }
      @commits_stub.then.raises Octokit::NotFound.new(nil)
    end

    should 'be able to load all commits from the repository\'s default branch' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      commits = @repo.commits
      assert_equal 460, commits.size
      assert commits.all? { |commit| commit.is_a? Metior::GitHub::Commit }

      head = commits.first
      assert_equal '1b2fe77', head.id
    end

    should 'be able to load a range of commits from the repository' do
      @commits_stub = Octokit.stubs :commits
      api_response = Fixtures.commits_as_rashies('ef2870b'..'4c592b4')
      @commits_stub.returns api_response
      @commits_stub.raises Octokit::NotFound.new(nil)

      commits = @repo.commits 'ef2870b'..'4c592b4'
      assert_equal 6, commits.size
      assert commits.all? { |commit| commit.is_a? Metior::GitHub::Commit }
      assert_equal '4c592b4', commits.first.id
      assert_equal 'f0cc7f7', commits.last.id
    end

    should 'know the authors of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      authors = @repo.authors
      assert_equal 37, authors.size
      assert authors.values.all? { |author| author.is_a? Metior::GitHub::Actor }

      assert_equal %w{
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL>.(none) <EMAIL> <EMAIL>
      }, authors.keys.sort
    end

    should 'know the committers of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      committers = @repo.committers
      assert_equal 29, committers.size
      assert committers.values.all? { |committer| committer.is_a? Metior::GitHub::Actor }

      assert_equal %w{
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL> <EMAIL>.(none)
         <EMAIL>
      }, committers.keys.sort
    end

    should 'know the top authors of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      authors = @repo.top_authors
      assert_equal 3, authors.size
      assert authors.all? { |author| author.is_a? Metior::GitHub::Actor }

      assert_equal [
        "<EMAIL>", "<EMAIL>", "<EMAIL>"
      ], authors.collect { |author| author.id }
    end

    should 'not be able to get file stats of a repository' do
      assert_raises UnsupportedError do
        @repo.file_stats
      end
    end

    should 'not be able to get the most significant authors of a repository' do
      assert_raises UnsupportedError do
        @repo.significant_authors
      end
    end

    should 'not be able to get the most significant commits of a repository' do
      assert_raises UnsupportedError do
        @repo.significant_commits
      end
    end

    should 'provide easy access to simple repository statistics' do
      Metior::GitHub::Repository.any_instance.expects(:id_for_ref).twice.
        with('master').returns('1b2fe77')

      stats = Metior.simple_stats :github, 'mojombo', 'grit'

      assert_equal 157, stats[:active_days].size
      assert_equal 460, stats[:commit_count]
      assert_in_delta 2.92993630573248, stats[:commits_per_active_day], 0.0001
      assert_equal Time.at(1191997100), stats[:first_commit_date]
      assert_equal Time.at(1306794294), stats[:last_commit_date]
      assert_equal 5, stats[:top_contributors].size
    end

    should 'be able to load all the branches of a repository' do
      branches = {
        'master' => '1b2fe77',
        'branch1' => '1234567',
        'branch2' => '0abcdef'
      }
      Octokit.expects(:branches).with('mojombo/grit').once.returns(branches)

      assert_equal %w{master branch1 branch2}, @repo.branches
      assert_equal branches, @repo.instance_variable_get(:@refs)
    end
<commit_msg>Fixed simple stats test case for GitHub<commit_after># This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2011, <NAME>

require 'fixtures'
require 'helper'

class TestGitHub < Test::Unit::TestCase

  context 'The GitHub implementation' do

    should 'not support file stats' do
      assert_not Metior::GitHub.supports? :file_stats
    end

    should 'not support line stats' do
      assert_not Metior::GitHub.supports? :line_stats
    end

  end

  context 'A GitHub repository' do

    setup do
      @repo = Metior::GitHub::Repository.new 'mojombo', 'grit'

      api_response = Fixtures.commits_as_rashies(''..'master')
      @commits_stub = Octokit.stubs :commits
      14.times { @commits_stub.returns api_response.shift(35) }
      @commits_stub.then.raises Octokit::NotFound.new(nil)
    end

    should 'be able to load all commits from the repository\'s default branch' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      commits = @repo.commits
      assert_equal 460, commits.size
      assert commits.all? { |commit| commit.is_a? Metior::GitHub::Commit }

      head = commits.first
      assert_equal '1b2fe77', head.id
    end

    should 'be able to load a range of commits from the repository' do
      @commits_stub = Octokit.stubs :commits
      api_response = Fixtures.commits_as_rashies('ef2870b'..'4c592b4')
      @commits_stub.returns api_response
      @commits_stub.raises Octokit::NotFound.new(nil)

      commits = @repo.commits 'ef2870b'..'4c592b4'
      assert_equal 6, commits.size
      assert commits.all? { |commit| commit.is_a? Metior::GitHub::Commit }
      assert_equal '4c592b4', commits.first.id
      assert_equal 'f0cc7f7', commits.last.id
    end

    should 'know the authors of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      authors = @repo.authors
      assert_equal 37, authors.size
      assert authors.values.all? { |author| author.is_a? Metior::GitHub::Actor }

      assert_equal %w{
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL> <EMAIL>
        <EMAIL> <EMAIL>.(none) <EMAIL> <EMAIL>
      }, authors.keys.sort
    end

    should 'know the committers of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      committers = @repo.committers
      assert_equal 29, committers.size
      assert committers.values.all? { |committer| committer.is_a? Metior::GitHub::Actor }

      assert_equal %w{
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL>
         <EMAIL> <EMAIL> <EMAIL> <EMAIL>.(none)
         <EMAIL>
      }, committers.keys.sort
    end

    should 'know the top authors of the repository' do
      @repo.expects(:id_for_ref).with('master').once.returns('1b2fe77')

      authors = @repo.top_authors
      assert_equal 3, authors.size
      assert authors.all? { |author| author.is_a? Metior::GitHub::Actor }

      assert_equal [
        "<EMAIL>", "<EMAIL>", "<EMAIL>"
      ], authors.collect { |author| author.id }
    end

    should 'not be able to get file stats of a repository' do
      assert_raises UnsupportedError do
        @repo.file_stats
      end
    end

    should 'not be able to get the most significant authors of a repository' do
      assert_raises UnsupportedError do
        @repo.significant_authors
      end
    end

    should 'not be able to get the most significant commits of a repository' do
      assert_raises UnsupportedError do
        @repo.significant_commits
      end
    end

    should 'provide easy access to simple repository statistics' do
      Metior::GitHub::Repository.any_instance.expects(:id_for_ref).twice.
        with('master').returns('1b2fe77')

      stats = Metior.simple_stats :github, 'mojombo/grit'

      assert_equal 157, stats[:active_days].size
      assert_equal 460, stats[:commit_count]
      assert_in_delta 2.92993630573248, stats[:commits_per_active_day], 0.0001
      assert_equal Time.at(1191997100), stats[:first_commit_date]
      assert_equal Time.at(1306794294), stats[:last_commit_date]
      assert_equal 5, stats[:top_contributors].size
    end

    should 'be able to load all the branches of a repository' do
      branches = {
        'master' => '1b2fe77',
        'branch1' => '1234567',
        'branch2' => '0abcdef'
      }
      Octokit.expects(:branches).with('mojombo/grit').once.returns(branches)

      assert_equal %w{master branch1 branch2}, @repo.branches
      assert_equal branches, @repo.instance_variable_get(:@refs)
    end

{'fraction_non_alphanumeric': 0.11664212076583211, 'fraction_numerical': 0.025527736867943053, 'mean_word_length': 2.9161860822760475, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 149, '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': '7419453', 'n_tokens_mistral': 3637, 'n_tokens_neox': 3395, 'n_words': 831}