rdf-tabular 0.1.3.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ require "bundler/setup"
5
5
  require 'rspec'
6
6
  require 'rspec/its'
7
7
  require 'rdf/isomorphic'
8
- require 'rdf/tabular'
9
8
  require 'rdf/turtle'
10
9
  require 'rdf/spec/matchers'
11
10
  require 'json'
@@ -13,7 +12,16 @@ require 'webmock/rspec'
13
12
  require 'matchers'
14
13
  require 'suite_helper'
15
14
  require 'simplecov'
16
- SimpleCov.start
15
+ require 'coveralls'
16
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
17
+ SimpleCov::Formatter::HTMLFormatter,
18
+ Coveralls::SimpleCov::Formatter
19
+ ]
20
+ SimpleCov.start do
21
+ add_filter "/spec/"
22
+ end
23
+
24
+ require 'rdf/tabular'
17
25
 
18
26
  JSON_STATE = JSON::State.new(
19
27
  :indent => " ",
@@ -7,7 +7,7 @@ require 'open-uri'
7
7
  # For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
8
8
  module RDF::Util
9
9
  module File
10
- REMOTE_PATH = "http://w3c.github.io/csvw/"
10
+ REMOTE_PATH = "http://www.w3.org/2013/csvw/"
11
11
  LOCAL_PATH = ::File.expand_path("../w3c-csvw", __FILE__) + '/'
12
12
 
13
13
  class << self
@@ -28,14 +28,20 @@ module RDF::Util
28
28
  when filename_or_url.to_s =~ /^file:/
29
29
  path = filename_or_url.to_s[5..-1]
30
30
  Kernel.open(path.to_s, &block)
31
- when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH}} && ::File.exist?(filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)))
31
+ when filename_or_url.to_s =~ %r{http://www.w3.org/ns/csvw/?}
32
+ ::File.open(::File.expand_path("../../etc/csvw.jsonld", __FILE__), &block)
33
+ when filename_or_url.to_s == "http://www.w3.org/.well-known/csvm"
34
+ ::File.open(::File.expand_path("../../etc/well-known", __FILE__), &block)
35
+ when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH}} && Dir.exist?(LOCAL_PATH))
32
36
  begin
33
37
  #puts "attempt to open #{filename_or_url} locally"
34
- localpath = filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
38
+ localpath = RDF::URI(filename_or_url).dup
39
+ localpath.query = nil
40
+ localpath = localpath.to_s.sub(REMOTE_PATH, LOCAL_PATH)
35
41
  response = begin
36
42
  ::File.open(localpath)
37
- rescue Errno::ENOENT
38
- Kernel.open(filename_or_url.to_s, "r:utf-8", 'Accept' => "application/ld+json, application/json, text/csv")
43
+ rescue Errno::ENOENT => e
44
+ raise IOError, e.message
39
45
  end
40
46
  document_options = {
41
47
  base_uri: RDF::URI(filename_or_url),
@@ -67,7 +73,22 @@ module RDF::Util
67
73
  end
68
74
  end
69
75
  else
70
- original_open_file(filename_or_url, options, &block)
76
+ original_open_file(filename_or_url, options) do |remote_document|
77
+ # Add Link header, if necessary
78
+ remote_document.headers[:link] = options[:httpLink] if options[:httpLink]
79
+
80
+ # Override content_type
81
+ if options[:contentType]
82
+ remote_document.headers[:content_type] = options[:contentType]
83
+ remote_document.instance_variable_set(:@content_type, options[:contentType].split(';').first)
84
+ end
85
+
86
+ if block_given?
87
+ yield remote_document
88
+ else
89
+ remote_document
90
+ end
91
+ end
71
92
  end
72
93
  end
73
94
  end
@@ -75,10 +96,9 @@ end
75
96
 
76
97
  module Fixtures
77
98
  module SuiteTest
78
- BASE = "http://w3c.github.io/csvw/tests/"
99
+ BASE = "http://www.w3.org/2013/csvw/tests/"
79
100
  class Manifest < JSON::LD::Resource
80
101
  def self.open(file, base)
81
- #puts "open: #{file}"
82
102
  RDF::Util::File.open_file(file) do |file|
83
103
  json = ::JSON.load(file.read)
84
104
  yield Manifest.new(json, context: json['@context'].merge('@base' => base))
@@ -94,6 +114,7 @@ module Fixtures
94
114
  class Entry < JSON::LD::Resource
95
115
  attr_accessor :debug
96
116
  attr_accessor :warnings
117
+ attr_accessor :errors
97
118
  attr_accessor :metadata
98
119
 
99
120
  def id
@@ -110,7 +131,7 @@ module Fixtures
110
131
  end
111
132
 
112
133
  def result
113
- RDF::URI(context['@base']).join(attributes["result"]).to_s
134
+ RDF::URI(context['@base']).join(attributes["result"]).to_s if attributes["result"]
114
135
  end
115
136
 
116
137
  def input
@@ -118,17 +139,13 @@ module Fixtures
118
139
  end
119
140
 
120
141
  def expected
121
- @expected ||= RDF::Util::File.open_file(result) {|f| f.read}
142
+ @expected ||= RDF::Util::File.open_file(result) {|f| f.read} rescue nil
122
143
  end
123
144
 
124
145
  def evaluate?
125
- type.include?("To")
146
+ type.to_s.include?("To")
126
147
  end
127
148
 
128
- def sparql?
129
- type.include?("Sparql")
130
- end
131
-
132
149
  def rdf?
133
150
  result.to_s.end_with?(".ttl")
134
151
  end
@@ -138,11 +155,11 @@ module Fixtures
138
155
  end
139
156
 
140
157
  def validation?
141
- type.include?("Validation")
158
+ type.to_s.include?("Validation")
142
159
  end
143
160
 
144
161
  def warning?
145
- type.include?("Warning")
162
+ type.to_s.include?("Warning")
146
163
  end
147
164
 
148
165
  def positive_test?
@@ -150,7 +167,7 @@ module Fixtures
150
167
  end
151
168
 
152
169
  def negative_test?
153
- type.include?("Negative")
170
+ type.to_s.include?("Negative")
154
171
  end
155
172
 
156
173
  def reader_options
@@ -9,23 +9,27 @@ describe RDF::Tabular::Reader do
9
9
  before(:all) {WebMock.allow_net_connect!(net_http_connect_on_start: true)}
10
10
  after(:all) {WebMock.allow_net_connect!(net_http_connect_on_start: false)}
11
11
 
12
- %w(rdf json validation).each do |variant|
12
+ %w(rdf json validation nonnorm).each do |variant|
13
13
  describe "w3c csvw #{variant.upcase} tests" do
14
14
  manifest = Fixtures::SuiteTest::BASE + "manifest-#{variant}.jsonld"
15
15
 
16
16
  Fixtures::SuiteTest::Manifest.open(manifest, manifest[0..-8]) do |m|
17
17
  describe m.comment do
18
18
  m.entries.each do |t|
19
+ next if t.approval =~ /Rejected/
19
20
  specify "#{t.id.split("/").last}: #{t.name} - #{t.comment}" do
21
+ pending "rdf#test158 should be isomorphic" if t.id.include?("rdf#test158")
20
22
  t.debug = []
21
23
  t.warnings = []
24
+ t.errors = []
22
25
  begin
23
26
  RDF::Tabular::Reader.open(t.action,
24
27
  t.reader_options.merge(
25
28
  base_uri: t.base,
26
29
  validate: t.validation?,
27
30
  debug: t.debug,
28
- warnings: t.warnings
31
+ warnings: t.warnings,
32
+ errors: t.errors,
29
33
  )
30
34
  ) do |reader|
31
35
  expect(reader).to be_a RDF::Reader
@@ -46,38 +50,36 @@ describe RDF::Tabular::Reader do
46
50
  expect(::JSON.parse(result)).to be_a(Hash)
47
51
  end
48
52
  else # RDF or Validation
49
- begin
53
+ if t.evaluate?
50
54
  graph << reader
51
- rescue Exception => e
52
- expect(e.message).to produce("Not exception #{e.inspect}\n#{e.backtrace.join("\n")}", t.debug)
53
- end
54
-
55
- if t.sparql?
56
- RDF::Util::File.open_file(t.result) do |query|
57
- expect(graph).to pass_query(query, t)
58
- end
59
- elsif t.evaluate?
60
55
  output_graph = RDF::Repository.load(t.result, format: :ttl, base_uri: t.base)
61
56
  expect(graph).to be_equivalent_graph(output_graph, t)
62
57
  elsif t.validation?
63
- expect(graph).to be_a(RDF::Enumerable)
64
-
65
- if t.warning?
66
- expect(t.warnings.length).to produce 1, t
67
- else
68
- expect(t.warnings).to produce [], t
69
- end
58
+ expect {reader.validate!}.not_to raise_error
70
59
  end
71
60
  end
72
- else
61
+
62
+ if t.warning?
63
+ expect(t.warnings.length).to be >= 1
64
+ else
65
+ expect(t.warnings).to produce [], t
66
+ end
67
+ expect(t.errors).to produce [], t
68
+ elsif t.json?
73
69
  expect {
74
- graph << reader
75
- expect(graph.dump(:ntriples)).to produce("not this", t.debug)
70
+ reader.to_json
76
71
  }.to raise_error(RDF::Tabular::Error)
72
+ elsif t.evaluate?
73
+ expect {
74
+ graph << reader
75
+ }.to raise_error(RDF::ReaderError)
76
+ elsif t.validation?
77
+ expect {reader.validate!}.to raise_error(RDF::Tabular::Error)
77
78
  end
78
79
  end
79
- rescue Exception => e
80
- unless t.negative_test? && t.validation?
80
+ rescue IOError, RDF::Tabular::Error
81
+ # Special case
82
+ unless t.negative_test?
81
83
  raise
82
84
  end
83
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-tabular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcp47
@@ -169,6 +169,9 @@ dependencies:
169
169
  - - "~>"
170
170
  - !ruby/object:Gem::Version
171
171
  version: '3.0'
172
+ - - '='
173
+ - !ruby/object:Gem::Version
174
+ version: 3.2.0
172
175
  type: :development
173
176
  prerelease: false
174
177
  version_requirements: !ruby/object:Gem::Requirement
@@ -176,6 +179,9 @@ dependencies:
176
179
  - - "~>"
177
180
  - !ruby/object:Gem::Version
178
181
  version: '3.0'
182
+ - - '='
183
+ - !ruby/object:Gem::Version
184
+ version: 3.2.0
179
185
  - !ruby/object:Gem::Dependency
180
186
  name: rspec-its
181
187
  requirement: !ruby/object:Gem::Requirement
@@ -215,10 +221,16 @@ files:
215
221
  - README.md
216
222
  - UNLICENSE
217
223
  - VERSION
224
+ - etc/README
218
225
  - etc/csvw.jsonld
219
226
  - etc/doap.csv
220
227
  - etc/doap.csv-metadata.json
221
228
  - etc/doap.ttl
229
+ - etc/earl.html
230
+ - etc/earl.jsonld
231
+ - etc/earl.ttl
232
+ - etc/template.haml
233
+ - etc/well-known
222
234
  - lib/rdf/tabular.rb
223
235
  - lib/rdf/tabular/csvw.rb
224
236
  - lib/rdf/tabular/format.rb
@@ -255,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
267
  version: '0'
256
268
  requirements: []
257
269
  rubyforge_project:
258
- rubygems_version: 2.4.3
270
+ rubygems_version: 2.4.7
259
271
  signing_key:
260
272
  specification_version: 4
261
273
  summary: Tabular Data RDF Reader and JSON serializer.