more config loader and file processor work

This commit is contained in:
John Bintz 2010-01-08 07:55:59 -05:00
parent ac31b5f98f
commit 480a911bf6
5 changed files with 67 additions and 1 deletions

View File

@ -1,3 +1,5 @@
require File.dirname(__FILE__) + '/Scheduler.rb'
class ConfigLoader class ConfigLoader
def load(file) def load(file)
config = load_yaml(file) config = load_yaml(file)
@ -61,6 +63,15 @@ class ConfigLoader
config['Global'] = global config['Global'] = global
scheduler = Scheduler.instance
config.each do |type, info|
if type != "Global"
if info['schedule']
info['publish_dates'] = scheduler.schedule(info['schedule'], files.length)
end
end
end
config config
end end

View File

@ -1,3 +1,4 @@
require File.dirname(__FILE__) + '/../modules/PrintHandling.rb'
require File.dirname(__FILE__) + '/InputFilter.rb' require File.dirname(__FILE__) + '/InputFilter.rb'
class SVGToTempBitmap < InputFilter class SVGToTempBitmap < InputFilter

View File

@ -1,3 +1,6 @@
require File.dirname(__FILE__) + '/OutputFilter.rb'
require File.dirname(__FILE__) + '/../modules/PrintHandling.rb'
require File.dirname(__FILE__) + '/../modules/Pagination.rb'
# #
# Convert bitmap files to a paginated print-ready file # Convert bitmap files to a paginated print-ready file

View File

@ -1,6 +1,8 @@
require 'rubygems' require 'rubygems'
require 'test/unit' require 'test/unit'
require 'mocha'
require File.dirname(__FILE__) + '/../classes/ConfigLoader.rb' require File.dirname(__FILE__) + '/../classes/ConfigLoader.rb'
require File.dirname(__FILE__) + '/../classes/Scheduler.rb'
class TestConfigLoader < Test::Unit::TestCase class TestConfigLoader < Test::Unit::TestCase
def setup def setup
@ -36,6 +38,9 @@ class TestConfigLoader < Test::Unit::TestCase
'path' => '*.svg', 'path' => '*.svg',
'match' => '.*\.svg', 'match' => '.*\.svg',
'page_index_format' => '%02d' 'page_index_format' => '%02d'
},
'Web' => {
'schedule' => 'schedule'
} }
}, },
{ {
@ -45,6 +50,10 @@ class TestConfigLoader < Test::Unit::TestCase
'page_index_format' => '%02d', 'page_index_format' => '%02d',
'files' => [ Dir.pwd + '/test1.svg', Dir.pwd + '/test2.svg' ], 'files' => [ Dir.pwd + '/test1.svg', Dir.pwd + '/test2.svg' ],
'fileinfo_by_file' => {} 'fileinfo_by_file' => {}
},
'Web' => {
'schedule' => 'schedule',
'publish_dates' => 'schedule'
} }
}, },
[], [],
@ -143,6 +152,14 @@ class TestConfigLoader < Test::Unit::TestCase
].each do |yaml, expected_result, expectations, files| ].each do |yaml, expected_result, expectations, files|
@config_loader.expects(:load_yaml).with('file').returns(yaml) @config_loader.expects(:load_yaml).with('file').returns(yaml)
yaml.each do |type, info|
if type != "Global"
if info['schedule']
Scheduler.any_instance.expects(:schedule).with(info['schedule'], expected_result['Global']['files'].length).returns('schedule')
end
end
end
if expectations if expectations
expectations.each do |expectation| expectations.each do |expectation|
e = @config_loader.expects(expectation[:expects]) e = @config_loader.expects(expectation[:expects])

View File

@ -1,6 +1,8 @@
require 'rubygems' require 'rubygems'
require 'test/unit' require 'test/unit'
require File.dirname(__FILE__) + '/../classes/FileProcessor.rb' Dir[File.dirname(__FILE__) + '/../classes/*'].each do |f|
require f
end
class TestFileProcessor < Test::Unit::TestCase class TestFileProcessor < Test::Unit::TestCase
def test_verify_filename def test_verify_filename
@ -79,6 +81,38 @@ class TestFileProcessor < Test::Unit::TestCase
end end
def test_construct_filters_and_targets def test_construct_filters_and_targets
match_data = 'test'
[
[
'test.svg',
{ 'target' => 'test.png' },
'test',
[ SVGToTempBitmap, TempBitmapToWeb, 'target' ]
],
[
'test.svg',
{ 'target' => 'test.pdf' },
'test',
[ SVGToTempBitmap, TempBitmapToPrint, 'target' ]
],
[
'test.svg',
{ 'target' => 'test.pdf', 'is_paginated' => true },
'test',
[ SVGToTempBitmap, TempBitmapToPaginatedPrint, 'target' ]
],
].each do |filename, info, match_data, expected_return|
file_processor = FileProcessor.new({})
file_processor.expects(:build_filename_parts).with(match_data).returns('parts')
expected_return[0..1].each do |m|
m.any_instance.stubs(:recalc_pixels)
end
expected_return[1].any_instance.expects(:targets).with('parts').returns('target')
file_processor.construct_filters_and_targets(filename, info, match_data)
end
end end
end end