From e69c9dcd9a93980a87b951e884dc6f2369312c1f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 10 Jan 2010 21:54:20 -0500 Subject: [PATCH] integration test fixes --- classes/ConfigLoader.rb | 2 +- classes/Scheduler.rb | 20 ++++++++++++++++++++ tests/TestConfigLoader.rb | 11 +++++++++-- tests/TestFileProcessor.rb | 1 + tests/TestFilter.rb | 2 ++ tests/TestSVGToTempBitmap.rb | 4 ++-- tests/TestScheduler.rb | 12 +++++++++++- tests/TestTempBitmapToWeb.rb | 9 ++------- 8 files changed, 48 insertions(+), 13 deletions(-) diff --git a/classes/ConfigLoader.rb b/classes/ConfigLoader.rb index 2c951c5..f2f5140 100644 --- a/classes/ConfigLoader.rb +++ b/classes/ConfigLoader.rb @@ -54,7 +54,7 @@ class ConfigLoader if matches = re.match(filename) filename end - end + end.compact end end diff --git a/classes/Scheduler.rb b/classes/Scheduler.rb index d5c8b99..8425d67 100644 --- a/classes/Scheduler.rb +++ b/classes/Scheduler.rb @@ -46,6 +46,26 @@ class Scheduler breaks = parameters['breaks'] || [] + all_strings = true + parameters['interval'].each do |i| + if !i.is_a? String + all_strings = false + break + end + end + + if all_strings + parameters['interval'].each_index do |i| + interval = parameters['interval'].shift + if current == skip_to_dow(current, interval) + parameters['interval'].unshift(interval) + break + else + parameters['interval'].push(interval) + end + end + end + index = 0 while dates.length < to_produce interval = parameters['interval'].shift diff --git a/tests/TestConfigLoader.rb b/tests/TestConfigLoader.rb index 433436e..10377eb 100644 --- a/tests/TestConfigLoader.rb +++ b/tests/TestConfigLoader.rb @@ -35,7 +35,7 @@ class TestConfigLoader < Test::Unit::TestCase [ { 'Global' => { - 'path' => '*.svg', + 'path' => '.', 'match' => '.*\.svg', 'page_index_format' => '%02d' }, @@ -45,7 +45,7 @@ class TestConfigLoader < Test::Unit::TestCase }, { 'Global' => { - 'path' => '*.svg', + 'path' => '.', 'match' => '.*\.svg', 'page_index_format' => '%02d', 'files' => [ Dir.pwd + '/test1.svg', Dir.pwd + '/test2.svg' ], @@ -178,6 +178,10 @@ class TestConfigLoader < Test::Unit::TestCase end assert_equal expected_result, @config_loader.load('file') + + if files + files.each { |f| FileUtils.rm f } + end end end end @@ -189,6 +193,8 @@ class TestConfigLoader < Test::Unit::TestCase end assert_equal %w(one two three), @config_loader.load_yaml('test') + + FileUtils.rm 'test' end end @@ -196,6 +202,7 @@ class TestConfigLoader < Test::Unit::TestCase FakeFS do FileUtils.touch [ 'test', 'test2', 'test3' ] assert_equal '%01d', @config_loader.count_pattern('*') + [ 'test', 'test2', 'test3' ].each { |f| FileUtils.rm f } end end end diff --git a/tests/TestFileProcessor.rb b/tests/TestFileProcessor.rb index 729ade4..6fe1595 100644 --- a/tests/TestFileProcessor.rb +++ b/tests/TestFileProcessor.rb @@ -143,6 +143,7 @@ class TestFileProcessor < Test::Unit::TestCase FakeFS do FileUtils.touch [ 'r-test', 'r-test2', 'source' ] assert_equal expected_return, file_processor.determine_rebuild(targets, filename) + [ 'r-test', 'r-test2', 'source' ].each { |f| FileUtils.rm f } end end end diff --git a/tests/TestFilter.rb b/tests/TestFilter.rb index 33660dc..f295473 100644 --- a/tests/TestFilter.rb +++ b/tests/TestFilter.rb @@ -65,6 +65,8 @@ class TestFilter < Test::Unit::TestCase [ 'test4' ].each do |file| assert File.exists? file end + + [ 'test', 'test3', 'test4' ].each { |f| FileUtils.rm f } end end diff --git a/tests/TestSVGToTempBitmap.rb b/tests/TestSVGToTempBitmap.rb index 45036f5..2278072 100644 --- a/tests/TestSVGToTempBitmap.rb +++ b/tests/TestSVGToTempBitmap.rb @@ -71,7 +71,7 @@ class TestSVGToTempBitmap < Test::Unit::TestCase def test_single_no_spread @filter.output_filename = 'test' - @filter.expects(:inkscape).with('file', Dir.pwd + '/test') + @filter.expects(:inkscape).with(Dir.pwd + '/file', Dir.pwd + '/test') assert_equal Dir.pwd + '/test', @filter.single('file') assert_equal [ Dir.pwd + '/test' ], @filter.cleanup end @@ -83,7 +83,7 @@ class TestSVGToTempBitmap < Test::Unit::TestCase 'spread' => true } - @filter.expects(:inkscape).with('file', Dir.pwd + '/test') + @filter.expects(:inkscape).with(Dir.pwd + '/file', Dir.pwd + '/test') @filter.expects(:build_spread).with(Dir.pwd + '/test').returns(['target1', 'target2']) @filter.single('file') diff --git a/tests/TestScheduler.rb b/tests/TestScheduler.rb index 88dbeb8..dbdc2a3 100644 --- a/tests/TestScheduler.rb +++ b/tests/TestScheduler.rb @@ -38,7 +38,7 @@ class TestScheduler < Test::Unit::TestCase ], [ { - 'start' => DateTime.parse('2010-01-01'), + 'start' => DateTime.parse('2010-01-02'), 'interval' => [ 'monday', 'wednesday', 'friday' ], 'breaks' => [ { 'at_index' => 3, 'for_days' => 7 } @@ -50,6 +50,16 @@ class TestScheduler < Test::Unit::TestCase DateTime.parse('2010-01-18'), DateTime.parse('2010-01-20'), DateTime.parse('2010-01-22') ] ], + [ + { + 'start' => DateTime.parse('2010-01-06'), + 'interval' => [ 'monday', 'wednesday', 'friday' ], + }, + 3, + [ + DateTime.parse('2010-01-06'), DateTime.parse('2010-01-08'), DateTime.parse('2010-01-11'), + ] + ], ].each do |parameters, to_produce, expected_results| assert_equal expected_results, @scheduler.schedule(parameters, to_produce) end diff --git a/tests/TestTempBitmapToWeb.rb b/tests/TestTempBitmapToWeb.rb index 741ea85..1d662b3 100644 --- a/tests/TestTempBitmapToWeb.rb +++ b/tests/TestTempBitmapToWeb.rb @@ -22,16 +22,11 @@ class TestTempBitmapToWeb < Test::Unit::TestCase end end - def test_requires_schedule - @filter.requires_schedule('test') - assert_equal 'test', @filter.schedule - end - def test_filename - @filter.schedule = [ Date.parse('2010-01-01') ] @filter.config = { 'target' => 'test{date}', - 'date_format' => '%Y-%m-%d' + 'date_format' => '%Y-%m-%d', + 'publish_dates' => [ Date.parse('2010-01-01') ] } assert_equal 'test2010-01-01', @filter.filename({'index' => 0}) end