testdata 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/testdata.rb +59 -0
- metadata +55 -0
data/lib/testdata.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# file: testdata.rb
|
4
|
+
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
class Select
|
8
|
+
include REXML
|
9
|
+
|
10
|
+
def initialize(type, node) @node, @type = node, type end
|
11
|
+
|
12
|
+
def data(x)
|
13
|
+
|
14
|
+
stringify = Proc.new {|x| x.texts.length <= 1 ? x.text : x.cdatas.join.strip}
|
15
|
+
|
16
|
+
procs = {}
|
17
|
+
procs[:String] = Proc.new do |type,x|
|
18
|
+
e = XPath.first(@node, "records/io/summary[type='#{type}']/#{x}")
|
19
|
+
stringify.call(e)
|
20
|
+
end
|
21
|
+
procs[:Array] = Proc.new do |type,a|
|
22
|
+
xpath = a.map {|x| "io/summary[type='#{type}']/#{x}"}.join(' | ')
|
23
|
+
XPath.match(@node, xpath).map {|x| stringify.call(x)}
|
24
|
+
end
|
25
|
+
|
26
|
+
yield procs[x.class.to_s.to_sym].call(@type, x)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Path
|
31
|
+
include REXML
|
32
|
+
|
33
|
+
def initialize(doc) @doc = doc end
|
34
|
+
|
35
|
+
def tested? description
|
36
|
+
node = XPath.first(@doc.root, "records/test[summary/description='#{description}']")
|
37
|
+
raise "Path error: node not found" unless node
|
38
|
+
yield *%w(input output).map {|x| Select.new(x,node)}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Testdata
|
43
|
+
include REXML
|
44
|
+
|
45
|
+
attr_reader :success
|
46
|
+
|
47
|
+
def initialize(s)
|
48
|
+
buffer = self.send('read_' + (s[/https?:\/\//] ? 'file' : 'url'), s)
|
49
|
+
@doc = Document.new(buffer)
|
50
|
+
raise "Testdata error: doc %s not found" % s unless @doc
|
51
|
+
@success = []
|
52
|
+
end
|
53
|
+
|
54
|
+
def paths() @success << yield(path = Path.new(@doc)) end
|
55
|
+
def read_file(s) File.open(s, 'r').read end
|
56
|
+
def read_url(xml_url) open(xml_url, 'UserAgent' => 'S-Rscript').read end
|
57
|
+
|
58
|
+
def passed?() @success.all? end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-05-15 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/testdata.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage:
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: testdata
|
54
|
+
test_files: []
|
55
|
+
|