Exemple #1
0
    def test_from_bad_string(self):
        u = IoosUrn.from_string('urn:ioos:sensor:whatami')
        assert u.urn is None

        u = IoosUrn.from_string('urn:ioos:nothinghere')
        assert u.urn is None

        u = IoosUrn.from_string('urn:totesbroken')
        assert u.urn is None
Exemple #2
0
 def test_messy_urn(self):
     u = IoosUrn.from_string('urn:ioos:sensor:myauthority:mylabel:standard_name#key=key1:value1,key2:value2;some_other_key=some_other_value')
     assert u.asset_type == 'sensor'
     assert u.authority  == 'myauthority'
     assert u.label      == 'mylabel'
     assert u.component  == 'standard_name'
     assert u.fragment   == 'key=key1:value1,key2:value2;some_other_key=some_other_value'
     assert u.discriminant is None
Exemple #3
0
 def test_cdiac_urn_with_discrim(self):
     u = IoosUrn.from_string('urn:ioos:sensor:gov.ornl.cdiac:cheeca_80w_25n:sea_water_temperature:somediscrim#key=key1:value1,key2:value2;some_other_key=some_other_value')
     assert u.asset_type == 'sensor'
     assert u.authority  == 'gov.ornl.cdiac'
     assert u.label      == 'cheeca_80w_25n'
     assert u.component  == 'sea_water_temperature'
     assert u.fragment   == 'key=key1:value1,key2:value2;some_other_key=some_other_value'
     assert u.discriminant == 'somediscrim'
Exemple #4
0
 def test_cdiac_urn(self):
     u = IoosUrn.from_string('urn:ioos:sensor:gov.ornl.cdiac:cheeca_80w_25n:sea_water_temperature')
     assert u.asset_type == 'sensor'
     assert u.authority  == 'gov.ornl.cdiac'
     assert u.label      == 'cheeca_80w_25n'
     assert u.component  == 'sea_water_temperature'
     assert u.fragment is None
     assert u.discriminant is None
Exemple #5
0
    def test_from_string(self):
        u = IoosUrn.from_string('urn:ioos:sensor:myauthority:mylabel')
        assert u.asset_type == 'sensor'
        assert u.authority  == 'myauthority'
        assert u.label      == 'mylabel'
        assert u.discriminant is None

        u = IoosUrn.from_string('urn:ioos:sensor:myauthority:mylabel:mycomponent')
        assert u.asset_type == 'sensor'
        assert u.authority  == 'myauthority'
        assert u.label      == 'mylabel'
        assert u.component  == 'mycomponent'
        assert u.discriminant is None

        u = IoosUrn.from_string('urn:ioos:sensor:myauthority:mylabel:mycomponent:mydiscriminant')
        assert u.asset_type == 'sensor'
        assert u.authority  == 'myauthority'
        assert u.label      == 'mylabel'
        assert u.component  == 'mycomponent'
        assert u.discriminant == 'mydiscriminant'
Exemple #6
0
    def test_change_sensor_to_station(self):
        u = IoosUrn.from_string('urn:ioos:sensor:myauthority:mylabel:mycomponent')
        assert u.asset_type == 'sensor'
        assert u.authority  == 'myauthority'
        assert u.label      == 'mylabel'
        assert u.component  == 'mycomponent'
        assert u.fragment is None
        assert u.discriminant is None

        u.asset_type = 'station'
        u.component = None
        assert u.urn == 'urn:ioos:station:myauthority:mylabel'
Exemple #7
0
 def test_from_long_string(self):
     u = IoosUrn.from_string('urn:ioos:sensor:whatami:wow:i:have:lots:of:things')
     assert u.urn == 'urn:ioos:sensor:whatami:wow:i:have'
Exemple #8
0
    def test_dict_from_urn(self):
        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean time: variance (interval: PT1H)'
        assert 'interval' not in d
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h'
        d = IoosUrn.from_string(urn).attributes(combine_interval=False)
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean time: variance'
        assert d['interval'] == 'PT1H'
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h,pt6h'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean (interval: PT1H) time: variance (interval: PT6H)'
        assert 'interval' not in d
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h,pt6h'
        d = IoosUrn.from_string(urn).attributes(combine_interval=False)
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean time: variance'
        assert d['interval'] == 'PT1H,PT6H'
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:variance;interval=pt1h'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: variance (interval: PT1H)'
        assert 'interval' not in d
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:variance;interval=pt1h'
        d = IoosUrn.from_string(urn).attributes(combine_interval=False)
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: variance'
        assert d['interval'] == 'PT1H'
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean_over_years,time:minimum_within_years'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean over years time: minimum within years'
        assert 'interval' not in d
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#vertical_datum=navd88'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['vertical_datum'] == 'NAVD88'
        assert 'interval' not in d
        assert 'cell_methods' not in d
        assert 'discriminant' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert 'interval' not in d
        assert 'cell_methods' not in d
        assert 'discriminant' not in d
        assert 'vertical_datum' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['discriminant'] == '2'
        assert 'interval' not in d
        assert 'cell_methods' not in d

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#cell_methods=time:mean_over_years,time:minimum_within_years;vertical_datum=navd88'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean over years time: minimum within years'
        assert d['discriminant'] == '2'
        assert d['vertical_datum'] == 'NAVD88'

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#cell_methods=time:mean_over_years,time:minimum_within_years;interval=pt1h;vertical_datum=navd88'
        d = IoosUrn.from_string(urn).attributes()
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean over years time: minimum within years (interval: PT1H)'
        assert d['discriminant'] == '2'
        assert 'interval' not in d
        assert d['vertical_datum'] == 'NAVD88'

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#cell_methods=time:mean_over_years,time:minimum_within_years;interval=pt1h;vertical_datum=navd88'
        d = IoosUrn.from_string(urn).attributes(combine_interval=False)
        assert d['standard_name'] == 'lwe_thickness_of_precipitation_amount'
        assert d['cell_methods'] == 'time: mean over years time: minimum within years'
        assert d['discriminant'] == '2'
        assert d['interval'] == 'PT1H'
        assert d['vertical_datum'] == 'NAVD88'

        urn = 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#interval=pt2h'
        # Cant have an interval without a cell_method
        with self.assertRaises(ValueError):
            d = IoosUrn.from_string(urn).attributes()