kiba 3.6.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,6 @@ module SharedTests
5
5
  end
6
6
 
7
7
  def shared_tests(desc, *args)
8
- self.class_exec(*args, &@@shared_tests.fetch(desc))
8
+ class_exec(*args, &@@shared_tests.fetch(desc))
9
9
  end
10
10
  end
@@ -2,7 +2,7 @@ class AggregateTransform
2
2
  def initialize(options)
3
3
  @aggregate_size = options.fetch(:aggregate_size)
4
4
  end
5
-
5
+
6
6
  def process(row)
7
7
  @buffer ||= []
8
8
  @buffer << row
@@ -12,7 +12,7 @@ class AggregateTransform
12
12
  end
13
13
  nil
14
14
  end
15
-
15
+
16
16
  def close
17
17
  yield @buffer unless @buffer.empty?
18
18
  end
@@ -2,8 +2,8 @@ class TestArrayDestination
2
2
  def initialize(array)
3
3
  @array = array
4
4
  end
5
-
5
+
6
6
  def write(row)
7
7
  @array << row
8
8
  end
9
- end
9
+ end
@@ -1,9 +1,9 @@
1
- require 'csv'
1
+ require "csv"
2
2
 
3
3
  # simple destination, not checking that each row has all the fields
4
4
  class TestCsvDestination
5
5
  def initialize(output_file)
6
- @csv = CSV.open(output_file, 'w')
6
+ @csv = CSV.open(output_file, "w")
7
7
  @headers_written = false
8
8
  end
9
9
 
@@ -1,4 +1,4 @@
1
- require 'csv'
1
+ require "csv"
2
2
 
3
3
  class TestCsvSource
4
4
  def initialize(input_file)
@@ -2,11 +2,11 @@ class TestDestinationReturningNil
2
2
  def initialize(options = {})
3
3
  on_init = options[:on_init]
4
4
  # A little trick to allow outer references to this instance
5
- on_init.call(self) if on_init
5
+ on_init&.call(self)
6
6
  end
7
-
7
+
8
8
  def write(row)
9
9
  (@written_rows ||= []) << row
10
10
  nil
11
11
  end
12
- end
12
+ end
@@ -6,4 +6,4 @@ class TestDuplicateRowTranform
6
6
  end
7
7
  nil
8
8
  end
9
- end
9
+ end
@@ -7,7 +7,7 @@ class TestKeywordArgumentsComponent
7
7
  }
8
8
  on_init&.call(values)
9
9
  end
10
-
10
+
11
11
  def each
12
12
  # no-op
13
13
  end
@@ -1,13 +1,13 @@
1
1
  # a mock component to test Ruby 3 keyword argument support
2
2
  class TestMixedArgumentsComponent
3
- def initialize(some_value, mandatory:, optional: nil, on_init:)
3
+ def initialize(some_value, mandatory:, on_init:, optional: nil)
4
4
  @values = {}
5
5
  @values[:some_value] = some_value
6
6
  @values[:mandatory] = mandatory
7
7
  @values[:optional] = optional
8
8
  on_init&.call(@values)
9
9
  end
10
-
10
+
11
11
  def each
12
12
  # no-op
13
13
  end
@@ -5,4 +5,4 @@ class TestYieldingTransform
5
5
  end
6
6
  {item: "classic-return-value"}
7
7
  end
8
- end
8
+ end
@@ -1,28 +1,33 @@
1
- require_relative 'helper'
1
+ require_relative "helper"
2
2
 
3
- require_relative 'support/test_csv_source'
4
- require_relative 'support/test_csv_destination'
5
- require_relative 'support/test_rename_field_transform'
6
- require_relative 'support/test_enumerable_source'
7
- require_relative 'support/test_source_that_reads_at_instantiation_time'
3
+ require_relative "support/test_csv_source"
4
+ require_relative "support/test_csv_destination"
5
+ require_relative "support/test_rename_field_transform"
6
+ require_relative "support/test_enumerable_source"
7
+ require_relative "support/test_source_that_reads_at_instantiation_time"
8
8
 
9
9
  # End-to-end tests go here
10
10
  class TestIntegration < Kiba::Test
11
- def output_file; 'test/tmp/output.csv'; end
12
- def input_file; 'test/tmp/input.csv'; end
11
+ def output_file
12
+ "test/tmp/output.csv"
13
+ end
14
+
15
+ def input_file
16
+ "test/tmp/input.csv"
17
+ end
13
18
 
14
19
  def sample_csv_data
15
- <<CSV
16
- first_name,last_name,sex
17
- John,Doe,M
18
- Mary,Johnson,F
19
- Cindy,Backgammon,F
20
- Patrick,McWire,M
21
- CSV
20
+ <<~CSV
21
+ first_name,last_name,sex
22
+ John,Doe,M
23
+ Mary,Johnson,F
24
+ Cindy,Backgammon,F
25
+ Patrick,McWire,M
26
+ CSV
22
27
  end
23
28
 
24
29
  def clean
25
- remove_files(*Dir['test/tmp/*.csv'])
30
+ remove_files(*Dir["test/tmp/*.csv"])
26
31
  end
27
32
 
28
33
  def setup
@@ -37,36 +42,36 @@ CSV
37
42
  def test_csv_to_csv
38
43
  # parse the ETL script (this won't run it)
39
44
  control = Kiba.parse do
40
- source TestCsvSource, 'test/tmp/input.csv'
45
+ source TestCsvSource, "test/tmp/input.csv"
41
46
 
42
47
  transform do |row|
43
48
  row[:sex] = case row[:sex]
44
- when 'M' then 'Male'
45
- when 'F' then 'Female'
46
- else 'Unknown'
49
+ when "M" then "Male"
50
+ when "F" then "Female"
51
+ else "Unknown"
47
52
  end
48
53
  row # must be returned
49
54
  end
50
55
 
51
56
  # returning nil dismisses the row
52
57
  transform do |row|
53
- row[:sex] == 'Female' ? row : nil
58
+ row[:sex] == "Female" ? row : nil
54
59
  end
55
60
 
56
61
  transform TestRenameFieldTransform, :sex, :sex_2015
57
62
 
58
- destination TestCsvDestination, 'test/tmp/output.csv'
63
+ destination TestCsvDestination, "test/tmp/output.csv"
59
64
  end
60
65
 
61
66
  # run the parsed ETL script
62
67
  Kiba.run(control)
63
68
 
64
69
  # verify the output
65
- assert_equal <<CSV, IO.read(output_file)
66
- first_name,last_name,sex_2015
67
- Mary,Johnson,Female
68
- Cindy,Backgammon,Female
69
- CSV
70
+ assert_equal <<~CSV, IO.read(output_file)
71
+ first_name,last_name,sex_2015
72
+ Mary,Johnson,Female
73
+ Cindy,Backgammon,Female
74
+ CSV
70
75
  end
71
76
 
72
77
  def test_variable_access
@@ -97,18 +102,18 @@ CSV
97
102
 
98
103
  Kiba.run(control)
99
104
 
100
- assert_equal 'Count is now 103', message
105
+ assert_equal "Count is now 103", message
101
106
  end
102
107
 
103
108
  def test_file_created_by_pre_process_can_be_read_by_source_at_instantiation_time
104
- remove_files('test/tmp/eager.csv')
109
+ remove_files("test/tmp/eager.csv")
105
110
 
106
111
  control = Kiba.parse do
107
112
  pre_process do
108
- IO.write('test/tmp/eager.csv', 'something')
113
+ IO.write("test/tmp/eager.csv", "something")
109
114
  end
110
115
 
111
- source SourceThatReadsAtInstantionTime, 'test/tmp/eager.csv'
116
+ source SourceThatReadsAtInstantionTime, "test/tmp/eager.csv"
112
117
  end
113
118
 
114
119
  Kiba.run(control)
data/test/test_parser.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative 'helper'
1
+ require_relative "helper"
2
2
 
3
- require_relative 'support/test_rename_field_transform'
3
+ require_relative "support/test_rename_field_transform"
4
4
 
5
5
  class DummyClass
6
6
  end
@@ -8,21 +8,20 @@ end
8
8
  class TestParser < Kiba::Test
9
9
  def test_source_definition
10
10
  control = Kiba.parse do
11
- source DummyClass, 'has', 'args'
11
+ source DummyClass, "has", "args"
12
12
  end
13
13
 
14
14
  assert_equal DummyClass, control.sources[0][:klass]
15
- assert_equal %w(has args), control.sources[0][:args]
15
+ assert_equal %w[has args], control.sources[0][:args]
16
16
  end
17
-
18
- # NOTE: useful for anything not using the CLI (e.g. sidekiq)
17
+
19
18
  def test_block_parsing_with_reference_to_outside_variable
20
19
  some_variable = Object.new
21
-
20
+
22
21
  control = Kiba.parse do
23
22
  source DummyClass, some_variable
24
23
  end
25
-
24
+
26
25
  assert_equal [some_variable], control.sources[0][:args]
27
26
  end
28
27
 
@@ -45,11 +44,11 @@ class TestParser < Kiba::Test
45
44
 
46
45
  def test_destination_definition
47
46
  control = Kiba.parse do
48
- destination DummyClass, 'has', 'args'
47
+ destination DummyClass, "has", "args"
49
48
  end
50
49
 
51
50
  assert_equal DummyClass, control.destinations[0][:klass]
52
- assert_equal %w(has args), control.destinations[0][:args]
51
+ assert_equal %w[has args], control.destinations[0][:args]
53
52
  end
54
53
 
55
54
  def test_block_post_process_definition
@@ -59,7 +58,7 @@ class TestParser < Kiba::Test
59
58
 
60
59
  assert_instance_of Proc, control.post_processes[0][:block]
61
60
  end
62
-
61
+
63
62
  def test_block_pre_process_definition
64
63
  control = Kiba.parse do
65
64
  pre_process {}
@@ -71,16 +70,16 @@ class TestParser < Kiba::Test
71
70
  def test_config
72
71
  control = Kiba.parse do
73
72
  extend Kiba::DSLExtensions::Config
74
-
73
+
75
74
  config :context, key: "value", other_key: "other_value"
76
75
  end
77
-
78
- assert_equal({ context: {
76
+
77
+ assert_equal({context: {
79
78
  key: "value",
80
79
  other_key: "other_value"
81
80
  }}, control.config)
82
81
  end
83
-
82
+
84
83
  def test_config_override
85
84
  control = Kiba.parse do
86
85
  extend Kiba::DSLExtensions::Config
@@ -88,8 +87,8 @@ class TestParser < Kiba::Test
88
87
  config :context, key: "value", other_key: "other_value"
89
88
  config :context, key: "new_value"
90
89
  end
91
-
92
- assert_equal({ context: {
90
+
91
+ assert_equal({context: {
93
92
  key: "new_value",
94
93
  other_key: "other_value"
95
94
  }}, control.config)
data/test/test_run.rb CHANGED
@@ -1,11 +1,11 @@
1
- require_relative 'helper'
2
- require 'minitest/mock'
3
- require_relative 'support/test_enumerable_source'
4
- require_relative 'support/test_array_destination'
1
+ require_relative "helper"
2
+ require "minitest/mock"
3
+ require_relative "support/test_enumerable_source"
4
+ require_relative "support/test_array_destination"
5
5
 
6
6
  class TestRun < Kiba::Test
7
7
  def test_ensure_kiba_defaults_to_streaming_runner
8
- cb = -> (job) { "Streaming runner called" }
8
+ cb = ->(job) { "Streaming runner called" }
9
9
  Kiba::StreamingRunner.stub(:run, cb) do
10
10
  job = Kiba::Control.new
11
11
  assert_equal "Streaming runner called", Kiba.run(job)
@@ -29,9 +29,8 @@ class TestRun < Kiba::Test
29
29
 
30
30
  def test_forbids_multiple_args
31
31
  assert_raises ArgumentError do
32
- job = Kiba.parse { }
32
+ job = Kiba.parse {}
33
33
  Kiba.run(job) do
34
- #
35
34
  end
36
35
  end
37
36
  end
@@ -1,13 +1,13 @@
1
- require_relative 'helper'
2
- require_relative 'support/test_enumerable_source'
3
- require_relative 'support/test_array_destination'
4
- require_relative 'support/test_yielding_transform'
5
- require_relative 'support/test_duplicate_row_transform'
6
- require_relative 'support/test_close_yielding_transform'
7
- require_relative 'support/test_non_closing_transform'
8
- require_relative 'shared_runner_tests'
9
- require_relative 'support/test_keyword_arguments_component'
10
- require_relative 'support/test_mixed_arguments_component'
1
+ require_relative "helper"
2
+ require_relative "support/test_enumerable_source"
3
+ require_relative "support/test_array_destination"
4
+ require_relative "support/test_yielding_transform"
5
+ require_relative "support/test_duplicate_row_transform"
6
+ require_relative "support/test_close_yielding_transform"
7
+ require_relative "support/test_non_closing_transform"
8
+ require_relative "shared_runner_tests"
9
+ require_relative "support/test_keyword_arguments_component"
10
+ require_relative "support/test_mixed_arguments_component"
11
11
 
12
12
  class TestStreamingRunner < Kiba::Test
13
13
  def kiba_run(job)
@@ -16,11 +16,11 @@ class TestStreamingRunner < Kiba::Test
16
16
  end
17
17
 
18
18
  include SharedRunnerTests
19
-
19
+
20
20
  def test_yielding_class_transform
21
21
  input_row = {tags: ["one", "two", "three"]}
22
22
  destination_array = []
23
-
23
+
24
24
  job = Kiba.parse do
25
25
  # provide a single row as the input
26
26
  source TestEnumerableSource, [input_row]
@@ -33,24 +33,24 @@ class TestStreamingRunner < Kiba::Test
33
33
 
34
34
  destination TestArrayDestination, destination_array
35
35
  end
36
-
36
+
37
37
  kiba_run(job)
38
-
38
+
39
39
  assert_equal [
40
- {item: 'one'},
41
- {item: 'one'},
40
+ {item: "one"},
41
+ {item: "one"},
42
42
 
43
- {item: 'two'},
44
- {item: 'two'},
43
+ {item: "two"},
44
+ {item: "two"},
45
45
 
46
- {item: 'three'},
47
- {item: 'three'},
46
+ {item: "three"},
47
+ {item: "three"},
48
48
 
49
- {item: 'classic-return-value'},
50
- {item: 'classic-return-value'}
49
+ {item: "classic-return-value"},
50
+ {item: "classic-return-value"}
51
51
  ], destination_array
52
52
  end
53
-
53
+
54
54
  def test_transform_yielding_from_close
55
55
  destination_array = []
56
56
  job = Kiba.parse do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaut Barrère
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,17 +66,30 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Lightweight ETL for Ruby
70
84
  email:
71
85
  - thibaut.barrere@gmail.com
72
- executables:
73
- - kiba
86
+ executables: []
74
87
  extensions: []
75
88
  extra_rdoc_files: []
76
89
  files:
77
90
  - ".github/FUNDING.yml"
91
+ - ".github/workflows/ci.yml"
78
92
  - ".gitignore"
79
- - ".travis.yml"
80
93
  - COMM-LICENSE.md
81
94
  - Changes.md
82
95
  - Gemfile
@@ -85,15 +98,12 @@ files:
85
98
  - Pro-Changes.md
86
99
  - README.md
87
100
  - Rakefile
88
- - appveyor.yml
89
- - bin/kiba
90
101
  - kiba.gemspec
91
102
  - lib/kiba.rb
92
103
  - lib/kiba/context.rb
93
104
  - lib/kiba/control.rb
94
105
  - lib/kiba/dsl_extensions/config.rb
95
106
  - lib/kiba/parser.rb
96
- - lib/kiba/runner.rb
97
107
  - lib/kiba/streaming_runner.rb
98
108
  - lib/kiba/version.rb
99
109
  - test/helper.rb
@@ -116,10 +126,9 @@ files:
116
126
  - test/test_integration.rb
117
127
  - test/test_parser.rb
118
128
  - test/test_run.rb
119
- - test/test_runner.rb
120
129
  - test/test_streaming_runner.rb
121
130
  - test/tmp/.gitkeep
122
- homepage: http://thbar.github.io/kiba/
131
+ homepage: https://www.kiba-etl.org
123
132
  licenses:
124
133
  - LGPL-3.0
125
134
  metadata:
@@ -165,6 +174,5 @@ test_files:
165
174
  - test/test_integration.rb
166
175
  - test/test_parser.rb
167
176
  - test/test_run.rb
168
- - test/test_runner.rb
169
177
  - test/test_streaming_runner.rb
170
178
  - test/tmp/.gitkeep