Skip to content

Commit

Permalink
using File.expand_path to ensure path is good when tests are run from…
Browse files Browse the repository at this point in the history
… any dir
  • Loading branch information
saumier committed Dec 2, 2024
1 parent 8e1fbbf commit 3ef3014
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/sparql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

class SparqlTest < Minitest::Test
def setup
@sparql = SPARQL.parse(File.read("sparql/score_algorithm.sparql"), update: true)
shacl_files = Dir.glob("shacl/partials/*.ttl")
sparql_file = File.expand_path("../sparql/score_algorithm.sparql", __dir__)
shacl_dir = File.expand_path("../shacl/partials/*.ttl", __dir__)

@sparql = SPARQL.parse(File.read(sparql_file), update: true)
shacl_files = Dir.glob(shacl_dir)
shapes_graph = RDF::Graph.new
shacl_files.each do |file|
shapes_graph << RDF::Graph.load(file)
Expand All @@ -21,7 +24,8 @@ def setup
def test_required_properties
# If any of the three required properties is missing, the score would be 0 (zero), no matter how good the rest of the structured data is.
# An event with all three required properties would have a score of 12 + (2 x 8) = 28.
graph = RDF::Graph.load("fixtures/score_tests.jsonld")
fixture_file = File.expand_path("../fixtures/score_tests.jsonld", __dir__)
graph = RDF::Graph.load(fixture_file)
graph << @shacl.execute(graph)
graph.query(@sparql)
# puts graph.dump(:ttl)
Expand All @@ -35,7 +39,8 @@ def test_required_properties

def test_event_types
# Should accepts TheaterEvent, DanceEvent, MusicEvent, VisualArtsEvent, FilmEvent.
graph = RDF::Graph.load("fixtures/event_types.jsonld")
fixture_file = File.expand_path("../fixtures/event_types.jsonld", __dir__)
graph = RDF::Graph.load(fixture_file)
graph << @shacl.execute(graph)
graph.query(@sparql)
actual = graph.query([nil, RDF::URI('http://example.org/score'), 0]).count
Expand All @@ -45,7 +50,8 @@ def test_event_types

# test high scores and precentages
def test_high_scores
graph = RDF::Graph.load("fixtures/score_high_tests.jsonld")
fixture_file = File.expand_path("../fixtures/score_high_tests.jsonld", __dir__)
graph = RDF::Graph.load(fixture_file)
graph << @shacl.execute(graph)
graph.query(@sparql)

Expand All @@ -62,7 +68,8 @@ def test_high_scores

# Test that events with an @id are awarded 2 points
def test_event_id
graph = RDF::Graph.load("fixtures/score_event_id.jsonld")
fixture_file = File.expand_path("../fixtures/score_event_id.jsonld", __dir__)
graph = RDF::Graph.load(fixture_file)
graph << @shacl.execute(graph)
graph.query(@sparql)
actual = graph.query([ RDF::URI('http://event1'), RDF::URI('http://example.org/score'), nil]).first.object.value.to_i
Expand All @@ -74,7 +81,8 @@ def test_event_id
end

def test_alternate_postal_code
graph = RDF::Graph.load("fixtures/score_alternate_postal_address.jsonld")
fixture_file = File.expand_path("../fixtures/score_alternate_postal_address.jsonld", __dir__)
graph = RDF::Graph.load(fixture_file)
graph << @shacl.execute(graph)
graph.query(@sparql)
actual = graph.query([ nil, RDF::URI('http://example.org/postalCode_score'), nil]).first.object.value.to_i
Expand Down

0 comments on commit 3ef3014

Please sign in to comment.