Skip to content

Commit

Permalink
Update suite test formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Sep 12, 2012
1 parent 8757e7e commit 379c17e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -35,7 +35,7 @@ GEM
rspec-expectations (~> 2.11.0) rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0) rspec-mocks (~> 2.11.0)
rspec-core (2.11.1) rspec-core (2.11.1)
rspec-expectations (2.11.2) rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3) diff-lcs (~> 1.1.3)
rspec-mocks (2.11.2) rspec-mocks (2.11.2)
spira (0.0.12) spira (0.0.12)
Expand Down
11 changes: 11 additions & 0 deletions etc/registry.json
Expand Up @@ -3,21 +3,32 @@
"propertyURI": "vocabulary", "propertyURI": "vocabulary",
"multipleValues": "unordered", "multipleValues": "unordered",
"properties": { "properties": {
"additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"},
"blogPosts": {"multipleValues": "list"},
"blogPosts": {"multipleValues": "list"}, "blogPosts": {"multipleValues": "list"},
"breadcrumb": {"multipleValues": "list"}, "breadcrumb": {"multipleValues": "list"},
"byArtist": {"multipleValues": "list"}, "byArtist": {"multipleValues": "list"},
"creator": {"multipleValues": "list"}, "creator": {"multipleValues": "list"},
"episode": {"multipleValues": "list"},
"episodes": {"multipleValues": "list"}, "episodes": {"multipleValues": "list"},
"event": {"multipleValues": "list"},
"events": {"multipleValues": "list"}, "events": {"multipleValues": "list"},
"founder": {"multipleValues": "list"},
"founders": {"multipleValues": "list"}, "founders": {"multipleValues": "list"},
"itemListElement": {"multipleValues": "list"}, "itemListElement": {"multipleValues": "list"},
"musicGroupMember": {"multipleValues": "list"}, "musicGroupMember": {"multipleValues": "list"},
"performerIn": {"multipleValues": "list"}, "performerIn": {"multipleValues": "list"},
"actor": {"multipleValues": "list"},
"actors": {"multipleValues": "list"},
"performer": {"multipleValues": "list"},
"performers": {"multipleValues": "list"}, "performers": {"multipleValues": "list"},
"producer": {"multipleValues": "list"}, "producer": {"multipleValues": "list"},
"recipeInstructions": {"multipleValues": "list"}, "recipeInstructions": {"multipleValues": "list"},
"season": {"multipleValues": "list"},
"seasons": {"multipleValues": "list"}, "seasons": {"multipleValues": "list"},
"subEvent": {"multipleValues": "list"},
"subEvents": {"multipleValues": "list"}, "subEvents": {"multipleValues": "list"},
"track": {"multipleValues": "list"},
"tracks": {"multipleValues": "list"} "tracks": {"multipleValues": "list"}
} }
}, },
Expand Down
4 changes: 3 additions & 1 deletion lib/rdf/microdata/reader.rb
Expand Up @@ -50,7 +50,7 @@ def self.load_registry(registry_uri)
return if @registry_uri == registry_uri return if @registry_uri == registry_uri


json = RDF::Util::File.open_file(registry_uri) { |f| JSON.load(f) } json = RDF::Util::File.open_file(registry_uri) { |f| JSON.load(f) }

@prefixes = {} @prefixes = {}
json.each do |prefix, elements| json.each do |prefix, elements|
next unless elements.is_a?(Hash) next unless elements.is_a?(Hash)
Expand Down Expand Up @@ -227,6 +227,7 @@ def initialize(input = $stdin, options = {}, &block)
# Load registry # Load registry
begin begin
registry_uri = options[:registry_uri] || DEFAULT_REGISTRY registry_uri = options[:registry_uri] || DEFAULT_REGISTRY
add_debug(@doc, "registry = #{registry_uri}")
Registry.load_registry(registry_uri) Registry.load_registry(registry_uri)
rescue JSON::ParserError => e rescue JSON::ParserError => e
raise RDF::ReaderError, "Failed to parse registry: #{e.message}" raise RDF::ReaderError, "Failed to parse registry: #{e.message}"
Expand Down Expand Up @@ -458,6 +459,7 @@ def generatePropertyValues(element, subject, predicate, values)
# If the registry contains a URI prefix that is a character for character match of predicate up to the length # If the registry contains a URI prefix that is a character for character match of predicate up to the length
# of the URI prefix, set vocab as that URI prefix. Otherwise set vocab to null # of the URI prefix, set vocab as that URI prefix. Otherwise set vocab to null
registry = Registry.find(predicate) registry = Registry.find(predicate)
add_debug("generatePropertyValues") { "list(#{predicate})? #{registry.as_list(predicate).inspect}"} if registry
if registry && registry.as_list(predicate) if registry && registry.as_list(predicate)
value = generateRDFCollection(element, values) value = generateRDFCollection(element, values)
add_triple(element, subject, predicate, value) add_triple(element, subject, predicate, value)
Expand Down
40 changes: 20 additions & 20 deletions spec/suite_helper.rb
Expand Up @@ -21,10 +21,12 @@ module File
# @yield [IO] File stream # @yield [IO] File stream
def self.open_file(filename_or_url, options = {}, &block) def self.open_file(filename_or_url, options = {}, &block)
#puts "open #{filename_or_url}" #puts "open #{filename_or_url}"
case filename_or_url.to_s f = case filename_or_url.to_s
when /^file:/ when /^file:/
path = filename_or_url[5..-1] path = filename_or_url[5..-1]
Kernel.open(path.to_s, &block) Kernel.open(path.to_s, &block)
when 'http://www.w3.org/ns/md'
Kernel.open(RDF::Microdata::Reader::DEFAULT_REGISTRY)
when /^#{REMOTE_PATH}/ when /^#{REMOTE_PATH}/
begin begin
#puts "attempt to open #{filename_or_url} locally" #puts "attempt to open #{filename_or_url} locally"
Expand All @@ -44,21 +46,23 @@ def response.content_type; 'unknown'; end
end end
#puts "use #{filename_or_url} locally as #{response.content_type}" #puts "use #{filename_or_url} locally as #{response.content_type}"


if block_given? response
begin
yield response
ensure
response.close
end
else
response
end
rescue Errno::ENOENT rescue Errno::ENOENT
# Not there, don't run tests # Not there, don't run tests
Kernel.open(path.to_s, &block) Kernel.open(path.to_s, &block)
end end
else else
end end

if block_given?
begin
yield f
ensure
f.close
end
else
f
end
end end
end end
end end
Expand Down Expand Up @@ -99,7 +103,7 @@ def method_missing(method, *args)


def inspect def inspect
"<Resource" + "<Resource" +
attributes.dup.keep_if {|k, v| %(@id @type comment).include?(k)}.map do |k, v| attributes.map do |k, v|
"\n #{k}: #{v.inspect}" "\n #{k}: #{v.inspect}"
end.join(" ") + end.join(" ") +
">" ">"
Expand Down Expand Up @@ -137,18 +141,14 @@ class Entry < JSON::LD::Resource
def data def data
self.action['data'] self.action['data']
end end


def query
self.action['query']
end

def registry def registry
self.action.fetch('registry', property('registry') ||
"http://www.w3.org/TR/microdata-rdf/tests/test-registry.json") "http://www.w3.org/TR/microdata-rdf/tests/test-registry.json"
end end


def result def positiveTest
property('result') == 'true' property('positiveTest') == 'true'
end end


def trace; @debug.join("\n"); end def trace; @debug.join("\n"); end
Expand Down
4 changes: 2 additions & 2 deletions spec/suite_spec.rb
Expand Up @@ -24,9 +24,9 @@
graph = RDF::Graph.new << reader graph = RDF::Graph.new << reader


#puts "parse #{t.query} as #{RDF::Reader.for(t.query)}" #puts "parse #{t.query} as #{RDF::Reader.for(t.query)}"
output_graph = RDF::Graph.load(t.query, :base_uri => t.data) output_graph = RDF::Graph.load(t.result, :base_uri => t.data)
puts "result: #{CGI.escapeHTML(graph.dump(:ttl))}" if ::RDF::Microdata::debug? puts "result: #{CGI.escapeHTML(graph.dump(:ttl))}" if ::RDF::Microdata::debug?
if t.result if t.positiveTest
graph.should be_equivalent_graph(output_graph, t) graph.should be_equivalent_graph(output_graph, t)
else else
graph.should_not be_equivalent_graph(output_graph, t) graph.should_not be_equivalent_graph(output_graph, t)
Expand Down
23 changes: 0 additions & 23 deletions spec/test-files/test-registry.json
Expand Up @@ -36,28 +36,5 @@
"list": {"multipleValues": "list"}, "list": {"multipleValues": "list"},
"typed": {"datatype": "http://typed"} "typed": {"datatype": "http://typed"}
} }
},
"http://schema.org/": {
"propertyURI": "vocabulary",
"multipleValues": "unordered",
"properties": {
"additionalType": {"subPropertyOf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"},
"blogPosts": {"multipleValues": "list"},
"breadcrumb": {"multipleValues": "list"},
"byArtist": {"multipleValues": "list"},
"creator": {"multipleValues": "list"},
"episodes": {"multipleValues": "list"},
"events": {"multipleValues": "list"},
"founders": {"multipleValues": "list"},
"itemListElement": {"multipleValues": "list"},
"musicGroupMember": {"multipleValues": "list"},
"performerIn": {"multipleValues": "list"},
"performers": {"multipleValues": "list"},
"producer": {"multipleValues": "list"},
"recipeInstructions": {"multipleValues": "list"},
"seasons": {"multipleValues": "list"},
"subEvents": {"multipleValues": "list"},
"tracks": {"multipleValues": "list"}
}
} }
} }

0 comments on commit 379c17e

Please sign in to comment.