Browse files

Use either local or remote versions of suite tests, after performing …

…translation from TR space.
  • Loading branch information...
1 parent 8757e7e commit 26352d5b482b931cf9436b71d3a8591a617c0a74 @gkellogg gkellogg committed Sep 4, 2012
Showing with 38 additions and 36 deletions.
  1. +1 −0 .gitignore
  2. +37 −35 spec/suite_helper.rb
  3. +0 −1 spec/suite_spec.rb
View
1 .gitignore
@@ -1,3 +1,4 @@
/.yardoc/
/doc/
/pkg/
+/.rbx/
View
72 spec/suite_helper.rb
@@ -7,8 +7,9 @@
# 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__) + '/'
+ TEST_PATH = "http://www.w3.org/TR/microdata-rdf/tests/"
+ REMOTE_PATH = "https://dvcs.w3.org/hg/htmldata/raw-file/default/microdata-rdf/tests/"
+ LOCAL_PATH = ::File.expand_path("../htmldata/microdata-rdf/tests/", __FILE__) + '/'
##
# Override to use Patron for http and https, Kernel.open otherwise.
@@ -21,43 +22,44 @@ module File
# @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}"
+
+ # Translate test URI to remote location
+ if filename_or_url.to_s.index(TEST_PATH) == 0
+ filename_or_url = filename_or_url.sub(TEST_PATH, REMOTE_PATH)
+ end
+
+ # Look up remote files locally, if we have them mapped
+ if filename_or_url.to_s.index(REMOTE_PATH) == 0 and ::File.exist?(LOCAL_PATH)
+ #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}"
- if block_given?
- begin
- yield response
- ensure
- response.close
- end
- else
- response
+ if block_given?
+ begin
+ yield response
+ ensure
+ response.close
end
- rescue Errno::ENOENT
- # Not there, don't run tests
- Kernel.open(path.to_s, &block)
+ else
+ response
end
else
+ # Standard implementation
+ filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
+ Kernel.open(filename_or_url.to_s, &block)
end
end
end
View
1 spec/suite_spec.rb
@@ -12,7 +12,6 @@
m.entries.each do |t|
specify "#{t.name}: #{t.comment}" do
t.debug = []
- t.debug << "base: #{t.data}"
reader = RDF::Microdata::Reader.open(t.data,
:base_uri => t.data,
:strict => true,

0 comments on commit 26352d5

Please sign in to comment.