<commit_before>require 'spec_helper'

describe Masamune::DataPlan do
  let(:fs) { MockFilesystem.new }
  before do
    Masamune.configure do |config|
      config.filesystem = fs
    end
  end

  let(:plan) { Masamune::DataPlan.new }
  let(:primary_command) { Proc.new { } }
  let(:derived_daily_command) { Proc.new {} }
  let(:derived_monthly_command) { Proc.new {} }

  before do
    plan.add_target('primary', 'table/y=%Y/m=%m/d=%d')
    plan.add_source('primary', 'log/%Y%m%d.*.log', :wildcard => true)
    plan.add_command('primary', primary_command)
    plan.add_target('derived_daily', 'daily/%Y-%m-%d')
    plan.add_source('derived_daily', 'table/y=%Y/m=%m/d=%d')
    plan.add_command('derived_daily', derived_daily_command)
    plan.add_target('derived_monthly', 'monthly/%Y-%m')
    plan.add_source('derived_monthly', 'table/y=%Y/m=%m/d=%d')
    plan.add_command('derived_monthly', derived_monthly_command)
  end

  describe '#targets_for_date_range' do
    let(:start) { Date.civil(2013,01,01) }
    let(:stop) { Date.civil(2013,01,03) }

    subject { plan.targets_for_date_range(rule, start, stop).map(&:path) }

    context 'primary' do
      let(:rule) { 'primary' }
      it { should include 'table/y=2013/m=01/d=01' }
      it { should include 'table/y=2013/m=01/d=02' }
      it { should include 'table/y=2013/m=01/d=03' }
    end

    context 'derived_daily' do
      let(:rule) { 'derived_daily' }
      it { should include 'daily/2013-01-01' }
      it { should include 'daily/2013-01-02' }
      it { should include 'daily/2013-01-03' }
    end
  end

  describe '#targets_for_source' do
    subject(:targets) do
      plan.targets_for_source(rule, source)
    end

    context 'primary' do
      let(:rule) { 'primary' }
      let(:source) { 'log/20130101.random.log' }

      it { targets.first.start_time.should == Date.civil(2013,01,01) }
      it { targets.first.stop_time.should == Date.civil(2013,01,02) }
      it { targets.first.path.should == 'table/y=2013/m=01/d=01' }
    end

    context 'derived_daily' do
      let(:rule) { 'derived_daily' }
      let(:source)  { 'table/y=2013/m=01/d=01' }

      it { targets.first.start_time.should == Date.civil(2013,01,01) }
      it { targets.first.stop_time.should == Date.civil(2013,01,02) }
      it { targets.first.path.should == 'daily/2013-01-01' }
    end
  end
<commit_msg>Add more time_step conversion coverage<commit_after>require 'spec_helper'

describe Masamune::DataPlan do
  let(:fs) { MockFilesystem.new }
  before do
    Masamune.configure do |config|
      config.filesystem = fs
    end
  end

  let(:plan) { Masamune::DataPlan.new }
  let(:primary_command) { Proc.new { } }
  let(:derived_daily_command) { Proc.new {} }
  let(:derived_monthly_command) { Proc.new {} }

  before do
    plan.add_target('primary', 'table/y=%Y/m=%m/d=%d')
    plan.add_source('primary', 'log/%Y%m%d.*.log', :wildcard => true)
    plan.add_command('primary', primary_command)
    plan.add_target('derived_daily', 'daily/%Y-%m-%d')
    plan.add_source('derived_daily', 'table/y=%Y/m=%m/d=%d')
    plan.add_command('derived_daily', derived_daily_command)
    plan.add_target('derived_monthly', 'monthly/%Y-%m')
    plan.add_source('derived_monthly', 'table/y=%Y/m=%m/d=%d')
    plan.add_command('derived_monthly', derived_monthly_command)
  end

  describe '#targets_for_date_range' do
    let(:start) { Date.civil(2013,01,01) }
    let(:stop) { Date.civil(2013,01,03) }

    subject { plan.targets_for_date_range(rule, start, stop).map(&:path) }

    context 'primary' do
      let(:rule) { 'primary' }
      it { should include 'table/y=2013/m=01/d=01' }
      it { should include 'table/y=2013/m=01/d=02' }
      it { should include 'table/y=2013/m=01/d=03' }
      it { should have(3).items }
    end

    context 'derived_daily' do
      let(:rule) { 'derived_daily' }
      it { should include 'daily/2013-01-01' }
      it { should include 'daily/2013-01-02' }
      it { should include 'daily/2013-01-03' }
      it { should have(3).items }
    end

    context 'derived_monthly' do
      let(:rule) { 'derived_monthly' }
      it { should include 'monthly/2013-01' }
      it { should have(1).items }
    end
  end

  describe '#targets_for_source' do
    subject(:targets) do
      plan.targets_for_source(rule, source)
    end

    context 'primary' do
      let(:rule) { 'primary' }
      let(:source) { 'log/20130101.random.log' }

      it { targets.first.start_time.should == Date.civil(2013,01,01) }
      it { targets.first.stop_time.should == Date.civil(2013,01,02) }
      it { targets.first.path.should == 'table/y=2013/m=01/d=01' }
    end

    context 'derived_daily' do
      let(:rule) { 'derived_daily' }
      let(:source)  { 'table/y=2013/m=01/d=01' }

      it { targets.first.start_time.should == Date.civil(2013,01,01) }
      it { targets.first.stop_time.should == Date.civil(2013,01,02) }
      it { targets.first.path.should == 'daily/2013-01-01' }
    end

    context 'derived_monthly' do
      let(:rule) { 'derived_monthly' }
      let(:source)  { 'table/y=2013/m=01/d=01' }

      it { targets.first.start_time.should == Date.civil(2013,01,01) }
      it { targets.first.stop_time.should == Date.civil(2013,02,01) }
      it { targets.first.path.should == 'monthly/2013-01' }
    end
  end

{'fraction_non_alphanumeric': 0.1650943396226415, 'fraction_numerical': 0.05566037735849057, 'mean_word_length': 3.2104845115170773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5606245', 'n_tokens_mistral': 2212, 'n_tokens_neox': 1911, 'n_words': 316}