<s> import logging <EOL> import xml . etree . ElementTree as ET <EOL> from siphon . ncss_dataset import NCSSDataset , _Types <EOL> from siphon . testing import get_recorder <EOL> from siphon . http_util import urlopen <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> log . setLevel ( logging . WARNING ) <EOL> log . addHandler ( logging . StreamHandler ( ) ) <EOL> recorder = get_recorder ( __file__ ) <EOL> class TestSimpleTypes ( object ) : <EOL> '<STR_LIT>' <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> cls . types = _Types ( ) <EOL> def test_attribute_1 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : "<STR_LIT>" } <EOL> actual = self . types . handle_attribute ( element ) <EOL> assert expected == actual <EOL> def test_attribute_2 ( self ) : <EOL> '<STR_LIT>' <EOL> import math <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ float ( "<STR_LIT>" ) ] } <EOL> actual = self . types . handle_attribute ( element ) <EOL> assert expected . keys ( ) == actual . keys ( ) <EOL> assert ( math . isnan ( actual [ "<STR_LIT>" ] [ <NUM_LIT:0> ] ) ) <EOL> assert ( math . isnan ( expected [ "<STR_LIT>" ] [ <NUM_LIT:0> ] ) ) <EOL> def test_attribute_3 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ float ( - <NUM_LIT> ) ] } <EOL> actual = self . types . handle_attribute ( element ) <EOL> assert expected == actual <EOL> def test_attribute_4 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ - <NUM_LIT> ] } <EOL> actual = self . types . handle_attribute ( element ) <EOL> assert expected == actual <EOL> def test_value_1 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ "<STR_LIT>" ] } <EOL> actual = self . types . handle_values ( element ) <EOL> assert expected == actual <EOL> def test_value_2 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] } <EOL> actual = self . types . handle_values ( element ) <EOL> assert expected == actual <EOL> def test_value_3 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] } <EOL> actual = self . types . handle_values ( element , value_type = "<STR_LIT:float>" ) <EOL> assert expected == actual <EOL> def test_value_4 ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] } <EOL> actual = self . types . handle_values ( element , value_type = "<STR_LIT:int>" ) <EOL> assert expected == actual <EOL> def test_projection_box ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : { "<STR_LIT>" : - <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : - <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> } } <EOL> actual = self . types . handle_projectionBox ( element ) <EOL> assert expected == actual <EOL> def test_axis_ref ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = "<STR_LIT>" <EOL> actual = self . types . handle_axisRef ( element ) <EOL> assert expected == actual <EOL> def test_coord_trans_ref ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : "<STR_LIT>" } <EOL> actual = self . types . handle_coordTransRef ( element ) <EOL> assert expected == actual <EOL> def test_grid ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ - <NUM_LIT> ] , <EOL> "<STR_LIT>" : [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] } } <EOL> actual = self . types . handle_grid ( element ) <EOL> assert expected [ "<STR_LIT>" ] == actual [ "<STR_LIT>" ] <EOL> assert expected . pop ( "<STR_LIT>" , None ) == actual . pop ( "<STR_LIT>" , None ) <EOL> def test_parameter ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : "<STR_LIT>" } <EOL> actual = self . types . handle_parameter ( element ) <EOL> assert expected == actual <EOL> def test_feature_type ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:url>" : "<STR_LIT>" <EOL> "<STR_LIT>" } <EOL> actual = self . types . handle_featureDataset ( element ) <EOL> assert expected == actual <EOL> def test_variable ( self ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT:float>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ - <NUM_LIT> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" } } <EOL> actual = self . types . handle_variable ( element ) <EOL> assert expected == actual <EOL> def test_dataset_elements_axis ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> actual = NCSSDataset ( element ) . axes <EOL> assert actual <EOL> assert len ( actual ) == <NUM_LIT:1> <EOL> assert actual [ "<STR_LIT>" ] <EOL> assert len ( actual [ "<STR_LIT>" ] ) == <NUM_LIT:4> <EOL> assert actual [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> assert len ( actual [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) == <NUM_LIT:8> <EOL> def test_dataset_elements_grid_set ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> actual = NCSSDataset ( element ) . gridsets <EOL> assert actual <EOL> assert len ( actual ) == <NUM_LIT:1> <EOL> assert actual [ "<STR_LIT>" ] <EOL> gs = actual [ "<STR_LIT>" ] <EOL> assert gs [ "<STR_LIT>" ] <EOL> assert len ( gs [ "<STR_LIT>" ] ) == <NUM_LIT:4> <EOL> assert gs [ "<STR_LIT>" ] <EOL> assert gs [ "<STR_LIT>" ] <EOL> assert len ( gs [ "<STR_LIT>" ] ) == <NUM_LIT:4> <EOL> assert gs [ "<STR_LIT>" ] <EOL> assert len ( gs [ "<STR_LIT>" ] ) == <NUM_LIT:2> <EOL> for grid in gs [ "<STR_LIT>" ] : <EOL> assert len ( gs [ "<STR_LIT>" ] [ grid ] ) == <NUM_LIT:4> <EOL> assert gs [ "<STR_LIT>" ] [ grid ] [ "<STR_LIT>" ] <EOL> assert gs [ "<STR_LIT>" ] [ grid ] [ "<STR_LIT>" ] <EOL> assert gs [ "<STR_LIT>" ] [ grid ] [ "<STR_LIT:type>" ] <EOL> assert gs [ "<STR_LIT>" ] [ grid ] [ "<STR_LIT:type>" ] == "<STR_LIT:float>" <EOL> assert len ( gs [ "<STR_LIT>" ] [ grid ] [ "<STR_LIT>" ] ) == <NUM_LIT> <EOL> def test_dataset_elements_coord_transform_valid ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> actual = NCSSDataset ( element ) . coordinate_transforms <EOL> assert actual <EOL> assert actual [ "<STR_LIT>" ] <EOL> assert len ( actual [ "<STR_LIT>" ] ) == <NUM_LIT:2> <EOL> assert actual [ "<STR_LIT>" ] [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> parameters = actual [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> assert len ( parameters ) == <NUM_LIT:5> <EOL> expected = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> assert parameters == expected <EOL> def test_dataset_elements_lat_lon_box ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : - <NUM_LIT> , <EOL> "<STR_LIT>" : - <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> } <EOL> actual = NCSSDataset ( element ) . lat_lon_box <EOL> assert actual <EOL> assert expected == actual <EOL> def test_dataset_elements_time_span ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" } <EOL> actual = NCSSDataset ( element ) . time_span <EOL> assert actual <EOL> assert expected == actual <EOL> def test_dataset_elements_accept_list ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } <EOL> actual = NCSSDataset ( element ) . accept_list <EOL> assert expected == actual <EOL> def test_dataset_elements_station_accept_list ( ) : <EOL> '<STR_LIT>' <EOL> xml = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> element = ET . fromstring ( xml ) <EOL> expected = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] } <EOL> actual = NCSSDataset ( element ) . accept_list <EOL> assert expected == actual <EOL> @ recorder . use_cassette ( '<STR_LIT>' ) <EOL> def test_dataset_elements_full_ncss_station ( ) : <EOL> '<STR_LIT>' <EOL> url = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> element = ET . fromstring ( urlopen ( url ) . read ( ) ) <EOL> parsed = NCSSDataset ( element ) <EOL> assert parsed <EOL> @ recorder . use_cassette ( '<STR_LIT>' ) <EOL> def test_dataset_elements_full_ncss_grid ( ) : <EOL> '<STR_LIT>' <EOL> url = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> element = ET . fromstring ( urlopen ( url ) . read ( ) ) <EOL> parsed = NCSSDataset ( element ) <EOL> assert parsed </s>
