4
4
5
5
import netCDF4
6
6
import numpy as np
7
+ import requests
7
8
8
9
import bald
9
10
from bald .tests import BaldTestCase
10
11
12
+ OGCFiles = ('https://raw.githubusercontent.com/opengeospatial/netcdf-ld/'
13
+ 'master/standard/abstract_tests/' )
14
+
11
15
class Test (BaldTestCase ):
12
16
def setUp (self ):
13
17
self .cdl_path = os .path .join (os .path .dirname (__file__ ), 'CDL' )
@@ -18,62 +22,110 @@ def test_conformance_a(self):
18
22
with self .temp_filename ('.nc' ) as tfile :
19
23
cdlname = 'ogcClassA.cdl'
20
24
cdl_file = os .path .join (self .cdl_path , cdlname )
25
+ with open (cdl_file , 'w' ) as cdlf :
26
+ cdluri = '{}CDL/ogcClassA.cdl' .format (OGCFiles )
27
+ r = requests .get (cdluri )
28
+ if r .status_code != 200 :
29
+ raise ValueError ('CDL download failed for {}' .format (cdluri ))
30
+ cdlf .write (r .text )
21
31
subprocess .check_call (['ncgen' , '-o' , tfile , cdl_file ])
22
32
cdl_file_uri = 'http://secret.binary-array-ld.net/identity.nc'
23
33
root_container = bald .load_netcdf (tfile , baseuri = cdl_file_uri , cache = self .acache )
24
34
ttl = root_container .rdfgraph ().serialize (format = 'n3' ).decode ("utf-8" )
25
- if os .environ .get ('bald_update_results' ) is not None :
26
- with open (os .path .join (self .ttl_path , 'ogcClassA.ttl' ), 'w' ) as sf :
27
- sf .write (ttl )
28
- with open (os .path .join (self .ttl_path , 'ogcClassA.ttl' ), 'r' ) as sf :
35
+ ttl_file = os .path .join (self .ttl_path , 'ogcClassA.ttl' )
36
+ with open (ttl_file , 'w' ) as ttlf :
37
+ ttluri = '{}TTL/ogcClassA.ttl' .format (OGCFiles )
38
+ r = requests .get (ttluri )
39
+ if r .status_code != 200 :
40
+ raise ValueError ('TTL download failed for {}' .format (ttluri ))
41
+ ttlf .write (r .text )
42
+ with open (ttl_file , 'r' ) as sf :
29
43
expected_ttl = sf .read ()
44
+ os .remove (ttl_file )
45
+ os .remove (cdl_file )
30
46
self .assertEqual (expected_ttl , ttl )
31
47
32
48
def test_conformance_b (self ):
33
49
with self .temp_filename ('.nc' ) as tfile :
34
50
cdlname = 'ogcClassB.cdl'
35
51
cdl_file = os .path .join (self .cdl_path , cdlname )
52
+ with open (cdl_file , 'w' ) as cdlf :
53
+ cdluri = '{}CDL/ogcClassB.cdl' .format (OGCFiles )
54
+ r = requests .get (cdluri )
55
+ if r .status_code != 200 :
56
+ raise ValueError ('CDL download failed for {}' .format (cdluri ))
57
+ cdlf .write (r .text )
36
58
subprocess .check_call (['ncgen' , '-o' , tfile , cdl_file ])
37
59
cdl_file_uri = 'http://secret.binary-array-ld.net/prefix.nc'
38
60
root_container = bald .load_netcdf (tfile , baseuri = cdl_file_uri , cache = self .acache )
39
61
ttl = root_container .rdfgraph ().serialize (format = 'n3' ).decode ("utf-8" )
40
- if os .environ .get ('bald_update_results' ) is not None :
41
- with open (os .path .join (self .ttl_path , 'ogcClassB.ttl' ), 'w' ) as sf :
42
- sf .write (ttl )
43
- with open (os .path .join (self .ttl_path , 'ogcClassB.ttl' ), 'r' ) as sf :
62
+ ttl_file = os .path .join (self .ttl_path , 'ogcClassA.ttl' )
63
+ with open (ttl_file , 'w' ) as ttlf :
64
+ ttluri = '{}TTL/ogcClassB.ttl' .format (OGCFiles )
65
+ r = requests .get (ttluri )
66
+ if r .status_code != 200 :
67
+ raise ValueError ('TTL download failed for {}' .format (ttluri ))
68
+ ttlf .write (r .text )
69
+ with open (ttl_file , 'r' ) as sf :
44
70
expected_ttl = sf .read ()
71
+ os .remove (ttl_file )
72
+ os .remove (cdl_file )
45
73
self .assertEqual (expected_ttl , ttl )
46
74
47
75
def test_conformance_c (self ):
48
76
with self .temp_filename ('.nc' ) as tfile :
49
77
cdlname = 'ogcClassC.cdl'
50
78
cdl_file = os .path .join (self .cdl_path , cdlname )
79
+ with open (cdl_file , 'w' ) as cdlf :
80
+ cdluri = '{}CDL/ogcClassC.cdl' .format (OGCFiles )
81
+ r = requests .get (cdluri )
82
+ if r .status_code != 200 :
83
+ raise ValueError ('CDL download failed for {}' .format (cdluri ))
84
+ cdlf .write (r .text )
51
85
subprocess .check_call (['ncgen' , '-o' , tfile , cdl_file ])
52
86
cdl_file_uri = 'http://secret.binary-array-ld.net/alias.nc'
53
87
alias_dict = {'NetCDF' : 'http://def.scitools.org.uk/NetCDF' }
54
88
root_container = bald .load_netcdf (tfile , baseuri = cdl_file_uri ,
55
89
alias_dict = alias_dict , cache = self .acache )
56
90
ttl = root_container .rdfgraph ().serialize (format = 'n3' ).decode ("utf-8" )
57
- if os .environ .get ('bald_update_results' ) is not None :
58
- with open (os .path .join (self .ttl_path , 'ogcClassC.ttl' ), 'w' ) as sf :
59
- sf .write (ttl )
60
- with open (os .path .join (self .ttl_path , 'ogcClassC.ttl' ), 'r' ) as sf :
91
+ ttl_file = os .path .join (self .ttl_path , 'ogcClassA.ttl' )
92
+ with open (ttl_file , 'w' ) as ttlf :
93
+ ttluri = '{}TTL/ogcClassC.ttl' .format (OGCFiles )
94
+ r = requests .get (ttluri )
95
+ if r .status_code != 200 :
96
+ raise ValueError ('TTL download failed for {}' .format (ttluri ))
97
+ ttlf .write (r .text )
98
+ with open (ttl_file , 'r' ) as sf :
61
99
expected_ttl = sf .read ()
100
+ os .remove (ttl_file )
101
+ os .remove (cdl_file )
62
102
self .assertEqual (expected_ttl , ttl )
63
103
64
104
def test_conformance_d (self ):
65
105
with self .temp_filename ('.nc' ) as tfile :
66
106
cdlname = 'ogcClassD.cdl'
67
107
cdl_file = os .path .join (self .cdl_path , cdlname )
108
+ with open (cdl_file , 'w' ) as cdlf :
109
+ cdluri = '{}CDL/ogcClassD.cdl' .format (OGCFiles )
110
+ r = requests .get (cdluri )
111
+ if r .status_code != 200 :
112
+ raise ValueError ('CDL download failed for {}' .format (cdluri ))
113
+ cdlf .write (r .text )
68
114
subprocess .check_call (['ncgen' , '-o' , tfile , cdl_file ])
69
115
cdl_file_uri = 'http://secret.binary-array-ld.net/attributes.nc'
70
116
alias_dict = {'NetCDF' : 'http://def.scitools.org.uk/NetCDF' }
71
117
root_container = bald .load_netcdf (tfile , baseuri = cdl_file_uri ,
72
118
alias_dict = alias_dict , cache = self .acache )
73
119
ttl = root_container .rdfgraph ().serialize (format = 'n3' ).decode ("utf-8" )
74
- if os .environ .get ('bald_update_results' ) is not None :
75
- with open (os .path .join (self .ttl_path , 'ogcClassD.ttl' ), 'w' ) as sf :
76
- sf .write (ttl )
77
- with open (os .path .join (self .ttl_path , 'ogcClassD.ttl' ), 'r' ) as sf :
120
+ ttl_file = os .path .join (self .ttl_path , 'ogcClassA.ttl' )
121
+ with open (ttl_file , 'w' ) as ttlf :
122
+ ttluri = '{}TTL/ogcClassD.ttl' .format (OGCFiles )
123
+ r = requests .get (ttluri )
124
+ if r .status_code != 200 :
125
+ raise ValueError ('TTL download failed for {}' .format (ttluri ))
126
+ ttlf .write (r .text )
127
+ with open (ttl_file , 'r' ) as sf :
78
128
expected_ttl = sf .read ()
129
+ os .remove (ttl_file )
130
+ os .remove (cdl_file )
79
131
self .assertEqual (expected_ttl , ttl )
0 commit comments