Skip to content

Commit

Permalink
Update ebnf dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Nov 2, 2015
1 parent 587a49e commit a73e84e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ld-patch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 2.0.0'
gem.requirements = []
gem.add_runtime_dependency 'rdf', '~> 1.1', '>= 1.1.15'
gem.add_runtime_dependency 'ebnf', '~> 0.3', '>= 0.3.9'
gem.add_runtime_dependency 'ebnf', '~> 1.0'
gem.add_runtime_dependency 'sparql', '~> 1.1', '>= 1.1.7'
gem.add_runtime_dependency 'sxp', '~> 0.1'
gem.add_runtime_dependency 'rdf-xsd', '~> 1.1'
Expand Down
18 changes: 13 additions & 5 deletions script/tc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ def run_tc(t, options)
}
end

options[:result_count][result] ||= 0
options[:result_count][result] += 1

STDERR.puts "#{"test result:" unless options[:quiet]} #{result}"
end

options = {
output: STDOUT,
validate: true,
verbose: false,
output: STDOUT,
validate: true,
verbose: false,
}
suite = "rdfxml"
opts = GetoptLong.new(
Expand Down Expand Up @@ -125,14 +128,19 @@ opts.each do |opt, arg|
end

earl_preamble(options) if options[:earl]
result_count = {}

%w(manifest.ttl manifest-syntax.ttl turtle/manifest-ldpatch.ttl).each do |variant|
manifest = Fixtures::SuiteTest::BASE + variant

Fixtures::SuiteTest::Manifest.open(manifest) do |m|
m.entries.each do |tc|
next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
run_tc(tc, options)
run_tc(tc, options.merge(result_count: result_count))
end
end
end
end

result_count.each do |result, count|
puts "#{result}: #{count}"
end
80 changes: 49 additions & 31 deletions spec/suite_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module File
REMOTE_PATH = "https://raw.githubusercontent.com/pchampin/ld-patch-testsuite/master/"
LOCAL_PATH = ::File.expand_path("../testsuite", __FILE__) + '/'

class << self
alias_method :original_open_file, :open_file
end

##
# Override to use Patron for http and https, Kernel.open otherwise.
#
Expand All @@ -19,42 +23,56 @@ module File
# @return [IO] File stream
# @yield [IO] File stream
def self.open_file(filename_or_url, options = {}, &block)
case filename_or_url.to_s
when /^file:/
case
when filename_or_url.to_s =~ /^file:/
path = filename_or_url[5..-1]
Kernel.open(path.to_s, options, &block)
when /^#{REMOTE_PATH}/
begin
#puts "attempt to open #{filename_or_url} locally"
local_filename = filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
if ::File.exist?(local_filename)
response = ::File.open(local_filename)
#puts "use #{filename_or_url} locally"
case filename_or_url.to_s
when /\.ttl$/
def response.content_type; 'text/turtle'; end
when /\.ldpatch$/
def response.content_type; 'text/ldpatch'; end
end

if block_given?
begin
yield response
ensure
response.close
end
else
response
end
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH}} && Dir.exist?(LOCAL_PATH))
localpath = RDF::URI(filename_or_url).dup
localpath.query = nil
localpath = localpath.to_s.sub(REMOTE_PATH, LOCAL_PATH)
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 /\.ldpatch$/ then 'text/ldpatch'
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
else
original_open_file(filename_or_url, options) do |rd|
# Override content_type
if options[:contentType]
rd.headers[:content_type] = options[:contentType]
rd.instance_variable_set(:@content_type, options[:contentType].split(';').first)
end

if block_given?
yield rd
else
Kernel.open(filename_or_url.to_s, options.fetch(:headers, {}), &block)
rd
end
rescue Errno::ENOENT #, OpenURI::HTTPError
# Not there, don't run tests
StringIO.new("")
end
else
Kernel.open(filename_or_url.to_s, options.fetch(:headers, {}), &block)
end
end
end
Expand Down

0 comments on commit a73e84e

Please sign in to comment.