etl 0.9.5.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.yardopts +5 -0
- data/0.9-UPGRADE +6 -0
- data/CHANGELOG +236 -0
- data/Gemfile +4 -0
- data/HOW_TO_RELEASE +13 -0
- data/LICENSE +7 -0
- data/README.textile +111 -0
- data/Rakefile +105 -0
- data/TODO +28 -0
- data/activewarehouse-etl.gemspec +38 -0
- data/bin/etl +28 -0
- data/bin/etl.cmd +8 -0
- data/examples/database.example.yml +16 -0
- data/lib/etl.rb +97 -0
- data/lib/etl/batch.rb +2 -0
- data/lib/etl/batch/batch.rb +111 -0
- data/lib/etl/batch/directives.rb +65 -0
- data/lib/etl/builder.rb +2 -0
- data/lib/etl/builder/date_dimension_builder.rb +96 -0
- data/lib/etl/builder/time_dimension_builder.rb +31 -0
- data/lib/etl/commands/etl.rb +89 -0
- data/lib/etl/control.rb +3 -0
- data/lib/etl/control/control.rb +405 -0
- data/lib/etl/control/destination.rb +438 -0
- data/lib/etl/control/destination/csv_destination.rb +113 -0
- data/lib/etl/control/destination/database_destination.rb +97 -0
- data/lib/etl/control/destination/excel_destination.rb +91 -0
- data/lib/etl/control/destination/file_destination.rb +126 -0
- data/lib/etl/control/destination/insert_update_database_destination.rb +136 -0
- data/lib/etl/control/destination/update_database_destination.rb +109 -0
- data/lib/etl/control/destination/yaml_destination.rb +74 -0
- data/lib/etl/control/source.rb +132 -0
- data/lib/etl/control/source/database_source.rb +224 -0
- data/lib/etl/control/source/enumerable_source.rb +11 -0
- data/lib/etl/control/source/file_source.rb +90 -0
- data/lib/etl/control/source/model_source.rb +39 -0
- data/lib/etl/core_ext.rb +1 -0
- data/lib/etl/core_ext/time.rb +5 -0
- data/lib/etl/core_ext/time/calculations.rb +42 -0
- data/lib/etl/engine.rb +582 -0
- data/lib/etl/execution.rb +19 -0
- data/lib/etl/execution/base.rb +8 -0
- data/lib/etl/execution/batch.rb +10 -0
- data/lib/etl/execution/job.rb +8 -0
- data/lib/etl/execution/migration.rb +90 -0
- data/lib/etl/generator.rb +2 -0
- data/lib/etl/generator/generator.rb +20 -0
- data/lib/etl/generator/surrogate_key_generator.rb +39 -0
- data/lib/etl/http_tools.rb +139 -0
- data/lib/etl/parser.rb +11 -0
- data/lib/etl/parser/apache_combined_log_parser.rb +49 -0
- data/lib/etl/parser/csv_parser.rb +93 -0
- data/lib/etl/parser/excel_parser.rb +112 -0
- data/lib/etl/parser/fixed_width_parser.rb +65 -0
- data/lib/etl/parser/nokogiri_xml_parser.rb +83 -0
- data/lib/etl/parser/parser.rb +41 -0
- data/lib/etl/parser/sax_parser.rb +218 -0
- data/lib/etl/parser/xml_parser.rb +65 -0
- data/lib/etl/processor.rb +11 -0
- data/lib/etl/processor/block_processor.rb +14 -0
- data/lib/etl/processor/bulk_import_processor.rb +94 -0
- data/lib/etl/processor/check_exist_processor.rb +80 -0
- data/lib/etl/processor/check_unique_processor.rb +39 -0
- data/lib/etl/processor/copy_field_processor.rb +26 -0
- data/lib/etl/processor/database_join_processor.rb +82 -0
- data/lib/etl/processor/encode_processor.rb +55 -0
- data/lib/etl/processor/ensure_fields_presence_processor.rb +24 -0
- data/lib/etl/processor/escape_csv_processor.rb +77 -0
- data/lib/etl/processor/filter_row_processor.rb +51 -0
- data/lib/etl/processor/ftp_downloader_processor.rb +68 -0
- data/lib/etl/processor/ftp_uploader_processor.rb +65 -0
- data/lib/etl/processor/hierarchy_exploder_processor.rb +55 -0
- data/lib/etl/processor/imapattachment_downloader_processor.rb +91 -0
- data/lib/etl/processor/pop3attachment_downloader_processor.rb +90 -0
- data/lib/etl/processor/print_row_processor.rb +12 -0
- data/lib/etl/processor/processor.rb +25 -0
- data/lib/etl/processor/rename_processor.rb +24 -0
- data/lib/etl/processor/require_non_blank_processor.rb +26 -0
- data/lib/etl/processor/row_processor.rb +27 -0
- data/lib/etl/processor/sequence_processor.rb +23 -0
- data/lib/etl/processor/sftp_downloader_processor.rb +63 -0
- data/lib/etl/processor/sftp_uploader_processor.rb +63 -0
- data/lib/etl/processor/surrogate_key_processor.rb +53 -0
- data/lib/etl/processor/truncate_processor.rb +40 -0
- data/lib/etl/processor/zip_file_processor.rb +27 -0
- data/lib/etl/row.rb +20 -0
- data/lib/etl/screen.rb +14 -0
- data/lib/etl/screen/row_count_screen.rb +20 -0
- data/lib/etl/transform.rb +2 -0
- data/lib/etl/transform/block_transform.rb +13 -0
- data/lib/etl/transform/calculation_transform.rb +71 -0
- data/lib/etl/transform/date_to_string_transform.rb +20 -0
- data/lib/etl/transform/decode_transform.rb +51 -0
- data/lib/etl/transform/default_transform.rb +20 -0
- data/lib/etl/transform/foreign_key_lookup_transform.rb +211 -0
- data/lib/etl/transform/hierarchy_lookup_transform.rb +49 -0
- data/lib/etl/transform/md5_transform.rb +13 -0
- data/lib/etl/transform/ordinalize_transform.rb +14 -0
- data/lib/etl/transform/sha1_transform.rb +13 -0
- data/lib/etl/transform/split_fields_transform.rb +27 -0
- data/lib/etl/transform/string_to_date_time_transform.rb +14 -0
- data/lib/etl/transform/string_to_date_transform.rb +16 -0
- data/lib/etl/transform/string_to_time_transform.rb +11 -0
- data/lib/etl/transform/transform.rb +61 -0
- data/lib/etl/transform/trim_transform.rb +26 -0
- data/lib/etl/transform/type_transform.rb +35 -0
- data/lib/etl/util.rb +59 -0
- data/lib/etl/version.rb +3 -0
- data/spec/fixtures/all.ebf +6 -0
- data/spec/fixtures/apache_combined_log.ctl +11 -0
- data/spec/fixtures/batch_with_error.ebf +6 -0
- data/spec/fixtures/batched1.ctl +0 -0
- data/spec/fixtures/batched2.ctl +0 -0
- data/spec/fixtures/block_processor.ctl +6 -0
- data/spec/fixtures/block_processor_error.ctl +1 -0
- data/spec/fixtures/block_processor_pre_post_process.ctl +4 -0
- data/spec/fixtures/block_processor_remove_rows.ctl +5 -0
- data/spec/fixtures/data/apache_combined_log.txt +3 -0
- data/spec/fixtures/data/bulk_import.txt +3 -0
- data/spec/fixtures/data/bulk_import_with_empties.txt +3 -0
- data/spec/fixtures/data/decode.txt +3 -0
- data/spec/fixtures/data/delimited.txt +3 -0
- data/spec/fixtures/data/encode_source_latin1.txt +2 -0
- data/spec/fixtures/data/excel.xls +0 -0
- data/spec/fixtures/data/excel2.xls +0 -0
- data/spec/fixtures/data/fixed_width.txt +3 -0
- data/spec/fixtures/data/multiple_delimited_1.txt +3 -0
- data/spec/fixtures/data/multiple_delimited_2.txt +3 -0
- data/spec/fixtures/data/nokogiri.xml +38 -0
- data/spec/fixtures/data/people.txt +3 -0
- data/spec/fixtures/data/sax.xml +14 -0
- data/spec/fixtures/data/xml.xml +16 -0
- data/spec/fixtures/delimited.ctl +30 -0
- data/spec/fixtures/delimited_absolute.ctl +31 -0
- data/spec/fixtures/delimited_destination_db.ctl +23 -0
- data/spec/fixtures/delimited_excel.ctl +31 -0
- data/spec/fixtures/delimited_insert_update.ctl +34 -0
- data/spec/fixtures/delimited_update.ctl +34 -0
- data/spec/fixtures/delimited_with_bulk_load.ctl +34 -0
- data/spec/fixtures/errors.ctl +24 -0
- data/spec/fixtures/excel.ctl +24 -0
- data/spec/fixtures/excel2.ctl +25 -0
- data/spec/fixtures/fixed_width.ctl +35 -0
- data/spec/fixtures/inline_parser.ctl +17 -0
- data/spec/fixtures/model_source.ctl +14 -0
- data/spec/fixtures/multiple_delimited.ctl +22 -0
- data/spec/fixtures/multiple_source_delimited.ctl +39 -0
- data/spec/fixtures/nokogiri_all.ctl +35 -0
- data/spec/fixtures/nokogiri_select.ctl +35 -0
- data/spec/fixtures/output/.ignore +1 -0
- data/spec/fixtures/output/delimited.txt +3 -0
- data/spec/fixtures/output/encode_destination_utf-8.txt +2 -0
- data/spec/fixtures/output/fixed_width.txt +3 -0
- data/spec/fixtures/output/inline_parser.txt +3 -0
- data/spec/fixtures/output/multiple_source_delimited.txt +6 -0
- data/spec/fixtures/output/test_excel_destination.xls +0 -0
- data/spec/fixtures/output/test_file_destination.2.txt +2 -0
- data/spec/fixtures/output/test_file_destination.txt +2 -0
- data/spec/fixtures/output/test_multiple_unique.txt +1 -0
- data/spec/fixtures/output/test_unique.txt +2 -0
- data/spec/fixtures/sax.ctl +26 -0
- data/spec/fixtures/scd/1.txt +1 -0
- data/spec/fixtures/scd/2.txt +1 -0
- data/spec/fixtures/scd/3.txt +1 -0
- data/spec/fixtures/scd_test_type_1.ctl +43 -0
- data/spec/fixtures/scd_test_type_2.ctl +34 -0
- data/spec/fixtures/screen_test_error.ctl +3 -0
- data/spec/fixtures/screen_test_fatal.ctl +3 -0
- data/spec/fixtures/xml.ctl +31 -0
- data/spec/quality_spec.rb +11 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/custom_fixtures.rb +54 -0
- data/spec/support/custom_matchers.rb +54 -0
- data/test-matrix.yml +10 -0
- data/test/.gitignore +1 -0
- data/test/.ignore +2 -0
- data/test/batch_test.rb +41 -0
- data/test/block_processor_test.rb +38 -0
- data/test/check_exist_processor_test.rb +92 -0
- data/test/check_unique_processor_test.rb +40 -0
- data/test/config/Gemfile.rails-2.3.x +3 -0
- data/test/config/Gemfile.rails-2.3.x.lock +53 -0
- data/test/config/Gemfile.rails-3.0.x +3 -0
- data/test/config/Gemfile.rails-3.0.x.lock +61 -0
- data/test/config/common.rb +29 -0
- data/test/connection/mysql/connection.rb +9 -0
- data/test/connection/mysql/schema.sql +37 -0
- data/test/connection/postgresql/connection.rb +13 -0
- data/test/connection/postgresql/schema.sql +40 -0
- data/test/control_test.rb +43 -0
- data/test/database_join_processor_test.rb +43 -0
- data/test/date_dimension_builder_test.rb +96 -0
- data/test/destination_test.rb +275 -0
- data/test/directive_test.rb +23 -0
- data/test/encode_processor_test.rb +32 -0
- data/test/engine_test.rb +78 -0
- data/test/ensure_fields_presence_processor_test.rb +28 -0
- data/test/etl_test.rb +42 -0
- data/test/foreign_key_lookup_transform_test.rb +50 -0
- data/test/generator_test.rb +14 -0
- data/test/mocks/mock_destination.rb +26 -0
- data/test/mocks/mock_source.rb +25 -0
- data/test/nokogiri_test.rb +35 -0
- data/test/parser_test.rb +224 -0
- data/test/performance/delimited.ctl +30 -0
- data/test/processor_test.rb +44 -0
- data/test/row_processor_test.rb +17 -0
- data/test/scd_test.rb +257 -0
- data/test/screen_test.rb +9 -0
- data/test/source_test.rb +154 -0
- data/test/test_helper.rb +37 -0
- data/test/transform_test.rb +101 -0
- data/test/truncate_processor_test.rb +37 -0
- metadata +510 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
# puts "executing nokogiri_all.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/nokogiri.xml',
|
5
|
+
:parser => :nokogiri_xml
|
6
|
+
},
|
7
|
+
{
|
8
|
+
:collection => 'people/person',
|
9
|
+
:fields => [
|
10
|
+
:first_name,
|
11
|
+
:last_name,
|
12
|
+
{
|
13
|
+
:name => :ssn,
|
14
|
+
:xpath => '@ssn'
|
15
|
+
},
|
16
|
+
{
|
17
|
+
:name => :age,
|
18
|
+
:type => :integer
|
19
|
+
},
|
20
|
+
{
|
21
|
+
:name => :hair_colour,
|
22
|
+
:xpath => 'colours/hair'
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
|
27
|
+
destination :out, {
|
28
|
+
:file => 'output/xml.txt'
|
29
|
+
},
|
30
|
+
{
|
31
|
+
:order => [:first_name, :last_name, :ssn]
|
32
|
+
}
|
33
|
+
|
34
|
+
transform :ssn, :sha1
|
35
|
+
transform(:ssn){ |v| v[0,24] }
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# puts "executing nokogiri_select.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/nokogiri.xml',
|
5
|
+
:parser => :nokogiri_xml
|
6
|
+
},
|
7
|
+
{
|
8
|
+
:collection => 'people/person[@type="client"]',
|
9
|
+
:fields => [
|
10
|
+
:first_name,
|
11
|
+
:last_name,
|
12
|
+
{
|
13
|
+
:name => :ssn,
|
14
|
+
:xpath => '@ssn'
|
15
|
+
},
|
16
|
+
{
|
17
|
+
:name => :age,
|
18
|
+
:type => :integer
|
19
|
+
},
|
20
|
+
{
|
21
|
+
:name => :hair_colour,
|
22
|
+
:xpath => 'colours/hair'
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
|
27
|
+
destination :out, {
|
28
|
+
:file => 'output/xml.txt'
|
29
|
+
},
|
30
|
+
{
|
31
|
+
:order => [:first_name, :last_name, :ssn]
|
32
|
+
}
|
33
|
+
|
34
|
+
transform :ssn, :sha1
|
35
|
+
transform(:ssn){ |v| v[0,24] }
|
@@ -0,0 +1 @@
|
|
1
|
+
*.txt
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Chris,Smith,23cc5914d48b146f0fbb73c4,24,,12
|
2
|
+
Jim,Foxworthy,596e3534978b8c2b47851e37,51,,14
|
3
|
+
Brian,Collingsworth,535776974fbf28b1dfbab5bd,10,,83
|
4
|
+
Chris,Smith,23cc5914d48b146f0fbb73c4,24,dude,
|
5
|
+
Jim,Foxworthy,596e3534978b8c2b47851e37,51,broseph,
|
6
|
+
Brian,Collingsworth,535776974fbf28b1dfbab5bd,10,maaan,
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
Bob,Smith,111234444
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# puts "executing fixed_width.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/sax.xml',
|
5
|
+
:parser => :sax
|
6
|
+
},
|
7
|
+
{
|
8
|
+
:write_trigger => 'people/person',
|
9
|
+
:fields => {
|
10
|
+
:first_name => 'people/person/first_name',
|
11
|
+
:last_name => 'people/person/last_name',
|
12
|
+
:ssn => 'people/person/social_security_number',
|
13
|
+
:age => 'people/person[age]'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
transform :ssn, :sha1
|
18
|
+
transform(:ssn){ |v| v[0,24] }
|
19
|
+
transform :age, :type, {:type => :number}
|
20
|
+
|
21
|
+
destination :out, {
|
22
|
+
:file => 'output/sax.out.txt'
|
23
|
+
},
|
24
|
+
{
|
25
|
+
:order => [:first_name, :last_name, :ssn, :age]
|
26
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
Bob,Smith,200 South Drive,Boston,MA,32123
|
@@ -0,0 +1 @@
|
|
1
|
+
Bob,Smith,1010 SW 23rd St,Los Angeles,CA,90392
|
@@ -0,0 +1 @@
|
|
1
|
+
Bob,Smith,280 Pine Street,Los Angeles,CA,90392
|
@@ -0,0 +1,43 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => "scd/#{ENV['run_number']}.txt",
|
3
|
+
:parser => :csv
|
4
|
+
},
|
5
|
+
[
|
6
|
+
:first_name,
|
7
|
+
:last_name,
|
8
|
+
:address,
|
9
|
+
:city,
|
10
|
+
:state,
|
11
|
+
:zip_code
|
12
|
+
]
|
13
|
+
|
14
|
+
# NOTE: These are not usually required for a type 1 SCD dimension, but since
|
15
|
+
# we're sharing this table with the type 2 tests, they're necessary.
|
16
|
+
transform :effective_date, :default, :default_value => Time.now.to_s(:db)
|
17
|
+
transform :end_date, :default, :default_value => '9999-12-31 00:00:00'
|
18
|
+
transform :latest_version, :default, :default_value => true
|
19
|
+
|
20
|
+
destination :out, {
|
21
|
+
:file => 'output/scd_test_type_1.txt',
|
22
|
+
:natural_key => [:first_name, :last_name],
|
23
|
+
:scd => {
|
24
|
+
:type => 1,
|
25
|
+
:dimension_target => :data_warehouse,
|
26
|
+
:dimension_table => 'person_dimension'
|
27
|
+
},
|
28
|
+
:scd_fields => [:address, :city, :state, :zip_code]
|
29
|
+
},
|
30
|
+
{
|
31
|
+
:order => [
|
32
|
+
:id, :first_name, :last_name, :address, :city, :state, :zip_code, :effective_date, :end_date, :latest_version
|
33
|
+
],
|
34
|
+
:virtual => {
|
35
|
+
:id => ETL::Generator::SurrogateKeyGenerator.new(:target => :data_warehouse, :table => 'person_dimension')
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
post_process :bulk_import, {
|
40
|
+
:file => 'output/scd_test_type_1.txt',
|
41
|
+
:target => :data_warehouse,
|
42
|
+
:table => 'person_dimension'
|
43
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
source :in, {
|
2
|
+
:file => "scd/#{ENV['run_number']}.txt",
|
3
|
+
:parser => :csv
|
4
|
+
},
|
5
|
+
[
|
6
|
+
:first_name,
|
7
|
+
:last_name,
|
8
|
+
:address,
|
9
|
+
:city,
|
10
|
+
:state,
|
11
|
+
:zip_code
|
12
|
+
]
|
13
|
+
|
14
|
+
destination :out, {
|
15
|
+
:type => :database,
|
16
|
+
:target => :data_warehouse,
|
17
|
+
:database => 'etl_unittest',
|
18
|
+
:table => 'person_dimension',
|
19
|
+
:natural_key => [:first_name, :last_name],
|
20
|
+
:scd => {
|
21
|
+
:type => 2,
|
22
|
+
:dimension_target => :data_warehouse,
|
23
|
+
:dimension_table => 'person_dimension'
|
24
|
+
},
|
25
|
+
:scd_fields => ENV['type_2_scd_fields'] ? Marshal.load(ENV['type_2_scd_fields']) : [:address, :city, :state, :zip_code]
|
26
|
+
},
|
27
|
+
{
|
28
|
+
:order => [
|
29
|
+
:id, :first_name, :last_name, :address, :city, :state, :zip_code, :effective_date, :end_date, :latest_version
|
30
|
+
],
|
31
|
+
:virtual => {
|
32
|
+
:id => ETL::Generator::SurrogateKeyGenerator.new(:target => :data_warehouse, :table => 'person_dimension')
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# puts "executing fixed_width.ctl"
|
2
|
+
|
3
|
+
source :in, {
|
4
|
+
:file => 'data/xml.xml',
|
5
|
+
:parser => :xml
|
6
|
+
},
|
7
|
+
{
|
8
|
+
:collection => 'people/person',
|
9
|
+
:fields => [
|
10
|
+
:first_name,
|
11
|
+
:last_name,
|
12
|
+
{
|
13
|
+
:name => :ssn,
|
14
|
+
:xpath => 'social_security_number'
|
15
|
+
},
|
16
|
+
{
|
17
|
+
:name => :age,
|
18
|
+
:type => :integer
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
22
|
+
|
23
|
+
destination :out, {
|
24
|
+
:file => 'output/xml.txt'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
:order => [:first_name, :last_name, :ssn]
|
28
|
+
}
|
29
|
+
|
30
|
+
transform :ssn, :sha1
|
31
|
+
transform(:ssn){ |v| v[0,24] }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
IGNORE = /\.(gitmodules|txt$|png$|tar$|gz$|rbc$|gem$|pdf$)/
|
4
|
+
|
5
|
+
describe "The application itself" do
|
6
|
+
it "has no malformed whitespace" do
|
7
|
+
files = `git ls-files`.split("\n").select {|fn| fn !~ IGNORE}
|
8
|
+
|
9
|
+
files.should be_well_formed
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
3
|
+
module CustomFixtures
|
4
|
+
attr_reader :fixtures
|
5
|
+
|
6
|
+
# @param [#to_sym]
|
7
|
+
# @return [String]
|
8
|
+
def fixture_for(name)
|
9
|
+
fixtures[name.to_sym][:fixture]
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [#to_sym]
|
13
|
+
# @return [String]
|
14
|
+
def path_for(name)
|
15
|
+
fixtures[name.to_sym][:path]
|
16
|
+
end
|
17
|
+
|
18
|
+
# @see ConfigFixtures#create_fixture_hash
|
19
|
+
def fixtures
|
20
|
+
@fixtures ||= begin
|
21
|
+
hash = Hash.new {|k,v| k[v] = {}}
|
22
|
+
hash.merge!(create_fixture_hash)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Hash{Symbol => String}]
|
27
|
+
def create_fixture_hash
|
28
|
+
Hash[ find_fixtures.map{|fpath| map_fixture(fpath) } ]
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [String]
|
32
|
+
# @return [Array<Symbol, String>]
|
33
|
+
def map_fixture(fpath)
|
34
|
+
[symbolize_filename(fpath), {:path => fpath, :fixture => read_file(fpath)}]
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Array<String>]
|
38
|
+
def find_fixtures
|
39
|
+
Dir.glob Bundler.root.join('spec/fixtures/**/*')
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String]
|
43
|
+
# @return [Symbol]
|
44
|
+
def symbolize_filename(fpath)
|
45
|
+
fname = File.basename(fpath)
|
46
|
+
fname.split(/\W/).shift.to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [String]
|
50
|
+
# @return [String]
|
51
|
+
def read_file(fpath)
|
52
|
+
File.read(fpath)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module CustomMatchers
|
2
|
+
class BeWellFormed
|
3
|
+
attr_writer :errors
|
4
|
+
|
5
|
+
def errors
|
6
|
+
@errors ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(files)
|
10
|
+
self.errors = files.dup
|
11
|
+
|
12
|
+
errors.map! do |filename|
|
13
|
+
file = File.read(filename).encode!("UTF-8")
|
14
|
+
|
15
|
+
next unless file.valid_encoding?
|
16
|
+
|
17
|
+
[ check_for_tabs(filename, file), excessive_spacing(filename, file), newline_precedes_eof(filename, file) ]
|
18
|
+
end
|
19
|
+
|
20
|
+
errors.flatten!
|
21
|
+
errors.compact!
|
22
|
+
|
23
|
+
errors.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message_for_should
|
27
|
+
errors.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_for_tabs(filename, file)
|
31
|
+
bad_lines = file.lines.each_with_index.map do |line, line_no|
|
32
|
+
line_no + 1 if line["\t"] and line !~ /^\s+#.*\s+\n$/
|
33
|
+
end.flatten.compact
|
34
|
+
|
35
|
+
"#{filename} has tab characters on lines #{bad_lines.join(', ')}" if bad_lines.any?
|
36
|
+
end
|
37
|
+
|
38
|
+
def excessive_spacing(filename, file)
|
39
|
+
bad_lines = file.lines.each_with_index.map do |line, line_no|
|
40
|
+
line_no + 1 if line =~ /\s+\n$/ and line !~ /^\s+#.*\s+\n$/
|
41
|
+
end.flatten.compact
|
42
|
+
|
43
|
+
"#{filename} has spaces on the EOL on lines #{bad_lines.join(', ')}" if bad_lines.any?
|
44
|
+
end
|
45
|
+
|
46
|
+
def newline_precedes_eof(filename, file)
|
47
|
+
"#{filename} does not have a newline (\\n) before EOF" if file !~ /\n$/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def be_well_formed
|
52
|
+
BeWellFormed.new
|
53
|
+
end
|
54
|
+
end
|
data/test-matrix.yml
ADDED
data/test/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
database*.yml
|
data/test/.ignore
ADDED
data/test/batch_test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class BatchTest < Test::Unit::TestCase
|
4
|
+
attr_reader :file, :db_yaml, :engine
|
5
|
+
def setup
|
6
|
+
@file = File.dirname(__FILE__) + '/all.ebf'
|
7
|
+
@db_yaml = File.dirname(__FILE__) + '/database.yml'
|
8
|
+
@engine = ETL::Engine.new
|
9
|
+
end
|
10
|
+
def teardown
|
11
|
+
|
12
|
+
end
|
13
|
+
def test_etl_batch_file
|
14
|
+
#`etl #{file} -c #{db_yaml}`
|
15
|
+
end
|
16
|
+
def test_batch
|
17
|
+
assert_nothing_raised do
|
18
|
+
batch = ETL::Batch::Batch.resolve(file, engine)
|
19
|
+
batch.execute
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def test_batch_with_file
|
23
|
+
assert_nothing_raised do
|
24
|
+
batch = ETL::Batch::Batch.resolve(File.new(file), engine)
|
25
|
+
batch.execute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def test_batch_with_batch_object
|
29
|
+
assert_nothing_raised do
|
30
|
+
batch_instance = ETL::Batch::Batch.new(File.new(file))
|
31
|
+
batch_instance.engine = engine
|
32
|
+
batch = ETL::Batch::Batch.resolve(batch_instance, engine)
|
33
|
+
batch.execute
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def test_batch_with_object_should_fail
|
37
|
+
assert_raise(RuntimeError) do
|
38
|
+
batch = ETL::Batch::Batch.resolve(0, engine)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|