turbot-runner 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/turbot_runner/runner.rb +8 -4
- data/lib/turbot_runner/version.rb +1 -1
- data/spec/lib/runner_spec.rb +48 -26
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NTQ3ZDQzMjMyYzQyMTg2OWMzZDk0NWVjZjgwYWFiNjU0MmRmYzdmZg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NmEzOGE5NjViYzc5ZGZhNjZmZjg1MjNmNGNkNTI4ZWVmMDIzNjI1YQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NmY3ZmMwM2Y2ZDljNWVkODM1MWM3YjcxNjM1M2I3MjAyM2Q4YzYxM2ExNWE0
|
|
10
|
+
MGM5YmM0MDM2MGYwMTQ1Nzk2NDhmNzNiYzZmYTJmNDNjYmY3NmNhMjA0ZTJj
|
|
11
|
+
NWJhYTJlZGQ4MzhiMWQ5MjMxYTk1MjQ4ZmU5Y2U1YzE2MjYwZGU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NjQ5NDRmN2EyNGM0NzEyZWNjYTQyYWQ5MjA4YTc4YWQ1ODMyYzc0MmUzNmJm
|
|
14
|
+
OTFkNjczN2E2NGQyNTllMDE1ZGQxMTNhMmY5MmYzMDE0MGY0NDI3YjdlNmVi
|
|
15
|
+
YjA3ZjE3Mzc4ZmYwMDVlZTQ0ZWI2ZTE1NTZhMmRiZDAwNzYwYWQ=
|
data/lib/turbot_runner/runner.rb
CHANGED
|
@@ -17,6 +17,7 @@ module TurbotRunner
|
|
|
17
17
|
@record_handler = options[:record_handler]
|
|
18
18
|
@log_to_file = options[:log_to_file]
|
|
19
19
|
@timeout = options[:timeout]
|
|
20
|
+
@scraper_provided = options[:scraper_provided]
|
|
20
21
|
if options[:output_directory]
|
|
21
22
|
assert_absolute_path(options[:output_directory])
|
|
22
23
|
@output_directory = options[:output_directory]
|
|
@@ -25,10 +26,10 @@ module TurbotRunner
|
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
def run
|
|
29
|
+
def run
|
|
29
30
|
set_up_output_directory
|
|
30
31
|
|
|
31
|
-
if
|
|
32
|
+
if @scraper_provided
|
|
32
33
|
scraper_succeeded = true
|
|
33
34
|
else
|
|
34
35
|
scraper_succeeded = run_script(scraper_config)
|
|
@@ -55,8 +56,11 @@ module TurbotRunner
|
|
|
55
56
|
|
|
56
57
|
def set_up_output_directory
|
|
57
58
|
FileUtils.mkdir_p(@output_directory)
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
if !@scraper_provided
|
|
61
|
+
FileUtils.rm_f(output_file('scraper', '.out'))
|
|
62
|
+
FileUtils.rm_f(output_file('scraper', '.err'))
|
|
63
|
+
end
|
|
60
64
|
|
|
61
65
|
transformers.each do |transformer_config|
|
|
62
66
|
FileUtils.rm_f(output_file(transformer_config[:file], '.out'))
|
data/spec/lib/runner_spec.rb
CHANGED
|
@@ -15,7 +15,7 @@ describe TurbotRunner::Runner do
|
|
|
15
15
|
|
|
16
16
|
it 'produces expected output' do
|
|
17
17
|
@runner.run
|
|
18
|
-
expect(
|
|
18
|
+
expect(@runner).to have_output('scraper', 'full-scraper.out')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'returns true' do
|
|
@@ -30,7 +30,7 @@ describe TurbotRunner::Runner do
|
|
|
30
30
|
|
|
31
31
|
it 'produces expected output' do
|
|
32
32
|
@runner.run
|
|
33
|
-
expect(
|
|
33
|
+
expect(@runner).to have_output('scraper', 'full-scraper.out')
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -41,8 +41,8 @@ describe TurbotRunner::Runner do
|
|
|
41
41
|
|
|
42
42
|
it 'produces expected outputs' do
|
|
43
43
|
@runner.run
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
44
|
+
expect(@runner).to have_output('scraper', 'full-scraper.out')
|
|
45
|
+
expect(@runner).to have_output('transformer', 'full-transformer.out')
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'returns true' do
|
|
@@ -57,9 +57,9 @@ describe TurbotRunner::Runner do
|
|
|
57
57
|
|
|
58
58
|
it 'produces expected outputs' do
|
|
59
59
|
@runner.run
|
|
60
|
-
expect(
|
|
61
|
-
expect(
|
|
62
|
-
expect(
|
|
60
|
+
expect(@runner).to have_output('scraper', 'full-scraper.out')
|
|
61
|
+
expect(@runner).to have_output('transformer1', 'full-transformer.out')
|
|
62
|
+
expect(@runner).to have_output('transformer2', 'full-transformer.out')
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it 'returns true' do
|
|
@@ -73,7 +73,7 @@ describe TurbotRunner::Runner do
|
|
|
73
73
|
expected_log = "doing...\ndone\n"
|
|
74
74
|
runner = test_runner('logging-bot', :log_to_file => true)
|
|
75
75
|
runner.run
|
|
76
|
-
expect(
|
|
76
|
+
expect(runner).to have_error_output_matching('scraper', expected_log)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -111,7 +111,7 @@ describe TurbotRunner::Runner do
|
|
|
111
111
|
|
|
112
112
|
it 'writes error to stderr' do
|
|
113
113
|
@runner.run
|
|
114
|
-
expect(
|
|
114
|
+
expect(@runner).to have_error_output_matching('scraper', /Oh no/)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
it 'still runs the transformers' do
|
|
@@ -144,7 +144,7 @@ describe TurbotRunner::Runner do
|
|
|
144
144
|
|
|
145
145
|
it 'writes error to stderr' do
|
|
146
146
|
@runner.run
|
|
147
|
-
expect(
|
|
147
|
+
expect(@runner).to have_error_output_matching('transformer2', /Oh no/)
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
|
|
@@ -176,7 +176,7 @@ describe TurbotRunner::Runner do
|
|
|
176
176
|
|
|
177
177
|
it 'produces expected output' do
|
|
178
178
|
@runner.run
|
|
179
|
-
expect(
|
|
179
|
+
expect(@runner).to have_output('scraper', 'truncated-scraper.out')
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
it 'returns true' do
|
|
@@ -252,6 +252,32 @@ describe TurbotRunner::Runner do
|
|
|
252
252
|
expect(@runner).to succeed
|
|
253
253
|
end
|
|
254
254
|
end
|
|
255
|
+
|
|
256
|
+
context 'when the scraped data is provided' do
|
|
257
|
+
before do
|
|
258
|
+
FileUtils.cp(
|
|
259
|
+
File.join('spec', 'outputs', 'full-scraper.out'),
|
|
260
|
+
File.join(File.dirname(__FILE__), '../bots', 'bot-with-transformer', 'output', 'scraper.out')
|
|
261
|
+
)
|
|
262
|
+
@runner = test_runner('bot-with-transformer', :scraper_provided => true)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it 'does not run scraper' do
|
|
266
|
+
expect(@runner).to receive(:run_script).once.with(
|
|
267
|
+
hash_including(:file => 'transformer.rb'), anything
|
|
268
|
+
)
|
|
269
|
+
@runner.run
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it 'succeeds' do
|
|
273
|
+
expect(@runner).to succeed
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
it 'produces expected transformed output' do
|
|
277
|
+
@runner.run
|
|
278
|
+
expect(@runner).to have_output('transformer', 'full-transformer.out')
|
|
279
|
+
end
|
|
280
|
+
end
|
|
255
281
|
end
|
|
256
282
|
|
|
257
283
|
describe '#process_output' do
|
|
@@ -317,10 +343,8 @@ describe TurbotRunner::Runner do
|
|
|
317
343
|
end
|
|
318
344
|
|
|
319
345
|
|
|
320
|
-
RSpec::Matchers.define
|
|
321
|
-
match do |
|
|
322
|
-
runner, script = actual
|
|
323
|
-
|
|
346
|
+
RSpec::Matchers.define(:have_output) do |script, expected|
|
|
347
|
+
match do |runner|
|
|
324
348
|
expected_path = File.join('spec', 'outputs', expected)
|
|
325
349
|
expected_output = File.readlines(expected_path).map {|line| JSON.parse(line)}
|
|
326
350
|
actual_path = File.join(runner.base_directory, 'output', "#{script}.out")
|
|
@@ -330,6 +354,15 @@ RSpec::Matchers.define :have_output do |expected|
|
|
|
330
354
|
end
|
|
331
355
|
|
|
332
356
|
|
|
357
|
+
RSpec::Matchers.define(:have_error_output_matching) do |script, expected|
|
|
358
|
+
match do |runner|
|
|
359
|
+
actual_path = File.join(runner.base_directory, 'output', "#{script}.err")
|
|
360
|
+
actual_output = File.read(actual_path)
|
|
361
|
+
expect(actual_output).to match(expected)
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
|
|
333
366
|
RSpec::Matchers.define(:succeed) do
|
|
334
367
|
match do |runner|
|
|
335
368
|
expect(runner.run).to eq(TurbotRunner::Runner::RC_OK)
|
|
@@ -350,17 +383,6 @@ RSpec::Matchers.define(:fail_in_transformer) do
|
|
|
350
383
|
end
|
|
351
384
|
end
|
|
352
385
|
|
|
353
|
-
|
|
354
|
-
RSpec::Matchers.define :have_error_output_matching do |expected|
|
|
355
|
-
match do |actual|
|
|
356
|
-
runner, script = actual
|
|
357
|
-
|
|
358
|
-
actual_path = File.join(runner.base_directory, 'output', "#{script}.err")
|
|
359
|
-
actual_output = File.read(actual_path)
|
|
360
|
-
expect(actual_output).to match(expected)
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
386
|
def test_runner(name, opts={})
|
|
365
387
|
test_bot_location = File.join(File.dirname(__FILE__), '../bots', name)
|
|
366
388
|
TurbotRunner::Runner.new(test_bot_location, opts)
|