Permalink
Browse files

Update suite spec based on new format of tests and manifests. Use the…

… JSON-LD version of the manifest as the driver.
  • Loading branch information...
1 parent fb15dd9 commit 8757e7e2d651b745fc28b3652efd2eb04a1493f5 @gkellogg committed Sep 3, 2012
Showing with 170 additions and 118 deletions.
  1. +19 −20 Gemfile.lock
  2. +1 −0 spec/.gitignore
  3. +3 −3 spec/matchers.rb
  4. +1 −0 spec/spec_helper.rb
  5. +131 −62 spec/suite_helper.rb
  6. +15 −33 spec/suite_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- rdf-microdata (0.2.3.1)
+ rdf-microdata (0.2.4)
htmlentities (>= 4.3.0)
json (>= 1.6.1)
rdf (>= 0.3.4)
@@ -10,41 +10,40 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- addressable (2.2.7)
+ addressable (2.3.2)
diff-lcs (1.1.3)
equivalent-xml (0.2.9)
nokogiri (>= 1.4.3)
htmlentities (4.3.1)
- json (1.6.5)
- json (1.6.5-java)
- nokogiri (1.5.2)
- nokogiri (1.5.2-java)
+ json (1.7.5)
+ json (1.7.5-java)
+ nokogiri (1.5.5)
+ nokogiri (1.5.5-java)
promise (0.3.0)
- rdf (0.3.5.1)
+ rdf (0.3.8)
addressable (>= 2.2.6)
rdf-isomorphic (0.3.4)
rdf (>= 0.2.3)
- rdf-spec (0.3.5.1)
+ rdf-spec (0.3.8)
rspec (>= 2.8.0)
- rdf-turtle (0.1.1)
+ rdf-turtle (0.1.2)
rdf (>= 0.3.4)
- rdf-xsd (0.3.5)
- nokogiri (>= 1.5.0)
+ rdf-xsd (0.3.8)
rdf (>= 0.3.4)
- rspec (2.8.0)
- rspec-core (~> 2.8.0)
- rspec-expectations (~> 2.8.0)
- rspec-mocks (~> 2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.8.0)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.2)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.2)
spira (0.0.12)
promise (>= 0.3.0)
rdf (>= 0.2.3)
rdf-isomorphic (>= 0.3.0)
wirble (0.1.3)
- yard (0.7.5)
+ yard (0.8.2.1)
PLATFORMS
java
View
@@ -1 +1,2 @@
/uri-cache/
+/htmldata
View
@@ -45,7 +45,7 @@ def normalize(graph)
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
match do |actual|
- @info = if info.respond_to?(:about)
+ @info = if info.respond_to?(:data)
info
elsif info.is_a?(Hash)
identifier = info[:identifier] || expected.is_a?(RDF::Graph) ? expected.context : info[:about]
@@ -75,8 +75,8 @@ def normalize(graph)
"\n#{info + "\n" unless info.empty?}" +
(@info.inputDocument ? "Input file: #{@info.inputDocument}\n" : "") +
(@info.outputDocument ? "Output file: #{@info.outputDocument}\n" : "") +
- "Expected:\n#{@expected.dump(@info.format, :standard_prefixes => true)}" +
- "Results:\n#{@actual.dump(@info.format, :standard_prefixes => true)}" +
+ "Expected:\n#{@expected.dump(:ttl, :standard_prefixes => true)}" +
+ "Results:\n#{@actual.dump(:ttl, :standard_prefixes => true)}" +
(@info.trace ? "\nDebug:\n#{@info.trace}" : "")
end
end
View
@@ -15,6 +15,7 @@
c.run_all_when_everything_filtered = true
c.exclusion_filter = {
:ruby => lambda { |version| !(RUBY_VERSION.to_s =~ /^#{version.to_s}/) },
+ :ci => lambda {|ci| !ci.nil? }
}
c.include(RDF::Spec::Matchers)
end
View
@@ -4,85 +4,154 @@
require 'rdf/turtle'
require 'open-uri'
-module Fixtures
- module SuiteTest
- class MF < RDF::Vocabulary("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"); end
- SUITE_BASE = File.expand_path(File.dirname(__FILE__)) + "/test-suite/"
+# For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
+module RDF::Util
+ module File
+ REMOTE_PATH = "http://www.w3.org/TR/microdata-rdf/tests/"
+ LOCAL_PATH = ::File.expand_path("../htmldata/microdata-rdf/tests", __FILE__) + '/'
+
+ ##
+ # Override to use Patron for http and https, Kernel.open otherwise.
+ #
+ # @param [String] filename_or_url to open
+ # @param [Hash{Symbol => Object}] options
+ # @option options [Array, String] :headers
+ # HTTP Request headers.
+ # @return [IO] File stream
+ # @yield [IO] File stream
+ def self.open_file(filename_or_url, options = {}, &block)
+ #puts "open #{filename_or_url}"
+ case filename_or_url.to_s
+ when /^file:/
+ path = filename_or_url[5..-1]
+ Kernel.open(path.to_s, &block)
+ when /^#{REMOTE_PATH}/
+ begin
+ #puts "attempt to open #{filename_or_url} locally"
+ #puts " => #{filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)}"
+ response = ::File.open(filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH))
+ case filename_or_url.to_s
+ when /\.html$/
+ def response.content_type; 'text/html'; end
+ when /\.ttl$/
+ def response.content_type; 'text/turtle'; end
+ when /\.json$/
+ def response.content_type; 'application/json'; end
+ when /\.jsonld$/
+ def response.content_type; 'application/ld+json'; end
+ else
+ def response.content_type; 'unknown'; end
+ end
+ #puts "use #{filename_or_url} locally as #{response.content_type}"
- class Manifest < Spira::Base
- type MF.Manifest
- property :entry_list, :predicate => MF['entries']
- property :comment, :predicate => RDFS.comment
+ if block_given?
+ begin
+ yield response
+ ensure
+ response.close
+ end
+ else
+ response
+ end
+ rescue Errno::ENOENT
+ # Not there, don't run tests
+ Kernel.open(path.to_s, &block)
+ end
+ else
+ end
end
+ end
+end
- class Entry
- attr_accessor :debug
- attr_accessor :compare
- include Spira::Resource
- type MF["Entry"]
+module JSON::LD
+ # Simple Ruby reflector class to provide native
+ # access to JSON-LD objects
+ class Resource
+ # Object representation of resource
+ # @attr [Hash<String => Object] attributes
+ attr :attributes
- property :name, :predicate => MF["name"], :type => XSD.string
- property :comment, :predicate => RDF::RDFS.comment, :type => XSD.string
- property :result, :predicate => MF.result
- has_many :action, :predicate => MF["action"]
+ # ID of this resource
+ # @attr [String] id
+ attr :id
+
+ # A new resource from the parsed graph
+ # @param [Hash{String => Object}] node_definition
+ def initialize(node_definition)
+ @attributes = node_definition
+ @attributes.delete('@context') # Don't store with object
+ @id = @attributes['@id']
+ @anon = @id.nil? || @id.to_s[0,2] == '_:'
+ end
- def input
- Kernel.open(self.inputDocument.to_s)
- end
-
- def output
- self.result ? Kernel.open(self.result.to_s) : ""
- end
+ # Values of all properties other than id and type
+ def property_values
+ attributes.dup.delete_if {|k, v| %(id type).include?(k)}.values
+ end
- def inputDocument
- self.class.repository.first_object(:subject => self.action.first)
- end
+ # Access individual fields, from subject definition
+ def property(prop_name); @attributes.fetch(prop_name, nil); end
- def base_uri
- inputDocument.to_s
- end
-
- def inspect
- "[#{self.class.to_s} " + %w(
- subject
- name
- comment
- result
- inputDocument
- ).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
- "]"
- end
+ # Access individual fields, from subject definition
+ def method_missing(method, *args)
+ property(method.to_s)
end
- class Good < Manifest
- default_source :turtle
+ def inspect
+ "<Resource" +
+ attributes.dup.keep_if {|k, v| %(@id @type comment).include?(k)}.map do |k, v|
+ "\n #{k}: #{v.inspect}"
+ end.join(" ") +
+ ">"
+ end
+ end
+end
- def entries
- RDF::List.new(entry_list, self.class.repository).map { |entry| entry.as(GoodEntry) }
+module Fixtures
+ module SuiteTest
+ class Manifest < JSON::LD::Resource
+ def self.open(file)
+ #puts "open: #{file}"
+ RDF::Util::File.open_file(file) do |f|
+ json = JSON.parse(f.read)
+ self.from_jsonld(json)
+ end
+ end
+
+ # @param [Hash] json framed JSON-LD
+ # @return [Array<Manifest>]
+ def self.from_jsonld(json)
+ json['@graph'].map {|e| Manifest.new(e)}
end
- end
-
- class Bad < Manifest
- default_source :turtle_bad
def entries
- RDF::List.new(entry_list, self.class.repository).map { |entry| entry.as(BadEntry) }
+ # Map entries to resources
+ attributes['entries'].map {|e| Entry.new(e)}
end
end
- class GoodEntry < Entry
- default_source :turtle
- end
+ class Entry < JSON::LD::Resource
+ attr_accessor :debug
- class BadEntry < Entry
- default_source :turtle_bad
- end
+ # Alias data and query
+ def data
+ self.action['data']
+ end
+
+ def query
+ self.action['query']
+ end
+
+ def registry
+ self.action.fetch('registry',
+ "http://www.w3.org/TR/microdata-rdf/tests/test-registry.json")
+ end
- # Note that the texts README says to use a different base URI
- tests = RDF::Repository.load(SUITE_BASE + "manifest.ttl")
- Spira.add_repository! :turtle, tests
-
- tests_bad = RDF::Repository.load(SUITE_BASE + "manifest-bad.ttl")
- Spira.add_repository! :turtle_bad, tests_bad
+ def result
+ property('result') == 'true'
+ end
+
+ def trace; @debug.join("\n"); end
+ end
end
end
View
@@ -3,55 +3,37 @@
describe RDF::Microdata::Reader do
# W3C Microdata Test suite from FIXME
- describe "w3c microdata tests" do
+ describe "w3c microdata tests", :ci => ENV['CI'] do
require 'suite_helper'
+ MANIFEST = "http://www.w3.org/TR/microdata-rdf/tests/manifest.jsonld"
- describe "positive parser tests" do
- Fixtures::SuiteTest::Good.each do |m|
+ Fixtures::SuiteTest::Manifest.open(MANIFEST).each do |m|
+ describe m.comment do
m.entries.each do |t|
- #puts t.inspect
specify "#{t.name}: #{t.comment}" do
t.debug = []
- reader = RDF::Microdata::Reader.new(t.input,
- :base_uri => t.inputDocument,
+ t.debug << "base: #{t.data}"
+ reader = RDF::Microdata::Reader.open(t.data,
+ :base_uri => t.data,
:strict => true,
:validate => true,
+ :registry_uri => t.registry,
:debug => t.debug)
reader.should be_a RDF::Reader
graph = RDF::Graph.new << reader
- #puts "parse #{self.outputDocument} as #{RDF::Reader.for(self.outputDocument)}"
- output_graph = RDF::Graph.load(t.result, :base_uri => t.inputDocument)
- puts "result: #{CGI.escapeHTML(graph.to_ntriples)}" if ::RDF::Microdata::debug?
- graph.should be_equivalent_graph(output_graph, self)
- end
- end
- end
- end
-
- describe "negative parser tests" do
- Fixtures::SuiteTest::Bad.each do |m|
- m.entries.each do |t|
- specify "#{t.name}: #{t.comment}" do
- begin
- t.run_test do
- lambda do
- #t.debug = []
- g = RDF::Graph.new
- RDF::Microdata::Reader.new(t.input,
- :base_uri => t.base_uri,
- :validate => true,
- :debug => t.debug).each do |statement|
- g << statement
- end
- end.should raise_error(RDF::ReaderError)
- end
+ #puts "parse #{t.query} as #{RDF::Reader.for(t.query)}"
+ output_graph = RDF::Graph.load(t.query, :base_uri => t.data)
+ puts "result: #{CGI.escapeHTML(graph.dump(:ttl))}" if ::RDF::Microdata::debug?
+ if t.result
+ graph.should be_equivalent_graph(output_graph, t)
+ else
+ graph.should_not be_equivalent_graph(output_graph, t)
end
end
end
end
end
end
-
end

0 comments on commit 8757e7e

Please sign in to comment.