<commit_before>require 'test_helper'

class EverypoliticianTest < Minitest::Test
  # Clear the countries.json cache before each run
  def setup
    Everypolitician.countries = nil
  end

  def test_legislative_periods
    VCR.use_cassette('countries_json') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      lp = au_senate.legislative_periods.first
      assert_equal 'term/44', lp.id
      assert_equal '44th Parliament', lp.name
      assert_equal Date.new(2013, 9, 7), lp.start_date
      assert_equal '44', lp.slug
      assert %r{https://raw.githubusercontent.com/everypolitician/everypolitician-data/\w+?/data/Australia/Senate/term-44.csv}.match(lp.csv_url)
      assert_equal 'Senate', lp.legislature.name
      assert_equal 'Australia', lp.country.name
    end
  end

  def test_legislative_period_csv
    VCR.use_cassette('term-44-csv') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      lp = au_senate.legislative_periods.first
      csv = lp.csv
      assert_instance_of CSV::Table, csv
    end
  end

  def test_legislative_period_square_brackets_expose_raw_data
    VCR.use_cassette('countries_json') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      lp = au_senate.legislative_periods.first
      assert_equal 'term/44', lp[:id]
      assert_equal '44th Parliament', lp[:name]
      assert_equal '2013-09-07', lp[:start_date]
      assert_equal 'data/Australia/Senate/term-44.csv', lp[:csv]
    end
  end

  def test_legislative_period_end_date
    VCR.use_cassette('countries_json') do
      lp = Everypolitician.country(slug: 'Australia').legislature(slug: 'Representatives').legislative_periods[1]
      assert_equal Date.new(2013, 9, 7), lp.end_date
    end
  end

  def test_missing_legislative_period_end_date
    VCR.use_cassette('countries_json') do
      lp = Everypolitician.country(slug: 'Australia').legislature(slug: 'Representatives').legislative_periods.first
      assert_nil lp.end_date
    end
  end

  def test_partial_dates
    VCR.use_cassette('countries_json') do
      af = Everypolitician.country(slug: 'Albania').legislature(slug: 'Assembly')
      lp = af.legislative_periods.last
      assert_equal Date.new(2009), lp.start_date
      assert_equal Date.new(2013), lp.end_date
    end
  end
end<commit_msg>Rename lp to something more readable<commit_after>require 'test_helper'

class EverypoliticianTest < Minitest::Test
  # Clear the countries.json cache before each run
  def setup
    Everypolitician.countries = nil
  end

  def test_legislative_periods
    VCR.use_cassette('countries_json') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      term = au_senate.legislative_periods.first
      assert_equal 'term/44', term.id
      assert_equal '44th Parliament', term.name
      assert_equal Date.new(2013, 9, 7), term.start_date
      assert_equal '44', term.slug
      assert %r{https://raw.githubusercontent.com/everypolitician/everypolitician-data/\w+?/data/Australia/Senate/term-44.csv}.match(term.csv_url)
      assert_equal 'Senate', term.legislature.name
      assert_equal 'Australia', term.country.name
    end
  end

  def test_legislative_period_csv
    VCR.use_cassette('term-44-csv') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      term = au_senate.legislative_periods.first
      csv = term.csv
      assert_instance_of CSV::Table, csv
    end
  end

  def test_legislative_period_square_brackets_expose_raw_data
    VCR.use_cassette('countries_json') do
      au_senate = Everypolitician.country(slug: 'Australia').legislature(slug: 'Senate')
      term = au_senate.legislative_periods.first
      assert_equal 'term/44', term[:id]
      assert_equal '44th Parliament', term[:name]
      assert_equal '2013-09-07', term[:start_date]
      assert_equal 'data/Australia/Senate/term-44.csv', term[:csv]
    end
  end

  def test_legislative_period_end_date
    VCR.use_cassette('countries_json') do
      term = Everypolitician.country(slug: 'Australia').legislature(slug: 'Representatives').legislative_periods[1]
      assert_equal Date.new(2013, 9, 7), term.end_date
    end
  end

  def test_missing_legislative_period_end_date
    VCR.use_cassette('countries_json') do
      term = Everypolitician.country(slug: 'Australia').legislature(slug: 'Representatives').legislative_periods.first
      assert_nil term.end_date
    end
  end

  def test_partial_dates
    VCR.use_cassette('countries_json') do
      af = Everypolitician.country(slug: 'Albania').legislature(slug: 'Assembly')
      term = af.legislative_periods.last
      assert_equal Date.new(2009), term.start_date
      assert_equal Date.new(2013), term.end_date
    end
  end
end
{'fraction_non_alphanumeric': 0.10282882510840388, 'fraction_numerical': 0.01858352260995251, 'mean_word_length': 4.0144927536231885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1956521', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1650, 'n_words': 284}