Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conformance tests #91

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/bald/tests/integration/CDL/ogcClassA.cdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
netcdf ogcClassA {
dimensions:
d0 = 1 ;
d1 = 1 ;
variables:
int var0 ;
int var1 ;

data:
}
16 changes: 16 additions & 0 deletions lib/bald/tests/integration/CDL/ogcClassB.cdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
netcdf ogcClassB {
dimensions:
d0 = 1 ;
d1 = 1 ;
variables:
int var0 ;
var0:rdfs__label = "rdfs__label" ;
int var1 ;
var1:rdfs__label = "rdfs__label" ;
int prefix_list ;
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
prefix_list:rdfs__ = "http://www.w3.org/2000/01/rdf-schema#" ;
:bald__isPrefixedBy = "prefix_list" ;
data:
}
10 changes: 10 additions & 0 deletions lib/bald/tests/integration/CDL/ogcClassC.cdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
netcdf ogcClassC {
dimensions:
d0 = 1 ;
d1 = 1 ;
variables:
int var0 ;
int var1 ;
:title = "Sample netCDF file definition with alias terms from the netCDF user guide" ;
data:
}
17 changes: 17 additions & 0 deletions lib/bald/tests/integration/CDL/ogcClassD.cdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
netcdf ogcClassD {
dimensions:
d0 = 1 ;
d1 = 1 ;
variables:
int var0 ;
var0:rdfs__label = "rdfs__label" ;
int var1 ;
var1:rdfs__label = "rdfs__label" ;
int prefix_list ;
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
prefix_list:rdfs__ = "http://www.w3.org/2000/01/rdf-schema#" ;
:bald__isPrefixedBy = "prefix_list" ;
:title = "Sample netCDF file definition with alias terms from the netCDF user guide" ;
data:
}
15 changes: 15 additions & 0 deletions lib/bald/tests/integration/TTL/ogcClassA.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@prefix bald: <http://binary-array-ld.net/latest/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix this: <http://secret.binary-array-ld.net/identity.nc/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://secret.binary-array-ld.net/identity.nc> a bald:Container ;
bald:contains this:var0,
this:var1 .

this:var0 a bald:Subject .

this:var1 a bald:Subject .

18 changes: 18 additions & 0 deletions lib/bald/tests/integration/TTL/ogcClassB.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@prefix bald: <http://binary-array-ld.net/latest/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix this: <http://secret.binary-array-ld.net/prefix.nc/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://secret.binary-array-ld.net/prefix.nc> a bald:Container ;
bald:contains this:var0,
this:var1 ;
bald:isPrefixedBy "prefix_list" .

this:var0 a bald:Subject ;
rdfs:label rdfs:label .

this:var1 a bald:Subject ;
rdfs:label rdfs:label .

17 changes: 17 additions & 0 deletions lib/bald/tests/integration/TTL/ogcClassC.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@prefix NetCDF: <http://def.scitools.org.uk/NetCDF/> .
@prefix bald: <http://binary-array-ld.net/latest/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix this: <http://secret.binary-array-ld.net/alias.nc/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://secret.binary-array-ld.net/alias.nc> a bald:Container ;
bald:contains this:var0,
this:var1 ;
NetCDF:title "Sample netCDF file definition with alias terms from the netCDF user guide" .

this:var0 a bald:Subject .

this:var1 a bald:Subject .

20 changes: 20 additions & 0 deletions lib/bald/tests/integration/TTL/ogcClassD.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@prefix NetCDF: <http://def.scitools.org.uk/NetCDF/> .
@prefix bald: <http://binary-array-ld.net/latest/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix this: <http://secret.binary-array-ld.net/attributes.nc/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://secret.binary-array-ld.net/attributes.nc> a bald:Container ;
bald:contains this:var0,
this:var1 ;
bald:isPrefixedBy "prefix_list" ;
NetCDF:title "Sample netCDF file definition with alias terms from the netCDF user guide" .

this:var0 a bald:Subject ;
rdfs:label rdfs:label .

this:var1 a bald:Subject ;
rdfs:label rdfs:label .

79 changes: 79 additions & 0 deletions lib/bald/tests/integration/test_ogc_conformance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import subprocess
import unittest

import netCDF4
import numpy as np

import bald
from bald.tests import BaldTestCase

class Test(BaldTestCase):
def setUp(self):
self.cdl_path = os.path.join(os.path.dirname(__file__), 'CDL')
self.ttl_path = os.path.join(os.path.dirname(__file__), 'TTL')
self.maxDiff = None

def test_conformance_a(self):
with self.temp_filename('.nc') as tfile:
cdlname = 'ogcClassA.cdl'
cdl_file = os.path.join(self.cdl_path, cdlname)
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
cdl_file_uri = 'http://secret.binary-array-ld.net/identity.nc'
root_container = bald.load_netcdf(tfile, baseuri=cdl_file_uri, cache=self.acache)
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
if os.environ.get('bald_update_results') is not None:
with open(os.path.join(self.ttl_path, 'ogcClassA.ttl'), 'w') as sf:
sf.write(ttl)
with open(os.path.join(self.ttl_path, 'ogcClassA.ttl'), 'r') as sf:
expected_ttl = sf.read()
self.assertEqual(expected_ttl, ttl)

def test_conformance_b(self):
with self.temp_filename('.nc') as tfile:
cdlname = 'ogcClassB.cdl'
cdl_file = os.path.join(self.cdl_path, cdlname)
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
cdl_file_uri = 'http://secret.binary-array-ld.net/prefix.nc'
root_container = bald.load_netcdf(tfile, baseuri=cdl_file_uri, cache=self.acache)
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
if os.environ.get('bald_update_results') is not None:
with open(os.path.join(self.ttl_path, 'ogcClassB.ttl'), 'w') as sf:
sf.write(ttl)
with open(os.path.join(self.ttl_path, 'ogcClassB.ttl'), 'r') as sf:
expected_ttl = sf.read()
self.assertEqual(expected_ttl, ttl)

def test_conformance_c(self):
with self.temp_filename('.nc') as tfile:
cdlname = 'ogcClassC.cdl'
cdl_file = os.path.join(self.cdl_path, cdlname)
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
cdl_file_uri = 'http://secret.binary-array-ld.net/alias.nc'
alias_dict = {'NetCDF': 'http://def.scitools.org.uk/NetCDF'}
root_container = bald.load_netcdf(tfile, baseuri=cdl_file_uri,
alias_dict=alias_dict, cache=self.acache)
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
if os.environ.get('bald_update_results') is not None:
with open(os.path.join(self.ttl_path, 'ogcClassC.ttl'), 'w') as sf:
sf.write(ttl)
with open(os.path.join(self.ttl_path, 'ogcClassC.ttl'), 'r') as sf:
expected_ttl = sf.read()
self.assertEqual(expected_ttl, ttl)

def test_conformance_d(self):
with self.temp_filename('.nc') as tfile:
cdlname = 'ogcClassD.cdl'
cdl_file = os.path.join(self.cdl_path, cdlname)
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
cdl_file_uri = 'http://secret.binary-array-ld.net/attributes.nc'
alias_dict = {'NetCDF': 'http://def.scitools.org.uk/NetCDF'}
root_container = bald.load_netcdf(tfile, baseuri=cdl_file_uri,
alias_dict=alias_dict, cache=self.acache)
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
if os.environ.get('bald_update_results') is not None:
with open(os.path.join(self.ttl_path, 'ogcClassD.ttl'), 'w') as sf:
sf.write(ttl)
with open(os.path.join(self.ttl_path, 'ogcClassD.ttl'), 'r') as sf:
expected_ttl = sf.read()
self.assertEqual(expected_ttl, ttl)