示例#1
0
def test_get_time_value():
    'make sure get_time_value goes to correct C++ derived class function'
    shio = CyShioTime(shio_file)
    t = time_utils.date_to_sec(datetime(2012, 8, 20, 13))
    time = [t + 3600.*dt for dt in range(10)]
    vel_rec = shio.get_time_value(time)
    assert all(vel_rec['u'] != 0)
    assert all(vel_rec['v'] == 0)
示例#2
0
def test_exceptions():
    bad_file = os.path.join('./', 'CLISShio.txtX')
    bad_yeardata_path = os.path.join('./', 'Data', 'yeardata')
    with pytest.raises(IOError):
        CyShioTime(bad_file)

    with pytest.raises(IOError):
        shio = CyShioTime(shio_file)
        shio.set_shio_yeardata_path(bad_yeardata_path)
示例#3
0
def test_yeardata():
    shio = CyShioTime(shio_file)
    assert shio.yeardata == ''
    yd = os.path.join(os.path.dirname(gnome.__file__), 'data',
                      'yeardata')
    shio.yeardata = yd
    # shio puts a trailing slash at the end that is platform dependent
    # so compare the names without the platform dependent trailing slash
    assert shio.yeardata[:-1] == yd
示例#4
0
def test_yeardata():
    'test default yeardata is set correctly. Also test set function.'
    shio = CyShioTime(shio_file)

    yd = os.path.join(os.path.dirname(gnome.__file__), 'data', 'yeardata')
    # shio puts a trailing slash at the end that is platform dependent
    # so compare the names without the platform dependent trailing slash
    assert shio.yeardata[:-1] == yd

    # bogus path but we just want to test that it gets set
    shio.yeardata = yd
    assert shio.yeardata[:-1] == yd
示例#5
0
def test_properties_read_from_file():
    """ read only properties """

    shio = CyShioTime(shio_file)
    print shio.filename
    with open(shio_file) as fh:
        data = fh.read()

    for (item, prop) in check_items.iteritems():
        s_idx = data.find(item)
        e_idx = data.find('\n', s_idx)
        val = getattr(shio, prop)
        if item == 'Longitude=':
            assert round(val[0], 4) == round(float(data[s_idx +
                                                        len(item):e_idx]), 4)
        elif item == 'Latitude=':

            assert round(val[1], 4) == round(float(data[s_idx
                                                        + len(item):e_idx]), 4)
        else:

            assert val == data[s_idx + len(item):e_idx]

    assert not shio.daylight_savings_off
    assert shio.path_filename == shio_file
示例#6
0
    def _obj_to_create(self, filename):
        """
        open file, read a few lines to determine if it is an ossm file
        or a shio file
        """
        # mode 'U' means universal newline support
        fh = open(filename, 'rU')

        lines = [fh.readline() for i in range(4)]

        if len(lines[1]) == 0:
            # look for \r for lines instead of \n
            lines = string.split(lines[0], '\r', 4)

        if len(lines[1]) == 0:
            # if this is still 0, then throw an error!
            raise ValueError('This does not appear to be a valid file format '
                             'that can be read by OSSM or Shio to get '
                             'tide information')

        # look for following keywords to determine if it is a Shio or OSSM file
        shio_file = ['[StationInfo]', 'Type=', 'Name=', 'Latitude=']

        if all([shio_file[i] == (lines[i])[:len(shio_file[i])]
                for i in range(4)]):
            return CyShioTime(filename)
        elif len(string.split(lines[3], ',')) == 7:
            # maybe log / display a warning that v=0 for tide file and will be
            # ignored
            # if float( string.split(lines[3],',')[-1]) != 0.0:
            return CyTimeseries(filename, file_format=tsformat('uv'))
        else:
            raise ValueError('This does not appear to be a valid file format '
                             'that can be read by OSSM or Shio to get '
                             'tide information')
示例#7
0
def test_eq():
    shio = CyShioTime(shio_file)

    other_shio = CyShioTime(shio_file)
    assert shio == other_shio

    other_shio = CyShioTime(shio_file)
    other_shio.daylight_savings_off = True
    assert shio != other_shio

    other_shio = CyShioTime(shio_file)
    other_shio.scale_factor = 2
    assert shio != other_shio
示例#8
0
def test_eval_repr():
    print "in test_eval_repr: shio_file is:", shio_file
    shio = CyShioTime(shio_file)

    print "the repr is:", repr(shio)
    other_shio = eval(repr(shio))
    assert shio == other_shio

    yd = os.path.join(os.path.dirname(gnome.__file__), 'data', 'yeardata')
    shio.yeardata = yd
    other_shio = eval(repr(shio))
    assert shio == other_shio

    shio.daylight_savings_off = False
    other_shio = eval(repr(shio))
    assert shio == other_shio

    shio.scale_factor = 2
    other_shio = eval(repr(shio))
    assert shio == other_shio
def test_eq():
    shio = CyShioTime(shio_file)

    other_shio = CyShioTime(shio_file)
    assert shio == other_shio

    other_shio = CyShioTime(shio_file)
    other_shio.daylight_savings_off = True
    assert shio != other_shio

    other_shio = CyShioTime(shio_file)
    other_shio.scale_factor = 2
    assert shio != other_shio

    other_shio = CyShioTime(shio_file)
    yd = os.path.join(os.path.dirname(gnome.__file__), 'data', 'yeardata')
    other_shio.yeardata = yd
    assert shio != other_shio
示例#10
0
def test_scale_factor():
    shio = CyShioTime(shio_file)
    assert shio.scale_factor == 1
    shio.scale_factor = 2
    assert shio.scale_factor == 2
示例#11
0
def test_daylight_savings_off():
    shio = CyShioTime(shio_file)
    assert not shio.daylight_savings_off
    shio.daylight_savings_off = True
    assert shio.daylight_savings_off