testdata 0.9.0 → 1.0.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/testdata.rb +188 -146
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42993343878323c49d342b13654f83ac569942ac
|
4
|
+
data.tar.gz: 9a381a6b441f8e1abd4f78401f0d08fa1ebea524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d82e33c38e86cae40b21dd3484586f99b5f9f06fa67e29c5308ba1b101072c3c16cfe429d5e22103e324dcedbb5f01d39de4432f038d728cae9d04df5f4757d9
|
7
|
+
data.tar.gz: e46240242b55a6cf686f2b4711aff34510c9b94709cb9bb1076dc6f58ffc3dd9be5f281efe3e161261f1b50202391fbbc6336c8f4df384ccc1b774441ed25e8c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/testdata.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
# file: testdata.rb
|
4
4
|
|
5
|
-
require 'rexml/document'
|
6
5
|
require 'app-routes'
|
7
6
|
require 'testdata_text'
|
8
7
|
require 'diffy'
|
@@ -11,191 +10,234 @@ require 'diffy'
|
|
11
10
|
class TestdataException < Exception
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
module Testdata
|
14
|
+
|
15
|
+
class Base
|
16
|
+
|
17
|
+
include AppRoutes
|
18
|
+
|
19
|
+
attr_accessor :debug
|
20
|
+
|
21
|
+
def initialize(s, options={})
|
22
|
+
|
23
|
+
super()
|
24
|
+
|
25
|
+
@params = {}
|
26
|
+
|
27
|
+
@success = [] # used by summary
|
28
|
+
@debug = false
|
29
|
+
|
30
|
+
# open the testdata document
|
31
|
+
procs = {
|
32
|
+
String: proc {|x|
|
33
|
+
|
34
|
+
if x.strip[/^</] then
|
35
|
+
x
|
36
|
+
elsif x[/https?:\/\//] then
|
37
|
+
read_url x
|
38
|
+
else
|
39
|
+
read_file x
|
40
|
+
end
|
41
|
+
},
|
42
|
+
Polyrex: proc {|x| x.to_xml}
|
43
|
+
}
|
44
|
+
|
45
|
+
buffer = procs[s.class.to_s.to_sym].call(s)
|
46
|
+
@doc = Rexle.new(buffer)
|
47
|
+
|
48
|
+
o = {log: false}.merge(options)
|
49
|
+
|
50
|
+
@log = o[:log] == true ? Rexle.new(tests) : nil
|
51
|
+
end
|
17
52
|
|
18
|
-
|
53
|
+
def run(x=nil, debug2=nil)
|
54
|
+
@debug2 = debug2 ? true : false
|
55
|
+
@success = []
|
56
|
+
procs = {NilClass: :test_all, Range: :test_all, String: :test_id, Fixnum: :test_id}
|
19
57
|
|
20
|
-
|
58
|
+
method(procs[x.class.to_s.to_sym]).call(x)
|
59
|
+
summary()
|
60
|
+
end
|
21
61
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#routes()
|
26
|
-
|
27
|
-
@success = [] # used by summary
|
28
|
-
@debug = false
|
29
|
-
|
30
|
-
# open the testdata document
|
31
|
-
procs = {
|
32
|
-
String: proc {|x|
|
33
|
-
|
34
|
-
if x.strip[/^</] then
|
35
|
-
x
|
36
|
-
elsif x[/https?:\/\//] then
|
37
|
-
read_url x
|
38
|
-
else
|
39
|
-
read_file x
|
40
|
-
end
|
41
|
-
},
|
42
|
-
Polyrex: proc {|x| x.to_xml}
|
43
|
-
}
|
44
|
-
|
45
|
-
buffer = procs[s.class.to_s.to_sym].call(s)
|
62
|
+
private
|
63
|
+
|
64
|
+
def testdata_values(id)
|
46
65
|
|
47
|
-
|
66
|
+
|
48
67
|
|
49
|
-
|
50
|
-
@log = o[:log] == true ? Document.new(tests) : nil
|
51
|
-
end
|
68
|
+
node = @doc.root.element "records/test[summary/path='#{id}']"
|
52
69
|
|
53
|
-
|
54
|
-
@debug2 = debug2 ? true : false
|
55
|
-
@success = []
|
56
|
-
procs = {NilClass: :test_all, Range: :test_all, String: :test_id, Fixnum: :test_id}
|
70
|
+
raise TestdataException, "Path error: node title not found" unless node
|
57
71
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def testdata_values(id)
|
72
|
+
path_no = node.text('summary/path')
|
73
|
+
xpath = "records/input/summary/*"
|
74
|
+
input_nodes = node.xpath(xpath) #[1..-1]
|
75
|
+
input_values = input_nodes.map{|x| x.texts.map(&:unescape).join.strip} + []
|
65
76
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
r
|
70
|
-
end
|
77
|
+
input_names = input_nodes.map(&:name)
|
78
|
+
raise TestdataException, 'inputs not found' if input_values.empty? \
|
79
|
+
or input_names.empty?
|
71
80
|
|
72
|
-
|
73
|
-
|
81
|
+
summary = node.element 'summary'
|
82
|
+
type, desc = summary.text('type'), summary.text('description')
|
74
83
|
|
75
|
-
|
84
|
+
xpath = "records/output/summary/*"
|
85
|
+
output_nodes = node.xpath(xpath) #[1..-1]
|
86
|
+
output_values = input_nodes.map{|x| x.texts.map(&:unescape).join.strip}
|
76
87
|
|
77
|
-
|
78
|
-
input_nodes = XPath.match(node, xpath) #[1..-1]
|
88
|
+
[path_no, input_values, input_names, type, output_values, desc]
|
79
89
|
|
80
|
-
|
90
|
+
end
|
81
91
|
|
82
|
-
|
83
|
-
|
84
|
-
or input_names.empty?
|
85
|
-
|
86
|
-
summary = XPath.first node, 'summary'
|
87
|
-
type, desc = summary.text('type'), summary.text('description')
|
92
|
+
def test_all(x)
|
93
|
+
x ||=(0..-1)
|
88
94
|
|
89
|
-
|
90
|
-
raw_output = XPath.match(node, xpath)
|
91
|
-
output_values = raw_output.length > 0 ? raw_output.map(&stringify) : []
|
95
|
+
break_on_fail = @doc.root.element('summary/break_on_fail/text()') == 'true'
|
92
96
|
|
93
|
-
|
97
|
+
@doc.root.xpath("records/test/summary/path/text()")[x].each do |id|
|
94
98
|
|
95
|
-
|
99
|
+
result = test_id(id)
|
100
|
+
break if result == false and break_on_fail
|
101
|
+
end
|
96
102
|
|
103
|
+
end
|
97
104
|
|
105
|
+
def test_id(id='')
|
98
106
|
|
99
|
-
def test_all(x)
|
100
|
-
x ||=(0..-1)
|
101
107
|
|
102
|
-
|
103
|
-
|
108
|
+
path_no, inputs, input_names, type, expected, @desc =
|
109
|
+
testdata_values(id.to_s)
|
110
|
+
@inputs = inputs
|
111
|
+
tests() # load the routes
|
104
112
|
|
105
|
-
|
106
|
-
|
107
|
-
break if result == false and break_on_fail
|
108
|
-
end
|
109
|
-
end
|
113
|
+
raw_actual = run_route type
|
114
|
+
puts "warning: no test route found for " + type unless raw_actual
|
110
115
|
|
111
|
-
|
116
|
+
result = nil
|
117
|
+
@success << [nil, path_no.to_i]
|
112
118
|
|
113
|
-
|
114
|
-
testdata_values(id.to_s)
|
115
|
-
@inputs = inputs
|
116
|
-
tests() # load the routes
|
119
|
+
begin
|
117
120
|
|
118
|
-
|
119
|
-
puts "warning: no test route found for " + type unless raw_actual
|
121
|
+
if raw_actual then
|
120
122
|
|
121
|
-
|
122
|
-
|
123
|
+
a = raw_actual.is_a?(String) ? [raw_actual].flatten.map(&:strip) : raw_actual
|
124
|
+
b = expected.map(&:strip)
|
123
125
|
|
124
|
-
|
126
|
+
if @debug == true or @debug2 == true then
|
127
|
+
|
128
|
+
inputs = input_names.zip(inputs).map{|x| ' ' + x.join(": ")}\
|
129
|
+
.join("\n")
|
125
130
|
|
126
|
-
|
131
|
+
puts "\ninputs: \n" + inputs
|
132
|
+
puts "\ntype or description:\n %s: %s" % [type, @desc]
|
133
|
+
puts "\nexpected : \n " + b.inspect
|
134
|
+
puts "\nactual : \n " + a.inspect + "\n"
|
135
|
+
end
|
127
136
|
|
128
|
-
|
129
|
-
b = expected.map(&:strip)
|
130
|
-
|
131
|
-
if @debug == true or @debug2 == true then
|
137
|
+
result = a == b
|
132
138
|
|
133
|
-
|
134
|
-
.join("\n")
|
139
|
+
if (@debug == true or @debug2 == true) and result == false then
|
135
140
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
141
|
+
# diff the expected and actual valuess
|
142
|
+
puts Diffy::Diff.new(a.first, b.first)
|
143
|
+
end
|
144
|
+
else
|
145
|
+
result = [raw_actual].compact == expected
|
140
146
|
end
|
141
147
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
result = [raw_actual].compact == expected
|
148
|
+
rescue Exception => e
|
149
|
+
err_label = e.message + " :: \n" + e.backtrace.join("\n")
|
150
|
+
raise TestdataException, err_label
|
151
|
+
result = false
|
152
|
+
ensure
|
153
|
+
@success[-1][0] = result
|
154
|
+
result
|
150
155
|
end
|
156
|
+
end
|
151
157
|
|
152
|
-
|
153
|
-
|
154
|
-
raise TestdataException, err_label
|
155
|
-
result = false
|
156
|
-
ensure
|
157
|
-
@success[-1][0] = result
|
158
|
-
result
|
158
|
+
def tests(*args)
|
159
|
+
# override this method in the child class
|
159
160
|
end
|
160
|
-
end
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
def read_file(s)
|
163
|
+
buffer = File.open(s, 'r').read
|
164
|
+
ext = url[/\.(\w+)$/,1]
|
165
|
+
method(('read_' + ext).to_sym).call(buffer)
|
166
|
+
end
|
167
|
+
|
168
|
+
def read_url(url)
|
169
|
+
buffer = open(url, 'UserAgent' => 'Testdata').read
|
170
|
+
ext = url[/.*\/[^\.]+\.(\w+)/,1]
|
171
|
+
method(('read_' + ext).to_sym).call(buffer)
|
172
|
+
end
|
165
173
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
method(('read_' + ext).to_sym).call(buffer)
|
170
|
-
end
|
174
|
+
def read_xml(buffer)
|
175
|
+
buffer
|
176
|
+
end
|
171
177
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
method(('read_' + ext).to_sym).call(buffer)
|
176
|
-
end
|
178
|
+
def read_td(buffer)
|
179
|
+
TestdataText.parse buffer
|
180
|
+
end
|
177
181
|
|
178
|
-
def read_xml(buffer)
|
179
|
-
buffer
|
180
|
-
end
|
181
|
-
|
182
|
-
def read_td(buffer)
|
183
|
-
TestdataText.parse buffer
|
184
|
-
end
|
185
182
|
|
183
|
+
def test(s)
|
184
|
+
self.add_route(s){yield(*(@inputs + [@desc]))}
|
185
|
+
end
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
187
|
+
def summary()
|
188
|
+
success = @success.map(&:first)
|
189
|
+
a = @success.map(&:last).sort
|
190
|
+
{
|
191
|
+
passed: success.all?,
|
192
|
+
score: [success.grep(true), success].map(&:length).join('/'),
|
193
|
+
failed: @success.select{|x| x[0] == false}.map(&:last).sort
|
194
|
+
}
|
195
|
+
end
|
190
196
|
end
|
191
197
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
198
|
+
class Unit
|
199
|
+
|
200
|
+
attr_reader :to_s
|
201
|
+
|
202
|
+
def initialize(s)
|
203
|
+
|
204
|
+
super()
|
205
|
+
@to_s = ''
|
206
|
+
|
207
|
+
buffer, _ = RXFHelper.read(s)
|
208
|
+
|
209
|
+
doc = Rexle.new(buffer)
|
210
|
+
|
211
|
+
# get the template
|
212
|
+
template = doc.root.xpath('summary/test_unit/text()').join.strip
|
213
|
+
raise 'no test_unit template found' unless template
|
214
|
+
|
215
|
+
doc.root.xpath('records/test').map do |test|
|
216
|
+
path, type, description = test.xpath('summary/*/text()')
|
217
|
+
|
218
|
+
inputs = test.xpath('records/input/summary/*/text()')
|
219
|
+
outputs = test.xpath('records/output/summary/*/text()')
|
220
|
+
records = test.element('records')
|
221
|
+
|
222
|
+
inputs = records.xpath('input/summary/*').map\
|
223
|
+
{|x| [x.name, x.texts.join.strip]}
|
224
|
+
inputs.each do |name, value|
|
225
|
+
template.sub!(/<%=\s*input\.#{name}\s*%>/, \
|
226
|
+
'"' + value.gsub('"','\"') + '"')
|
227
|
+
end
|
228
|
+
|
229
|
+
outputs = records.xpath('output/summary/*').map\
|
230
|
+
{|x| [x.name, x.texts.join.strip]}
|
231
|
+
outputs.each do |name, value|
|
232
|
+
template.sub!(/<%=\s*output\.#{name}\s*%>/, \
|
233
|
+
'"' + value.gsub('"','\"') + '"')
|
234
|
+
end
|
235
|
+
|
236
|
+
@to_s << template + "\n"
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
end # end of initialize()
|
241
|
+
end # end of initialize()
|
242
|
+
|
243
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
vWFtb5VPsjLRwClW20j7R9zEUv5XjYoyxcUn1W1xQINMVIQMtvMhouLBeWTXF7g4
|
32
32
|
ab2xQAvsYawLTw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
34
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: app-routes
|
@@ -62,7 +62,7 @@ dependencies:
|
|
62
62
|
version: '0.1'
|
63
63
|
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.1.
|
65
|
+
version: 0.1.8
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
version: '0.1'
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.1.
|
75
|
+
version: 0.1.8
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: diffy
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|