ruby-aws 1.6.0
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.
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/History.txt +75 -0
- data/LICENSE.txt +202 -0
- data/Manifest.txt +72 -0
- data/NOTICE.txt +4 -0
- data/README.txt +105 -0
- data/Rakefile +33 -0
- data/bin/ruby-aws +9 -0
- data/lib/amazon/util.rb +10 -0
- data/lib/amazon/util/binder.rb +48 -0
- data/lib/amazon/util/data_reader.rb +169 -0
- data/lib/amazon/util/filter_chain.rb +79 -0
- data/lib/amazon/util/hash_nesting.rb +93 -0
- data/lib/amazon/util/lazy_results.rb +59 -0
- data/lib/amazon/util/logging.rb +23 -0
- data/lib/amazon/util/paginated_iterator.rb +70 -0
- data/lib/amazon/util/proactive_results.rb +116 -0
- data/lib/amazon/util/threadpool.rb +129 -0
- data/lib/amazon/util/user_data_store.rb +100 -0
- data/lib/amazon/webservices/mechanical_turk.rb +123 -0
- data/lib/amazon/webservices/mechanical_turk_requester.rb +274 -0
- data/lib/amazon/webservices/mturk/mechanical_turk_error_handler.rb +150 -0
- data/lib/amazon/webservices/mturk/question_generator.rb +58 -0
- data/lib/amazon/webservices/util/amazon_authentication_relay.rb +72 -0
- data/lib/amazon/webservices/util/command_line.rb +157 -0
- data/lib/amazon/webservices/util/convenience_wrapper.rb +90 -0
- data/lib/amazon/webservices/util/filter_proxy.rb +45 -0
- data/lib/amazon/webservices/util/mock_transport.rb +70 -0
- data/lib/amazon/webservices/util/request_signer.rb +42 -0
- data/lib/amazon/webservices/util/rest_transport.rb +120 -0
- data/lib/amazon/webservices/util/soap_simplifier.rb +48 -0
- data/lib/amazon/webservices/util/soap_transport.rb +20 -0
- data/lib/amazon/webservices/util/soap_transport_header_handler.rb +27 -0
- data/lib/amazon/webservices/util/unknown_result_exception.rb +27 -0
- data/lib/amazon/webservices/util/validation_exception.rb +55 -0
- data/lib/amazon/webservices/util/xml_simplifier.rb +61 -0
- data/lib/ruby-aws.rb +19 -0
- data/lib/ruby-aws/version.rb +6 -0
- data/run_rcov.sh +1 -0
- data/samples/mturk/best_image/BestImage.rb +61 -0
- data/samples/mturk/best_image/best_image.properties +39 -0
- data/samples/mturk/best_image/best_image.question +82 -0
- data/samples/mturk/blank_slate/BlankSlate.rb +63 -0
- data/samples/mturk/blank_slate/BlankSlate_multithreaded.rb +67 -0
- data/samples/mturk/helloworld/MTurkHelloWorld.rb +56 -0
- data/samples/mturk/helloworld/mturk.yml +8 -0
- data/samples/mturk/review_policy/ReviewPolicy.rb +139 -0
- data/samples/mturk/review_policy/review_policy.question +30 -0
- data/samples/mturk/reviewer/Reviewer.rb +103 -0
- data/samples/mturk/reviewer/mturk.yml +8 -0
- data/samples/mturk/simple_survey/SimpleSurvey.rb +90 -0
- data/samples/mturk/simple_survey/simple_survey.question +30 -0
- data/samples/mturk/site_category/SiteCategory.rb +87 -0
- data/samples/mturk/site_category/externalpage.htm +71 -0
- data/samples/mturk/site_category/site_category.input +6 -0
- data/samples/mturk/site_category/site_category.properties +45 -0
- data/samples/mturk/site_category/site_category.question +9 -0
- data/test/mturk/test_changehittypeofhit.rb +130 -0
- data/test/mturk/test_error_handler.rb +137 -0
- data/test/mturk/test_mechanical_turk_requester.rb +178 -0
- data/test/mturk/test_mock_mechanical_turk_requester.rb +205 -0
- data/test/test_ruby-aws.rb +24 -0
- data/test/unit/test_binder.rb +89 -0
- data/test/unit/test_data_reader.rb +135 -0
- data/test/unit/test_exceptions.rb +32 -0
- data/test/unit/test_hash_nesting.rb +99 -0
- data/test/unit/test_lazy_results.rb +89 -0
- data/test/unit/test_mock_transport.rb +132 -0
- data/test/unit/test_paginated_iterator.rb +58 -0
- data/test/unit/test_proactive_results.rb +108 -0
- data/test/unit/test_question_generator.rb +55 -0
- data/test/unit/test_threadpool.rb +50 -0
- data/test/unit/test_user_data_store.rb +80 -0
- metadata +238 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,205 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require 'test/unit/testcase'
|
5
|
+
require 'ruby-aws'
|
6
|
+
require 'amazon/webservices/util/mock_transport'
|
7
|
+
|
8
|
+
class TestMockMechanicalTurkRequester < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@mock = Amazon::WebServices::Util::MockTransport.new
|
12
|
+
@mturk = Amazon::WebServices::MechanicalTurkRequester.new( :Transport => @mock, :AWSAccessKey => 'bogus', :AWSAccessKeyId => 'fake' )
|
13
|
+
end
|
14
|
+
|
15
|
+
def testGetAccountBalance
|
16
|
+
res = @mturk.getAccountBalance # using the convenience layer method
|
17
|
+
assert_equal nil, res
|
18
|
+
res = @mturk.getAccountBalanceRaw({}) # using the raw method ( no default parameters )
|
19
|
+
assert_equal nil, res
|
20
|
+
res = @mturk.GetAccountBalance # using pass-through method ( no convenience processing )
|
21
|
+
assert_equal true, res[:MockResult][:Mock]
|
22
|
+
|
23
|
+
assert_equal 3, @mock.call_buffer.size
|
24
|
+
@mock.each do |request|
|
25
|
+
assert_equal :GetAccountBalance, request.name
|
26
|
+
assert request.args
|
27
|
+
[:AWSAccessKeyId, :Signature, :Timestamp, :Request].each { |key| assert request.args[key]}
|
28
|
+
assert_equal( {}, request.request )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def testCreateHIT
|
33
|
+
res = @mturk.createHIT # convenience layer, will auto-populate some default parameters
|
34
|
+
res = @mturk.createHITRaw({}) # raw method, no default parameters
|
35
|
+
res = @mturk.CreateHIT # pass-through method ( no convenience processing )
|
36
|
+
|
37
|
+
assert_equal 3, @mock.call_buffer.size
|
38
|
+
|
39
|
+
default_call = @mock.next # request from convenience layer
|
40
|
+
request = default_call.request
|
41
|
+
assert !request.keys.empty?
|
42
|
+
expected = [:MaxAssignments, :AssignmentDurationInSeconds, :AutoApprovalDelayInSeconds, :LifetimeInSeconds]
|
43
|
+
assert_equal [], request.keys - expected, 'Convenience layer should not populate unexpected arguments'
|
44
|
+
assert_equal [], expected - request.keys, 'Convenience layer should populate all expected arguments'
|
45
|
+
|
46
|
+
@mock.each do |call|
|
47
|
+
# both remaining calls should have no arguments
|
48
|
+
assert_equal( {}, call.request, 'Raw calls should not auto-populate arguments')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def testCreateHITs
|
53
|
+
@mock.listen do |call|
|
54
|
+
{:RegisterHITTypeResult => {:HITTypeId => 'specialType', :Request => {}} } if call.name == :RegisterHITType
|
55
|
+
end
|
56
|
+
|
57
|
+
template = { :Arg1 => 'Param2', :RequesterAnnotation => 'blub' }
|
58
|
+
question_template = "blarg <%= @zip %> foo"
|
59
|
+
data_set = [ { :zip => 'poodle' }, { :zip => 'fizz' } ]
|
60
|
+
|
61
|
+
result = @mturk.createHITs( template, question_template, data_set )
|
62
|
+
|
63
|
+
assert_equal 2, result[:Created].size
|
64
|
+
assert_equal 0, result[:Failed].size
|
65
|
+
|
66
|
+
register_call = @mock.next
|
67
|
+
assert_equal :RegisterHITType, register_call.name
|
68
|
+
assert_equal(
|
69
|
+
{ :AssignmentDurationInSeconds=>3600, # default
|
70
|
+
:AutoApprovalDelayInSeconds=>604800, # default
|
71
|
+
:Arg1=>"Param2" # there's our arg!
|
72
|
+
},
|
73
|
+
register_call.request )
|
74
|
+
expected_questions = [ "blarg poodle foo", "blarg fizz foo" ]
|
75
|
+
@mock.each do |call|
|
76
|
+
assert_equal :CreateHIT, call.name
|
77
|
+
assert_equal 'specialType', call.request[:HITTypeId]
|
78
|
+
assert_equal call.request[:Question], expected_questions.delete( call.request[:Question] )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def testCreateHITsWithMaxAssignment
|
83
|
+
@mock.listen do |call|
|
84
|
+
case call.name
|
85
|
+
when :RegisterHITType
|
86
|
+
{:RegisterHITTypeResult => {:HITTypeId => 'mockHITType', :Request => {} } }
|
87
|
+
else
|
88
|
+
{}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
template = { :Description => 'foo bar', :MaxAssignments => 2, :RequesterAnnotation => "Funky <%= @jazz %>" }
|
93
|
+
question = "who what <%= @where %>"
|
94
|
+
data_set = [ { :jazz => "LaLa", :where => 1}, {:jazz => nil, :where => 2, :MaxAssignments => 1}, {:jazz => "Poodle", :where => nil} ]
|
95
|
+
|
96
|
+
results = @mturk.createHITs( template, question, data_set )
|
97
|
+
|
98
|
+
assert_equal [], results[:Failed]
|
99
|
+
assert_equal 3, results[:Created].size
|
100
|
+
|
101
|
+
ht = @mock.next
|
102
|
+
assert_equal :RegisterHITType, ht.name
|
103
|
+
assert_equal 'foo bar', ht.request[:Description]
|
104
|
+
assert_equal nil, ht.request[:MaxAssignments]
|
105
|
+
|
106
|
+
3.times do
|
107
|
+
hit = @mock.next
|
108
|
+
assert_equal :CreateHIT, hit.name
|
109
|
+
assert_equal 'mockHITType', hit.request[:HITTypeId]
|
110
|
+
case hit.request[:Question]
|
111
|
+
when 'who what 1'
|
112
|
+
assert_equal 2, hit.request[:MaxAssignments]
|
113
|
+
assert_equal 'Funky LaLa', hit.request[:RequesterAnnotation]
|
114
|
+
when 'who what 2'
|
115
|
+
assert_equal 1, hit.request[:MaxAssignments]
|
116
|
+
assert_equal 'Funky ', hit.request[:RequesterAnnotation]
|
117
|
+
when 'who what '
|
118
|
+
assert_equal 2, hit.request[:MaxAssignments]
|
119
|
+
assert_equal 'Funky Poodle', hit.request[:RequesterAnnotation]
|
120
|
+
else
|
121
|
+
fail 'generated an unexpected Question'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal nil, @mock.next
|
126
|
+
end
|
127
|
+
|
128
|
+
def testCreatHITsWithFailure
|
129
|
+
@mock.listen do |call|
|
130
|
+
raise "Mock hates you" if call.request[:Question] and call.request[:Question] =~ /poodle/
|
131
|
+
{:RegisterHITTypeResult => {:HITTypeId => 'specialType', :Request => {}} } if call.name == :RegisterHITType
|
132
|
+
end
|
133
|
+
|
134
|
+
template = { :Arg1 => 'Param2', :RequesterAnnotation => 'blub' }
|
135
|
+
question_template = "blarg <%= @zip %> foo"
|
136
|
+
data_set = [ { :zip => 'poodle' }, { :zip => 'fizz' } ]
|
137
|
+
|
138
|
+
result = @mturk.createHITs( template, question_template, data_set )
|
139
|
+
|
140
|
+
assert_equal 1, result[:Created].size
|
141
|
+
assert_equal 1, result[:Failed].size
|
142
|
+
|
143
|
+
assert_equal "Mock hates you", result[:Failed].first[:Error]
|
144
|
+
end
|
145
|
+
|
146
|
+
def testGetHITResults
|
147
|
+
# need to set up a listener to feed back hit and assignment attributes for testing results and work with pagination
|
148
|
+
assignments_per_hit = 31
|
149
|
+
@mock.mock_reply = {:OperationRequest => {}}
|
150
|
+
@mock.listen do |call|
|
151
|
+
case call.name
|
152
|
+
when :GetHIT
|
153
|
+
{:HIT => { :HITId => call.request[:HITId], :MockHITAttribute => 'amazing', :Request => {} } }
|
154
|
+
when :GetAssignmentsForHIT
|
155
|
+
size = call.request[:PageSize]
|
156
|
+
num = call.request[:PageNumber]
|
157
|
+
index = size * (num-1)
|
158
|
+
max = ( assignments_per_hit > index+size ) ? index+size : assignments_per_hit
|
159
|
+
res = []
|
160
|
+
index.upto(max-1) do |i|
|
161
|
+
res << { :HITId => call.request[:HITId], :AssignmentId => i, :MockAssignmentAttribute => 'stunning' }
|
162
|
+
end
|
163
|
+
{ :GetAssignmentsForHITResult => { :Assignment => res, :Request => {} } }
|
164
|
+
else
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
list = %w( hitid1 hitid2 amazinghit3 lamehit4 ).collect {|id| { :HITId => id } }
|
170
|
+
results = @mturk.getHITResults( list )
|
171
|
+
|
172
|
+
assert_equal assignments_per_hit*list.size, results.size
|
173
|
+
results.each { |item|
|
174
|
+
assert_not_nil item[:HITId]
|
175
|
+
assert_equal 'amazing', item[:MockHITAttribute]
|
176
|
+
assert_not_nil item[:AssignmentId]
|
177
|
+
assert_equal 'stunning', item[:MockAssignmentAttribute]
|
178
|
+
}
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
def testAvailableFunds
|
183
|
+
# TODO
|
184
|
+
end
|
185
|
+
|
186
|
+
def testSimplifyAnswer
|
187
|
+
rawAnswer = <<EOF
|
188
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
189
|
+
<QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd">
|
190
|
+
<Answer>
|
191
|
+
<QuestionIdentifier>1</QuestionIdentifier>
|
192
|
+
<FreeText>yes, sir</FreeText>
|
193
|
+
</Answer>
|
194
|
+
<Answer>
|
195
|
+
<QuestionIdentifier>pudding</QuestionIdentifier>
|
196
|
+
<SelectionIdentifier>B+</SelectionIdentifier>
|
197
|
+
</Answer>
|
198
|
+
</QuestionFormAnswers>
|
199
|
+
EOF
|
200
|
+
expected = { 1 => 'yes, sir', 'pudding' => 'B+' }
|
201
|
+
result = @mturk.simplifyAnswer( rawAnswer )
|
202
|
+
assert_equal expected, result
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
|
4
|
+
# Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'ruby-aws'
|
9
|
+
|
10
|
+
class TestRubyAWS < Test::Unit::TestCase
|
11
|
+
|
12
|
+
VERSION_NUMBER_PATTERN = '\d+\.\d+\.\d+(\.[a-zA-Z\d]+)*'
|
13
|
+
|
14
|
+
def testVersion
|
15
|
+
assert( RubyAWS::VERSION =~ /^#{VERSION_NUMBER_PATTERN}$/ , "RubyAWS::VERSION is incorrectly formatted")
|
16
|
+
end
|
17
|
+
|
18
|
+
def testAgent
|
19
|
+
assert( RubyAWS.agent =~ /^ruby-aws\/#{VERSION_NUMBER_PATTERN}$/ )
|
20
|
+
assert( RubyAWS.agent('Tester') =~ /^ruby-aws\/#{VERSION_NUMBER_PATTERN} Tester$/ )
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require 'test/unit/testcase'
|
5
|
+
require 'amazon/util/binder'
|
6
|
+
|
7
|
+
class TestBinder < Test::Unit::TestCase
|
8
|
+
include Amazon::Util
|
9
|
+
|
10
|
+
SAMPLE_VARS = { :a => 'pudding', :b => 'pie', :c => 'cheesecake' }
|
11
|
+
|
12
|
+
SAMPLE_TEMPLATE = "I love <%= @b %> (especially with <%= @a %>), but I love <%= @c %> even more!"
|
13
|
+
|
14
|
+
SAMPLE_EXPECTED = "I love pie (especially with pudding), but I love cheesecake even more!"
|
15
|
+
|
16
|
+
def testConstructorConfig
|
17
|
+
b = Binder.new( SAMPLE_VARS )
|
18
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
19
|
+
assert_equal SAMPLE_EXPECTED, result
|
20
|
+
end
|
21
|
+
|
22
|
+
def testBuilderConfig
|
23
|
+
b = Binder.new { |bb| SAMPLE_VARS.each {|k,v| bb.set( k, v ) } }
|
24
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
25
|
+
assert_equal SAMPLE_EXPECTED, result
|
26
|
+
end
|
27
|
+
|
28
|
+
def testInstanceConfig
|
29
|
+
b = Binder.new
|
30
|
+
SAMPLE_VARS.each { |k,v| b.set( k, v ) }
|
31
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
32
|
+
assert_equal SAMPLE_EXPECTED, result
|
33
|
+
end
|
34
|
+
|
35
|
+
def testMergeConfig
|
36
|
+
b = Binder.new
|
37
|
+
b.merge SAMPLE_VARS
|
38
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
39
|
+
assert_equal SAMPLE_EXPECTED, result
|
40
|
+
end
|
41
|
+
|
42
|
+
def testCombinedConfig
|
43
|
+
keys = SAMPLE_VARS.keys
|
44
|
+
b = Binder.new( keys[0] => SAMPLE_VARS[ keys[0] ] ) { |bb|
|
45
|
+
bb.set( keys[1], SAMPLE_VARS[ keys[1] ] ) }
|
46
|
+
b.set( keys[2], SAMPLE_VARS[ keys[2] ] )
|
47
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
48
|
+
assert_equal SAMPLE_EXPECTED, result
|
49
|
+
end
|
50
|
+
|
51
|
+
def testConfigPrecedence
|
52
|
+
b = Binder.new( SAMPLE_VARS ) { |bb|
|
53
|
+
bb.merge( 'a' => 'rhubarb', 'c'=> 'gelato' ) }
|
54
|
+
b.merge( :c => 'jello' )
|
55
|
+
result = b.erb_eval( SAMPLE_TEMPLATE )
|
56
|
+
assert_equal "I love pie (especially with rhubarb), but I love jello even more!", result
|
57
|
+
end
|
58
|
+
|
59
|
+
def testMissingVar
|
60
|
+
b = Binder.new
|
61
|
+
result = silently { b.erb_eval( "Going to the <%=@blue%> moon" ) }
|
62
|
+
assert_equal "Going to the moon", result
|
63
|
+
end
|
64
|
+
|
65
|
+
def testScopeCaller
|
66
|
+
b = Binder.new
|
67
|
+
@arg = "ocean"
|
68
|
+
result = silently { b.erb_eval( "swim in the <%= @arg %> seas" ) }
|
69
|
+
assert_equal "swim in the seas", result
|
70
|
+
end
|
71
|
+
|
72
|
+
def testScopeBoth
|
73
|
+
@zip = '--zip--'
|
74
|
+
b = Binder.new( :zip => '++zap++' )
|
75
|
+
result = b.erb_eval( "The line went <%= @zip %>" )
|
76
|
+
assert_equal "The line went ++zap++", result
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def silently( &block )
|
82
|
+
warn_level = $VERBOSE
|
83
|
+
$VERBOSE = nil
|
84
|
+
result = block.call
|
85
|
+
$VERBOSE = warn_level
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
require 'test/unit/testcase'
|
6
|
+
require 'amazon/util/data_reader'
|
7
|
+
|
8
|
+
class TestDataReader < Test::Unit::TestCase
|
9
|
+
include Amazon::Util
|
10
|
+
|
11
|
+
SAMPLE_LIST_DATA = [ { :a => 1, :b => { :c => 2, :d => 3 }, :e => [ {:f => 4, :g => 5}, {:f => "anew\nline", :g => 7} ] },
|
12
|
+
{ :a => 2, :b => { :c => 4, :d => "for fun" }, :e => [ {:f => 2, :g => 4}, {:f => 8, :g => 7} ] },
|
13
|
+
{ :a => 3, :b => { :c => "apples, oranges", :d => 1 }, :e => [ {:f => 2, :g => 3}, {:f => 9, :g => 6} ] }, ]
|
14
|
+
|
15
|
+
YAML_LIST_DATA = <<EOF
|
16
|
+
---
|
17
|
+
- :b:
|
18
|
+
:c: 2
|
19
|
+
:d: 3
|
20
|
+
:a: 1
|
21
|
+
:e:
|
22
|
+
- :f: 4
|
23
|
+
:g: 5
|
24
|
+
- :f: "anew\\nline"
|
25
|
+
:g: 7
|
26
|
+
- :b:
|
27
|
+
:c: 4
|
28
|
+
:d: for fun
|
29
|
+
:a: 2
|
30
|
+
:e:
|
31
|
+
- :f: 2
|
32
|
+
:g: 4
|
33
|
+
- :f: 8
|
34
|
+
:g: 7
|
35
|
+
- :b:
|
36
|
+
:c: apples, oranges
|
37
|
+
:d: 1
|
38
|
+
:a: 3
|
39
|
+
:e:
|
40
|
+
- :f: 2
|
41
|
+
:g: 3
|
42
|
+
- :f: 9
|
43
|
+
:g: 6
|
44
|
+
EOF
|
45
|
+
|
46
|
+
TABULAR_LIST_DATA = <<EOF
|
47
|
+
a b.c b.d e.1.f e.1.g e.2.f e.2.g
|
48
|
+
1 2 3 4 5 "anew
|
49
|
+
line" 7
|
50
|
+
2 4 "for fun" 2 4 8 7
|
51
|
+
3 apples, oranges 1 2 3 9 6
|
52
|
+
EOF
|
53
|
+
|
54
|
+
CSV_LIST_DATA = <<EOF
|
55
|
+
a,b.c,b.d,e.1.f,e.1.g,e.2.f,e.2.g
|
56
|
+
1,2,3,4,5,"anew
|
57
|
+
line",7
|
58
|
+
2,4,for fun,2,4,8,7
|
59
|
+
3,"apples, oranges",1,2,3,9,6
|
60
|
+
EOF
|
61
|
+
|
62
|
+
SAMPLE_PROPERTIES_DATA = { :a => 1, :b => { :c => 2, :d => 3 }, :e => 4, :f => "Such a complex, yet whimsical fancy" }
|
63
|
+
|
64
|
+
YAML_PROPERTIES_DATA = <<EOF
|
65
|
+
---
|
66
|
+
:b:
|
67
|
+
:c: 2
|
68
|
+
:d: 3
|
69
|
+
:a: 1
|
70
|
+
:e: 4
|
71
|
+
:f: Such a complex, yet whimsical fancy
|
72
|
+
EOF
|
73
|
+
|
74
|
+
PROP_PROPERTIES_DATA = <<EOF
|
75
|
+
b.c=2
|
76
|
+
b.d=3
|
77
|
+
a=1
|
78
|
+
e=4
|
79
|
+
f=Such a complex, yet whimsical fancy
|
80
|
+
EOF
|
81
|
+
|
82
|
+
include Amazon::Util
|
83
|
+
|
84
|
+
def saveAndLoad( raw, format, sample )
|
85
|
+
@tmp = Tempfile.new( 'ruby-aws-test')
|
86
|
+
@tmp << raw
|
87
|
+
@tmp.close
|
88
|
+
data = DataReader.load( @tmp.path, format )
|
89
|
+
assert_equal sample, data
|
90
|
+
end
|
91
|
+
|
92
|
+
def reloadCheck( format, data )
|
93
|
+
@tmp = Tempfile.new( 'ruby-aws-test')
|
94
|
+
@tmp.close
|
95
|
+
DataReader.save( @tmp.path, data, format )
|
96
|
+
restore = DataReader.load( @tmp.path, format )
|
97
|
+
assert_equal data, restore
|
98
|
+
end
|
99
|
+
|
100
|
+
def testReadYAML
|
101
|
+
saveAndLoad( YAML_LIST_DATA, :YAML, SAMPLE_LIST_DATA )
|
102
|
+
saveAndLoad( YAML_PROPERTIES_DATA, :YAML, SAMPLE_PROPERTIES_DATA )
|
103
|
+
end
|
104
|
+
|
105
|
+
def testReadProp
|
106
|
+
saveAndLoad( PROP_PROPERTIES_DATA, :Properties, SAMPLE_PROPERTIES_DATA )
|
107
|
+
end
|
108
|
+
|
109
|
+
def testReadTabular
|
110
|
+
saveAndLoad( TABULAR_LIST_DATA, :Tabular, SAMPLE_LIST_DATA )
|
111
|
+
end
|
112
|
+
|
113
|
+
def testReadCSV
|
114
|
+
saveAndLoad( CSV_LIST_DATA, :CSV, SAMPLE_LIST_DATA )
|
115
|
+
end
|
116
|
+
|
117
|
+
def testRestoreYAML
|
118
|
+
reloadCheck( :YAML, SAMPLE_LIST_DATA )
|
119
|
+
reloadCheck( :YAML, SAMPLE_PROPERTIES_DATA )
|
120
|
+
end
|
121
|
+
|
122
|
+
def testRestoreProp
|
123
|
+
reloadCheck( :Properties, SAMPLE_PROPERTIES_DATA )
|
124
|
+
end
|
125
|
+
|
126
|
+
def testRestoreTabular
|
127
|
+
reloadCheck( :Tabular, SAMPLE_LIST_DATA )
|
128
|
+
end
|
129
|
+
|
130
|
+
def testRestoreCSV
|
131
|
+
reloadCheck( :CSV, SAMPLE_LIST_DATA )
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
end # TestDataReader
|