Example #1
0
def test_bad_magic(caplog):
    """Test that we get notified of bad magic bytes in stream."""
    # Try reading a bad message
    f = BytesIO(b'\x00\x01\x02\x03')
    read_ncstream_messages(f)

    assert 'Unknown magic' in caplog.text
Example #2
0
def test_bad_magic():
    'Test that we get notified of bad magic bytes in stream'
    import logging
    import sys

    # Only StringIO's version supports writing str
    if sys.version_info.major == 2:
        from StringIO import StringIO
    else:
        from io import StringIO

    # Set up capturing of logging
    log = logging.getLogger('siphon.cdmr.ncstream')
    err_out = StringIO()
    log.addHandler(logging.StreamHandler(err_out))

    # Try reading a bad message
    f = BytesIO(b'\x00\x01\x02\x03')
    read_ncstream_messages(f)

    log.handlers.pop()

    # Make sure we got some error output
    err_out.seek(0)
    assert 'Unknown magic' in err_out.read()
Example #3
0
def test_bad_magic():
    'Test that we get notified of bad magic bytes in stream'
    import logging
    import sys

    # Only StringIO's version supports writing str
    if sys.version_info.major == 2:
        from StringIO import StringIO
    else:
        from io import StringIO

    # Set up capturing of logging
    log = logging.getLogger('siphon.cdmr.ncstream')
    err_out = StringIO()
    log.addHandler(logging.StreamHandler(err_out))

    # Try reading a bad message
    f = BytesIO(b'\x00\x01\x02\x03')
    read_ncstream_messages(f)

    log.handlers.pop()

    # Make sure we got some error output
    err_out.seek(0)
    assert 'Unknown magic' in err_out.read()
Example #4
0
def test_bad_magic(caplog):
    """Test that we get notified of bad magic bytes in stream."""
    # Try reading a bad message
    f = BytesIO(b'\x00\x01\x02\x03')
    read_ncstream_messages(f)

    assert 'Unknown magic' in caplog.text
Example #5
0
def test_local_data():
    """Test reading ncstream messages directly from bytes in a file-like object."""
    f = BytesIO(b'\xab\xec\xce\xba\x17\n\x0breftime_ISO\x10\x07\x1a\x04\n'
                b'\x02\x10\x01(\x02\x01\x142014-10-28T21:00:00Z')
    messages = read_ncstream_messages(f)
    assert len(messages) == 1
    assert messages[0][0] == '2014-10-28T21:00:00Z'
Example #6
0
def test_local_data():
    'Test reading ncstream messages directly from bytes in a file-like object'
    f = BytesIO(b'\xab\xec\xce\xba\x17\n\x0breftime_ISO\x10\x07\x1a\x04\n'
                b'\x02\x10\x01(\x02\x01\x142014-10-28T21:00:00Z')
    messages = read_ncstream_messages(f)
    assert len(messages) == 1
    assert messages[0][0] == '2014-10-28T21:00:00Z'
Example #7
0
def test_header_message_def():
    'Test parsing of Header message'
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    assert len(messages) == 1
    assert isinstance(messages[0], Header)
    head = messages[0]
    assert head.location == ('http://thredds-test.unidata.ucar.edu/thredds/cdmremote/grib/'
                             'NCEP/RAP/CONUS_13km/RR_CONUS_13km_20150519_0300.grib2')
    assert head.title == ''
    assert head.id == ''
    assert head.version == 1
Example #8
0
def test_header_message_def():
    'Test parsing of Header message'
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    assert len(messages) == 1
    assert isinstance(messages[0], Header)
    head = messages[0]
    assert head.location == ('http://thredds-test.unidata.ucar.edu/thredds/cdmremote/grib/'
                             'NCEP/RAP/CONUS_13km/RR_CONUS_13km_20150519_0300.grib2')
    assert head.title == ''
    assert head.id == ''
    assert head.version == 1
Example #9
0
def test_remote_header():
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    assert isinstance(messages[0], Header)

    head = messages[0]
    # make sure fields in the message are set to non-default values
    #  when HasField returns True
    for field in head.ListFields():
        fname = field[0].name
        if not fname == "root":
            test = eval("head.{} == HEAD_{}_DEFAULT".format(fname, fname.upper()))
            assert eval("[{}, not {}][head.HasField('{}')]".format(test, test, fname))
Example #10
0
def test_header_message_def():
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    assert isinstance(messages[0], Header)
    head = messages[0]
    # test that the header message definition has not changed!
    test = head.location == HEAD_LOCATION_DEFAULT
    assert [test, not test][head.HasField("location")]
    test = head.title == HEAD_TITLE_DEFAULT
    assert [test, not test][head.HasField("title")]
    test = head.title == HEAD_ID_DEFAULT
    assert [test, not test][head.HasField("id")]
    test = head.title == HEAD_VERSION_DEFAULT
    assert [test, not test][head.HasField("version")]
Example #11
0
def test_header_message_def():
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    assert isinstance(messages[0], Header)
    head = messages[0]
    # test that the header message definition has not changed!
    test = head.location == HEAD_LOCATION_DEFAULT
    assert [test, not test][head.HasField("location")]
    test = head.title == HEAD_TITLE_DEFAULT
    assert [test, not test][head.HasField("title")]
    test = head.title == HEAD_ID_DEFAULT
    assert [test, not test][head.HasField("id")]
    test = head.title == HEAD_VERSION_DEFAULT
    assert [test, not test][head.HasField("version")]
Example #12
0
def test_remote_header():
    f = get_header_remote()
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    assert isinstance(messages[0], Header)

    head = messages[0]
    # make sure fields in the message are set to non-default values
    #  when HasField returns True
    for field in head.ListFields():
        fname = field[0].name
        if not fname == "root":
            test = eval("head.{} == HEAD_{}_DEFAULT".format(
                fname, fname.upper()))
            assert eval("[{}, not {}][head.HasField('{}')]".format(
                test, test, fname))
Example #13
0
def test_local_data():
    f = BytesIO(b'\xab\xec\xce\xba\x17\n\x0breftime_ISO\x10\x07\x1a\x04\n'
                b'\x02\x10\x01(\x02\x01\x142014-10-28T21:00:00Z')
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    eq_(messages[0][0], b'2014-10-28T21:00:00Z')
Example #14
0
def test_local_data():
    f = BytesIO(b'\xab\xec\xce\xba\x17\n\x0breftime_ISO\x10\x07\x1a\x04\n'
                b'\x02\x10\x01(\x02\x01\x142014-10-28T21:00:00Z')
    messages = read_ncstream_messages(f)
    eq_(len(messages), 1)
    eq_(messages[0][0], b'2014-10-28T21:00:00Z')