Exemplo n.º 1
0
def test_log_setter_metadata():
    log = divelog.Log()
    log.metadata = {'a': 1}
    assert 'a' in log.metadata
    assert log.metadata['a'] == 1
    with pytest.raises(ValueError):
        log.metadata = ()
Exemplo n.º 2
0
def create_log(add_dives=True):
    log = divelog.Log()
    log.computer_model = 'Mares Sport'
    log.computer_serial = '8762-3478-6234'
    if add_dives:
        log.dives.append(create_dive(True))
    return log
Exemplo n.º 3
0
def test_log_slots():
    slots = ['metadata', 'created', 'computer_model', 'computer_serial',
             'depth_unit', 'depth_pressure_unit', 'altitude_unit',
             'temperature_unit', 'tank_pressure_unit', 'tank_volume_unit',
             'dives']
    log = divelog.Log()
    for slot in slots:
        assert slot in dir(log)
    for slot in dir(log):
        if not slot[0:2] == '__':
            assert slot in slots
Exemplo n.º 4
0
def test_log_setter_created():
    log = divelog.Log()
    #   format:    YYYYMMDDhhmmss.s
    log.created = '20160518083029.2'
    assert log.created.year == 2016
    assert log.created.month == 5
    assert log.created.day == 18
    assert log.created.hour == 8
    assert log.created.minute == 30
    assert log.created.second == 29
    assert log.created.microsecond == 200000
    with pytest.raises(ValueError):
        log.created = 'April 1st'
    log.created = datetime.datetime.now()
Exemplo n.º 5
0
def parse(file):
    """
    Parse this file object and return either a new top-level Log
    object, or None.
    """
    def copy_obj(src, tgt, ignore):
        for key in src:
            if not key == ignore:
                setattr(tgt, key, src[key])
    log = divelog.Log()
    jobj = json.load(file)
    copy_obj(jobj, log, 'dives')
    for jdive in jobj['dives']:
        dive = divelog.Dive()
        log.dives.append(dive)
        copy_obj(jdive, dive, 'record')
        for jdet in jdive['record']:
            detail = divelog.DiveDetail()
            dive.record.append(detail)
            copy_obj(jdet, detail, None)
    return log
Exemplo n.º 6
0
def test_log_setter_errors():
    log = divelog.Log()
    time = log.created
    with pytest.raises(ValueError):
        log.created = {'msg': 'this is not a date'}
    assert log.created == time
    with pytest.raises(ValueError):
        log.depth_unit = 'lightyear'
    assert log.depth_unit == 'M'
    with pytest.raises(ValueError):
        log.depth_pressure_unit = 'lightyear'
    assert log.depth_pressure_unit == 'MSWG'
    with pytest.raises(ValueError):
        log.altitude_unit = 'lightyear'
    assert log.altitude_unit == 'ThM'
    with pytest.raises(ValueError):
        log.temperature_unit = 'lightyear'
    assert log.temperature_unit == 'C'
    with pytest.raises(ValueError):
        log.tank_pressure_unit = 'lightyear'
    assert log.tank_pressure_unit == 'bar'
    with pytest.raises(ValueError):
        log.tank_volume_unit = 'lightyear'
    assert log.tank_volume_unit == 'L'
Exemplo n.º 7
0
def test_log_setter_unknown():
    log = divelog.Log()
    assert ('computer_color' not in dir(log))
    with pytest.raises(AttributeError):
        log.computer_color = 'red'
    assert ('computer_color' not in dir(log))
Exemplo n.º 8
0
def test_log_setter_dives():
    log = divelog.Log()
    log.dives = [divelog.Dive()]
    assert len(log.dives) == 1
    with pytest.raises(ValueError):
        log.dives = {}
Exemplo n.º 9
0
def test_log_setter():
    log = divelog.Log()
    assert log.depth_pressure_unit == 'MSWG'
    for unit in divelog.NMRI_PRESSURE_CODE:
        log.depth_pressure_unit = unit
        assert log.depth_pressure_unit == unit