Skip to content

Commit

Permalink
Update test suite locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Aug 26, 2023
1 parent faa35db commit b6fb8db
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 88 deletions.
2 changes: 1 addition & 1 deletion lib/rdf/trig/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Reader < RDF::Turtle::Reader
terminal(:GRAPH, /graph/i)
terminal(:PREFIX, PREFIX)
terminal(:BASE, BASE)
terminal(:LANG_DIR, LANG_DIR)
terminal(:LANG_DIR, LANG_DIR)

##
# Iterates the given block for each RDF statement in the input.
Expand Down
15 changes: 7 additions & 8 deletions script/tc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def run_tc(tc, **options)
options = {
base_uri: tc.base,
validate: true,
rdfstar: true,
logger: logger
}.merge(options)

Expand Down Expand Up @@ -140,7 +141,6 @@ OPT_ARGS = [
["--nquads", GetoptLong::NO_ARGUMENT, "Run N-Quads tests"],
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT, "Output to specified file"],
["--quiet", "-q", GetoptLong::NO_ARGUMENT, "Minimal output"],
["--rdfstar", GetoptLong::NO_ARGUMENT, "Run RDF-star tests"],
["--skip-slow", "-s", GetoptLong::NO_ARGUMENT, "Avoid files taking too much time"],
["--validate", GetoptLong::NO_ARGUMENT, "Validate input"],
["--verbose", "-v", GetoptLong::NO_ARGUMENT, "Verbose output"],
Expand Down Expand Up @@ -183,22 +183,21 @@ opts.each do |opt, arg|
when '--quiet'
options[:quiet] = true
options[:level] = Logger::FATAL
when '--rdfstar' then options[:rdfstar] = true
when '--skip-slow' then options[:slow] = true
when '--validate' then options[:validate] = true
when '--verbose' then options[:verbose] = true
# when '--write-manifests' then options[:write_manifests] = true
end
end

manifests = if options[:rdfstar]
%w{nt/syntax turtle/syntax turtle/eval trig/syntax trig/eval}.map do
|man| "https://w3c.github.io/rdf-star/tests/#{man}/"
end
elsif options[:nquads]
manifests = if options[:nquads]
[Fixtures::SuiteTest::BASE + "rdf11/rdf-n-quads/"]
else
[Fixtures::SuiteTest::BASE + "rdf11/rdf-trig/"]
[
Fixtures::SuiteTest::BASE + "rdf11/rdf-trig/",
Fixtures::SuiteTest::BASE + "rdf12/rdf-trig/syntax/",
Fixtures::SuiteTest::BASE + "rdf12/rdf-trig/eval/",
]
end.map {|m| "#{m}manifest.ttl"}

earl_preamble(**options) if options[:earl]
Expand Down
7 changes: 5 additions & 2 deletions spec/star_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
describe "rdfstar TriG tests" do
require 'suite_helper'

%w(nt/syntax turtle/syntax turtle/eval trig/syntax trig/eval).each do |man|
Fixtures::SuiteTest::Manifest.open("https://w3c.github.io/rdf-star/tests/#{man}/manifest.ttl") do |m|
%w(
rdf12/rdf-n-triples/syntax/manifest.ttl
rdf12/rdf-trig/syntax/manifest.ttl
rdf12/rdf-trig/eval/manifest.ttl).each do |man|
Fixtures::SuiteTest::Manifest.open(Fixtures::SuiteTest::BASE + man) do |m|
describe [m.label, m.comment].compact.join(': ') do
m.entries.each do |t|
specify "#{t.name}: #{t.comment}" do
Expand Down
92 changes: 15 additions & 77 deletions spec/suite_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
# 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 = "https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-trig/"
LOCAL_PATH = ::File.expand_path("../w3c-rdf-tests/rdf/rdf11/rdf-trig", __FILE__) + '/'
REMOTE_PATH_NQ = "https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/"
LOCAL_PATH_NQ = ::File.expand_path("../w3c-rdf/rdf/rdf11/rdf-n-quads", __FILE__) + '/'
REMOTE_PATH_STAR = "https://w3c.github.io/rdf-star/"
LOCAL_PATH_STAR = ::File.expand_path("../w3c-rdf-star/", __FILE__) + '/'
REMOTE_PATH = "https://w3c.github.io/rdf-tests/rdf/"
LOCAL_PATH = ::File.expand_path("../w3c-rdf-tests/rdf/", __FILE__) + '/'

class << self
alias_method :original_open_file, :open_file
Expand Down Expand Up @@ -59,72 +55,6 @@ def self.open_file(filename_or_url, **options, &block)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]

remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_NQ}} && Dir.exist?(LOCAL_PATH_NQ))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH_NQ, LOCAL_PATH_NQ)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.trig$/ then 'application/trig'
when /\.nt$/ then 'application/n-triples'
when /\.nq$/ then 'application/n-quads'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end

document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]

remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
else
remote_document
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_STAR}} && Dir.exist?(LOCAL_PATH_STAR))
#puts "attempt to open #{filename_or_url} locally"
localpath = filename_or_url.to_s.sub(REMOTE_PATH_STAR, LOCAL_PATH_STAR)
response = begin
::File.open(localpath)
rescue Errno::ENOENT => e
raise IOError, e.message
end
document_options = {
base_uri: RDF::URI(filename_or_url),
charset: Encoding::UTF_8,
code: 200,
headers: {}
}
#puts "use #{filename_or_url} locally"
document_options[:headers][:content_type] = case filename_or_url.to_s
when /\.ttl$/ then 'text/turtle'
when /\.nt$/ then 'application/n-triples'
when /\.jsonld$/ then 'application/ld+json'
else 'unknown'
end

document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
# For overriding content type from test data
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]

remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
if block_given?
yield remote_document
Expand All @@ -134,6 +64,8 @@ def self.open_file(filename_or_url, **options, &block)
else
original_open_file(filename_or_url, **options, &block)
end
rescue IOError => e
raise IOError, "Error opening #{filename_or_url.inspect}: #{e.message}"
end
end
end
Expand All @@ -150,6 +82,7 @@ module SuiteTest
"rdft": "http://www.w3.org/ns/rdftest#",
"label": "rdfs:label",
"baseIri": {"@id": "mf:assumedTestBase", "@type": "@id"},
"comment": "rdfs:comment",
"entries": {"@id": "mf:entries", "@container": "@list"},
"name": "mf:name",
Expand Down Expand Up @@ -178,15 +111,20 @@ def self.from_jsonld(json)

def entries
# Map entries to resources
attributes['entries'].map {|e| Entry.new(e)}
attributes['entries'].map {|e| Entry.new(e, base_iri: attributes['baseIri'])}
end
end

class Entry < JSON::LD::Resource
attr_accessor :logger

def initialize(json, base_iri:)
@base_iri = base_iri
super
end

def base
RDF::URI(action)
RDF::URI(@base_iri || action)
end

# Alias data and query
Expand All @@ -195,15 +133,15 @@ def input
end

def expected
@expected ||= RDF::Util::File.open_file(result) {|f| f.read}
@expected ||= RDF::Util::File.open_file(result) {|f| f.read} if result
end

def evaluate?
attributes['@type'].to_s.match(/Eval/)
!!attributes['@type'].to_s.match(/Eval/)
end

def syntax?
attributes['@type'].to_s.match(/Syntax/)
!!attributes['@type'].to_s.match(/Syntax/)
end

def positive_test?
Expand Down

0 comments on commit b6fb8db

Please sign in to comment.