Skip to content

Commit 665f9e4

Browse files
committed
do not test for uri resolution by default
1 parent 6cd816c commit 665f9e4

File tree

7 files changed

+77
-65
lines changed

7 files changed

+77
-65
lines changed

lib/bald/__init__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,26 +1011,26 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
10111011
return root_container
10121012

10131013

1014-
def validate_netcdf(afilepath, baseuri=None, cache=None):
1014+
def validate_netcdf(afilepath, baseuri=None, cache=None, uris_resolve=False):
10151015
"""
10161016
Validate a file with respect to binary-array-linked-data.
10171017
Returns a :class:`bald.validation.Validation`
10181018
10191019
"""
10201020
root_container = load_netcdf(afilepath, baseuri=baseuri, cache=cache)
1021-
return validate(root_container, cache=cache)
1021+
return validate(root_container, cache=cache, uris_resolve=uris_resolve)
10221022

10231023

1024-
def validate_hdf5(afilepath, baseuri=None, cache=None):
1024+
def validate_hdf5(afilepath, baseuri=None, cache=None, uris_resolve=False):
10251025
"""
10261026
Validate a file with respect to binary-array-linked-data.
10271027
Returns a :class:`bald.validation.Validation`
10281028
10291029
"""
10301030
root_container = load_hdf5(afilepath, baseuri=baseuri, cache=cache)
1031-
return validate(root_container, cache=cache)
1031+
return validate(root_container, cache=cache, uris_resolve=uris_resolve)
10321032

1033-
def validate(root_container, sval=None, cache=None):
1033+
def validate(root_container, sval=None, cache=None, uris_resolve=False):
10341034
"""
10351035
Validate a Container with respect to binary-array-linked-data.
10361036
Returns a :class:`bald.validation.Validation`
@@ -1039,16 +1039,20 @@ def validate(root_container, sval=None, cache=None):
10391039
if sval is None:
10401040
sval = bv.StoredValidation()
10411041

1042-
root_val = bv.ContainerValidation(subject=root_container, httpcache=cache)
1042+
root_val = bv.ContainerValidation(subject=root_container, httpcache=cache,
1043+
uris_resolve=uris_resolve)
10431044
sval.stored_exceptions += root_val.exceptions()
10441045
for subject in root_container.attrs.get('bald__contains', set()):
10451046
if isinstance(subject, Array):
1046-
array_val = bv.ArrayValidation(subject, httpcache=cache)
1047+
array_val = bv.ArrayValidation(subject, httpcache=cache,
1048+
uris_resolve=uris_resolve)
10471049
sval.stored_exceptions += array_val.exceptions()
10481050
elif isinstance(subject, Container):
1049-
sval = validate(subject, sval=sval, cache=cache)
1051+
sval = validate(subject, sval=sval, cache=cache,
1052+
uris_resolve=uris_resolve)
10501053
elif isinstance(subject, Subject):
1051-
subject_val = bv.SubjectValidation(subject, httpcache=cache)
1054+
subject_val = bv.SubjectValidation(subject, httpcache=cache,
1055+
uris_resolve=uris_resolve)
10521056
sval.stored_exceptions += subject_val.exceptions()
10531057

10541058
return sval

lib/bald/tests/integration/test_aliases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def test_invalid_uri(self):
5252
dsetp = f.create_dataset("parent_dataset", (11, 17), dtype='i')
5353
dsetp.attrs['skosPrefLabel'] = 'alabel'
5454
f.close()
55-
validation = bald.validate_hdf5(tfile, cache=self.acache)
55+
validation = bald.validate_hdf5(tfile, cache=self.acache,
56+
uris_resolve=True)
5657
exns = validation.exceptions()
5758
expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
5859
'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']

lib/bald/tests/integration/test_cdl.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,47 @@ def atest(self):
3030
setattr(Test, 'test_{}'.format(file_id), make_a_test(cdl_file))
3131

3232

33-
def test_ereefs_gbr4_ncld(self):
34-
"""Override ereefs test with currently accepted failures"""
35-
with self.temp_filename('.nc') as tfile:
36-
cdl_file = os.path.join(self.cdl_path, 'ereefs_gbr4_ncld.cdl')
37-
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
38-
validation = bald.validate_netcdf(tfile, cache=self.acache)
39-
exns = validation.exceptions()
40-
exns.sort()
41-
# expected = ['http://qudt.org/vocab/unit#Meter is not resolving as a resource (404).',
42-
# 'http://qudt.org/vocab/unit#MeterPerSecond is not resolving as a resource (404).',
43-
# 'http://qudt.org/vocab/unit#MeterPerSecond is not resolving as a resource (404).',
44-
# 'http://qudt.org/vocab/unit#DegreeCelsius is not resolving as a resource (404).']
45-
# expected.sort()
46-
# self.assertTrue(not validation.is_valid() and exns == expected,
47-
# msg='{} \n!= \n{}'.format(exns, expected))
48-
self.assertTrue(not validation.is_valid())
49-
50-
setattr(Test, 'test_ereefs_gbr4_ncld', test_ereefs_gbr4_ncld)
51-
52-
53-
def test_ProcessChain0300(self):
54-
"""Override ProcessChain 0300 test with currently accepted failures"""
55-
self.assertTrue(True)
56-
57-
setattr(Test, 'test_ProcessChain0300', test_ProcessChain0300)
58-
59-
60-
def test_grid_OISST_GHRSST(self):
61-
"""Override grid OISST GHRSST test with currently accepted failures"""
62-
with self.temp_filename('.nc') as tfile:
63-
cdl_file = os.path.join(self.cdl_path, 'grid_OISST_GHRSST.cdl')
64-
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
65-
validation = bald.validate_netcdf(tfile, cache=self.acache)
66-
exns = validation.exceptions()
67-
exns.sort()
68-
expected = ['http://doi.org/10.7289/V5SQ8XB5 is not resolving as a resource (404).',
69-
'http://www.ncdc.noaa.gov/sst is not resolving as a resource (404).',
70-
'http://www.ncdc.noaa.gov/sst/ is not resolving as a resource (404).']
71-
expected.sort()
72-
self.assertTrue(not validation.is_valid() and exns == expected,
73-
msg='{} \n!= \n{}'.format(exns, expected))
74-
75-
setattr(Test, 'test_grid_OISST_GHRSST', test_grid_OISST_GHRSST)
33+
# def test_ereefs_gbr4_ncld(self):
34+
# """Override ereefs test with currently accepted failures"""
35+
# with self.temp_filename('.nc') as tfile:
36+
# cdl_file = os.path.join(self.cdl_path, 'ereefs_gbr4_ncld.cdl')
37+
# subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
38+
# validation = bald.validate_netcdf(tfile, cache=self.acache)
39+
# exns = validation.exceptions()
40+
# exns.sort()
41+
# # expected = ['http://qudt.org/vocab/unit#Meter is not resolving as a resource (404).',
42+
# # 'http://qudt.org/vocab/unit#MeterPerSecond is not resolving as a resource (404).',
43+
# # 'http://qudt.org/vocab/unit#MeterPerSecond is not resolving as a resource (404).',
44+
# # 'http://qudt.org/vocab/unit#DegreeCelsius is not resolving as a resource (404).']
45+
# # expected.sort()
46+
# # self.assertTrue(not validation.is_valid() and exns == expected,
47+
# # msg='{} \n!= \n{}'.format(exns, expected))
48+
# self.assertTrue(not validation.is_valid())
49+
50+
# setattr(Test, 'test_ereefs_gbr4_ncld', test_ereefs_gbr4_ncld)
51+
52+
53+
# def test_ProcessChain0300(self):
54+
# """Override ProcessChain 0300 test with currently accepted failures"""
55+
# self.assertTrue(True)
56+
57+
# setattr(Test, 'test_ProcessChain0300', test_ProcessChain0300)
58+
59+
60+
# def test_grid_OISST_GHRSST(self):
61+
# """Override grid OISST GHRSST test with currently accepted failures"""
62+
# with self.temp_filename('.nc') as tfile:
63+
# cdl_file = os.path.join(self.cdl_path, 'grid_OISST_GHRSST.cdl')
64+
# subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
65+
# validation = bald.validate_netcdf(tfile, cache=self.acache)
66+
# exns = validation.exceptions()
67+
# self.assertTrue(validation.is_valid(), msg='{} != []'.format(exns))
68+
# # exns.sort()
69+
# # expected = ['http://doi.org/10.7289/V5SQ8XB5 is not resolving as a resource (404).',
70+
# # 'http://www.ncdc.noaa.gov/sst is not resolving as a resource (404).',
71+
# # 'http://www.ncdc.noaa.gov/sst/ is not resolving as a resource (404).']
72+
# # expected.sort()
73+
# # self.assertTrue(not validation.is_valid() and exns == expected,
74+
# # msg='{} \n!= \n{}'.format(exns, expected))
75+
76+
# setattr(Test, 'test_grid_OISST_GHRSST', test_grid_OISST_GHRSST)

lib/bald/tests/integration/test_netcdf.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ def test_invalid_uri(self):
5151
f.close()
5252
validation = bald.validate_netcdf(tfile, cache=self.acache)
5353
exns = validation.exceptions()
54-
expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
55-
'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']
56-
self.assertTrue((not validation.is_valid()) and exns == expected,
57-
msg='{} != {}'.format(exns, expected))
54+
self.assertTrue(validation.is_valid(), msg='{} != []'.format(exns))
55+
# expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
56+
# 'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']
57+
# self.assertTrue((not validation.is_valid()) and exns == expected,
58+
# msg='{} != {}'.format(exns, expected))
5859

5960

6061
class TestArrayReference(BaldTestCase):

lib/bald/tests/integration/test_netcdf4_classic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ def test_invalid_uri(self):
4747
f = _fattrs(f)
4848
setattr(f, 'bald__turtle', 'bald__walnut')
4949
f.close()
50-
validation = bald.validate_netcdf(tfile, cache=self.acache)
50+
validation = bald.validate_netcdf(tfile, cache=self.acache,
51+
uris_resolve=True)
5152
exns = validation.exceptions()
52-
53+
5354
expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
5455
'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']
5556
self.assertTrue((not validation.is_valid()) and exns == expected,

lib/bald/tests/integration/test_validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_invalid_uri(self):
4444
f = _create_parent_child(f, (11, 17), (11, 17))
4545
f.attrs['bald__turtle'] = 'bald__walnut'
4646
f.close()
47-
validation = bald.validate_hdf5(tfile, cache=self.acache)
47+
validation = bald.validate_hdf5(tfile, cache=self.acache,
48+
uris_resolve=True)
4849
exns = validation.exceptions()
4950
expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
5051
'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']

lib/bald/validation.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@ def exceptions(self):
6262

6363

6464
class SubjectValidation(Validation):
65-
def __init__(self, subject, httpcache=None):
65+
def __init__(self, subject, httpcache=None, uris_resolve=False):
6666
self.subject = subject
6767
if isinstance(httpcache, bald.HttpCache):
6868
self.cache = httpcache
6969
else:
7070
self.cache = bald.HttpCache()
71+
self.uris_resolve = False
72+
if uris_resolve == True:
73+
self.uris_resolve = True
7174

7275
def is_valid(self):
7376
return not self.exceptions()
7477

7578
def exceptions(self):
7679
exceptions = []
77-
exceptions = self.check_attr_uris(exceptions)
80+
if self.uris_resolve:
81+
exceptions = self.check_attr_uris(exceptions)
7882
exceptions = self.check_attr_domain_range(exceptions)
7983
exceptions = self._extra_exceptions(exceptions)
8084
return exceptions
@@ -158,10 +162,9 @@ def __init__(self, **kwargs):
158162

159163

160164
class ArrayValidation(SubjectValidation):
161-
162-
def __init__(self, array, httpcache=None):
165+
def __init__(self, array, httpcache=None, uris_resolve=False):
163166
self.array = array
164-
super(ArrayValidation, self).__init__(array, httpcache)
167+
super(ArrayValidation, self).__init__(array, httpcache, uris_resolve)
165168

166169
def _extra_exceptions(self, exceptions):
167170
exceptions = self.check_array_references(exceptions)

0 commit comments

Comments
 (0)