Skip to content

use OGC test cases #100

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

Merged
merged 1 commit into from
Oct 30, 2020
Merged
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: 0 additions & 10 deletions lib/bald/tests/integration/CDL/ogcClassA.cdl

This file was deleted.

16 changes: 0 additions & 16 deletions lib/bald/tests/integration/CDL/ogcClassB.cdl

This file was deleted.

10 changes: 0 additions & 10 deletions lib/bald/tests/integration/CDL/ogcClassC.cdl

This file was deleted.

17 changes: 0 additions & 17 deletions lib/bald/tests/integration/CDL/ogcClassD.cdl

This file was deleted.

22 changes: 0 additions & 22 deletions lib/bald/tests/integration/TTL/ogcClassA.ttl

This file was deleted.

25 changes: 0 additions & 25 deletions lib/bald/tests/integration/TTL/ogcClassB.ttl

This file was deleted.

24 changes: 0 additions & 24 deletions lib/bald/tests/integration/TTL/ogcClassC.ttl

This file was deleted.

27 changes: 0 additions & 27 deletions lib/bald/tests/integration/TTL/ogcClassD.ttl

This file was deleted.

84 changes: 68 additions & 16 deletions lib/bald/tests/integration/test_ogc_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import netCDF4
import numpy as np
import requests

import bald
from bald.tests import BaldTestCase

OGCFiles = ('https://raw.githubusercontent.com/opengeospatial/netcdf-ld/'
'master/standard/abstract_tests/')

class Test(BaldTestCase):
def setUp(self):
self.cdl_path = os.path.join(os.path.dirname(__file__), 'CDL')
Expand All @@ -18,62 +22,110 @@ def test_conformance_a(self):
with self.temp_filename('.nc') as tfile:
cdlname = 'ogcClassA.cdl'
cdl_file = os.path.join(self.cdl_path, cdlname)
with open(cdl_file, 'w') as cdlf:
cdluri = '{}CDL/ogcClassA.cdl'.format(OGCFiles)
r = requests.get(cdluri)
if r.status_code != 200:
raise ValueError('CDL download failed for {}'.format(cdluri))
cdlf.write(r.text)
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:
ttl_file = os.path.join(self.ttl_path, 'ogcClassA.ttl')
with open(ttl_file, 'w') as ttlf:
ttluri = '{}TTL/ogcClassA.ttl'.format(OGCFiles)
r = requests.get(ttluri)
if r.status_code != 200:
raise ValueError('TTL download failed for {}'.format(ttluri))
ttlf.write(r.text)
with open(ttl_file, 'r') as sf:
expected_ttl = sf.read()
os.remove(ttl_file)
os.remove(cdl_file)
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)
with open(cdl_file, 'w') as cdlf:
cdluri = '{}CDL/ogcClassB.cdl'.format(OGCFiles)
r = requests.get(cdluri)
if r.status_code != 200:
raise ValueError('CDL download failed for {}'.format(cdluri))
cdlf.write(r.text)
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:
ttl_file = os.path.join(self.ttl_path, 'ogcClassA.ttl')
with open(ttl_file, 'w') as ttlf:
ttluri = '{}TTL/ogcClassB.ttl'.format(OGCFiles)
r = requests.get(ttluri)
if r.status_code != 200:
raise ValueError('TTL download failed for {}'.format(ttluri))
ttlf.write(r.text)
with open(ttl_file, 'r') as sf:
expected_ttl = sf.read()
os.remove(ttl_file)
os.remove(cdl_file)
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)
with open(cdl_file, 'w') as cdlf:
cdluri = '{}CDL/ogcClassC.cdl'.format(OGCFiles)
r = requests.get(cdluri)
if r.status_code != 200:
raise ValueError('CDL download failed for {}'.format(cdluri))
cdlf.write(r.text)
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:
ttl_file = os.path.join(self.ttl_path, 'ogcClassA.ttl')
with open(ttl_file, 'w') as ttlf:
ttluri = '{}TTL/ogcClassC.ttl'.format(OGCFiles)
r = requests.get(ttluri)
if r.status_code != 200:
raise ValueError('TTL download failed for {}'.format(ttluri))
ttlf.write(r.text)
with open(ttl_file, 'r') as sf:
expected_ttl = sf.read()
os.remove(ttl_file)
os.remove(cdl_file)
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)
with open(cdl_file, 'w') as cdlf:
cdluri = '{}CDL/ogcClassD.cdl'.format(OGCFiles)
r = requests.get(cdluri)
if r.status_code != 200:
raise ValueError('CDL download failed for {}'.format(cdluri))
cdlf.write(r.text)
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:
ttl_file = os.path.join(self.ttl_path, 'ogcClassA.ttl')
with open(ttl_file, 'w') as ttlf:
ttluri = '{}TTL/ogcClassD.ttl'.format(OGCFiles)
r = requests.get(ttluri)
if r.status_code != 200:
raise ValueError('TTL download failed for {}'.format(ttluri))
ttlf.write(r.text)
with open(ttl_file, 'r') as sf:
expected_ttl = sf.read()
os.remove(ttl_file)
os.remove(cdl_file)
self.assertEqual(expected_ttl, ttl)