Esempio n. 1
0
def test_if():
    """Test IFs statements and boolean functions"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('if p(v26) then v26^a fi', 'Paris'),
        ('if p(v25) then v26^a fi', ''),
        ('if p(v26) then v26^a else v26^b fi', 'Paris'),
        ('if p(v25) then v26^a else v26^b fi', 'Unesco'),
        ('if a(v26) then v26^a fi', ''),
        ('if a(v25) then v26^a fi', 'Paris'),
        ('if a(v26) then v26^a else v26^b fi', 'Unesco'),
        ('if a(v25) then v26^a else v26^b fi', 'Paris'),
        ('if p(v26) then v26^a fi', 'Paris'),
        ('if p(v26) then v26^a,v26^b fi', 'ParisUnesco'),
        ('if p(v26) then v26^a v26^b fi', 'ParisUnesco'),
        # field expression
        ("if v26>'' then v26^a fi", 'Paris'),
        ("if v50:'bib' then v26^a fi", 'Paris'),
        # test for heading and trailing spaces
        ("if 1=1 then 'ok' fi ", "ok"),
        ("  if 1=1 then 'ok' fi", "ok"),
        ("   if 1=1 then 'ok' fi   ", "ok"),
        ("if nocc(v70)=2 then 'OK' else 'NOK' fi", "OK"),
    )
    run_list(expr_list, record)
Esempio n. 2
0
def test_repeatable_literals():
    """Test repeatable literals"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('|Do not show|v1', ''),
        ('|Show|v26', 'Show^aParis^bUnesco^c-1965'),
        ('mpu,|Show|v26^a', 'SHOWPARIS'),
        ('v1|Do not show|', ''),
        ('v26|Show|', '^aParis^bUnesco^c-1965Show'),
        ('|Do not show|v26^z', ''),
        ('|Show|v26^a', 'ShowParis'),
        ('v26^z|Do not show|', ''),
        ('v26^b|Show|', 'UnescoShow'),
        ('| Author:|v70', ' Author:Magalhaes, A.C. Author:Franco, C.M.'),
        ('| Author:|+v70', 'Magalhaes, A.C. Author:Franco, C.M.'),
        ('|<Left> |v70| <Right>|',
         u'<Left> Magalhaes, A.C. <Right><Left> Franco, C.M. <Right>'),
        ('|<Left> |+v70| <Right>|',
         u'Magalhaes, A.C. <Right><Left> Franco, C.M. <Right>'),
        ('|<Left> |v70+| <Right>|',
         u'<Left> Magalhaes, A.C. <Right><Left> Franco, C.M.'),
        ('|<Left> |+v70+| <Right>|',
         u'Magalhaes, A.C. <Right><Left> Franco, C.M.'),
        ('|Show |v26^a|; |/', 'Show Paris; \n'),
        ('|Show |+v26^a|; |/', 'Paris; \n'),
        ('|Show |v26^a+|; |/', 'Show Paris\n'),
        ('|Show |+v26^a+|; |/', 'Paris\n'),
        ('|Show |v26^a(5,5)|; |/', '     Show Paris; \n'),
        ('|Show |+v26^a(5,5)|; |/', '     Paris; \n'),
        ('|<antes>|+v70,|meio|+v26+|depois|/',
         'Magalhaes, A.C.<antes>Franco, C.M.^aParis^bUnesco^c-1965\n'),
    )
    run_list(expr_list, record)
Esempio n. 3
0
def test_spacing():
    """Test for vertical spacing commands: # / %"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('v26^b v26^a', 'UnescoParis'),
        ('v26^b  v26^a', 'UnescoParis'),
        ('v26^b/v26^a', 'Unesco\nParis'),
        ('v26^b///v26^a', 'Unesco\nParis'),
        ('v26^b#v26^a', 'Unesco\nParis'),
        ('v26^b/#v26^a', 'Unesco\n\nParis'),
        ('v26^b##v26^a', 'Unesco\n\nParis'),
        ('v26^b###%v26^a', 'Unesco\nParis'),
        ('v26^bx10v26^a', 'Unesco          Paris'),
        ('v26^bX10v26^a', 'Unesco          Paris'),
        ('v26^bX100v26^a', "Unesco\nParis"),
        ('v26^bC0v26^a', "Unesco\nParis"),
        ("v26^bC7v26^a", "UnescoParis"),
        ("v26^bC8v26^a", "Unesco Paris"),
        # ignore tabulation that exceeds MAX_WIDTH
        ("v26^bC120v26^a", "UnescoParis"),
        ("v26^bC5v26^a", "Unesco\n    Paris"),
        ("### X3 v26^b", "\n\n\n   Unesco"),
        ("###,X3,v26^b", "\n\n\n   Unesco"),
        ("v26^a#", "Paris\n"),
        ("v26^a///", "Paris\n"),
        ("v26^a#", "Paris\n"),
        ("v26^a%##v26^b%##v26^c", "Paris\nUnesco\n\n-1965"),
    )
    run_list(expr_list, record)
Esempio n. 4
0
def test_max_width():
    """Test max width and field alignment"""
    record = MasterRecord()
    record.update(test_data)
    # Fake config and change default param MAX_LINE_WIDTH
    record.mst = Lyer()
    record.mst.config.INPUT_ENCODING = 'utf-8'
    record.mst.config.OUTPUT_ENCODING = 'utf-8'
    record.mst.config.MAX_LINE_WIDTH = 40
    record.mst.config.YACC_DEBUG = False
    expr_list = (
        ("v44",
         'Methodology of plant eco-physiology: \nproceedings of the Montpellier \nSymposium'
         ),
        ("v44(0,0)",
         'Methodology of plant eco-physiology: \nproceedings of the Montpellier \nSymposium'
         ),
        ("v44(10)",
         '          Methodology of plant \neco-physiology: proceedings of the \nMontpellier Symposium'
         ),
        ("v44(0,5)",
         'Methodology of plant eco-physiology: \n     proceedings of the Montpellier \n     Symposium'
         ),
        ("v44(10,5)",
         '          Methodology of plant \n     eco-physiology: proceedings of the \n     Montpellier Symposium'
         ),
        # special case of unbreakable line
        ("'%s'" % ('a' * 120),
         u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
         ),
    )
    run_list(expr_list, record)
Esempio n. 5
0
def test_update_flags():
    """Test update flags (xrf and master files)"""

    xref_fd = join('fixtures', 'testflag.xrf')
    db_fd = join('fixtures', 'testflag.mst')

    if exists(xref_fd):
        remove(xref_fd)
    if exists(db_fd):
        remove(db_fd)

    dbtest = MasterFile(db_fd)
    rec = MasterRecord()
    rec.update(test_data)
    rec.save(dbtest)

    xrf_rec = dbtest.xrf[1]
    assert xrf_rec.status == 'active'
    assert xrf_rec.status == 'active'
    assert xrf_rec.new_flag == True
    assert xrf_rec.modified_flag == False

    rec = dbtest[1]
    rec[27] = 'Test new field'
    rec.save(dbtest)

    assert xrf_rec.new_flag == False
    assert xrf_rec.modified_flag == True

    dbtest.invertdb(expr='70 0 MHU,(V70/)')

    assert xrf_rec.new_flag == False
    assert xrf_rec.modified_flag == False
Esempio n. 6
0
def test_boolean_expr():
    """Test Boolean expressions"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ("1<>2", "True"),
        ("1=2", "False"),
        ("1>2", "False"),
        ("1 > 2", "False"),
        ("1> 2", "False"),
        ("1 >2", "False"),
        ("1<2", "True"),
        ("1>=2", "False"),
        ("2>=1", "True"),
        ("2<=1", "False"),
        ("2>=1", "True"),
        ("1 > 2", "False"),
        ("1>2 or 2>1", "True"),
        ("1>2 and 2>1", "False"),
        ("1<2 or 2>1", "True"),
        ("1<2 and 2>1", "True"),
        ("1<2 xor 2>1", "False"),
        ("1>2 xor 2>1", "True"),
        ("not 1<2", "False"),
        ("not (1<2)", "False"),
    )
    run_list(expr_list, record)
Esempio n. 7
0
def test_singlerecord_master():
    """Create a MasterFile with a single record inside"""
    clean_start()
    mf = MasterFile(testmst)
    rec = MasterRecord()
    rec.update(test_data)
    rec.save(mf)
    del mf  # force flush
Esempio n. 8
0
def test_first_subfield_default():
    """Test sub-field acessor ^* in field without subfields"""
    record = MasterRecord()
    record.update(test_data)
    first_subfield = format("v50^*", record)
    assert first_subfield == 'Incl. bibl.', 'Failed to extract first subfield'
    record.v13 = "First ^ok"
    assert format(
        "v13^*", record) == 'First ', 'Failed during first subfield extraction'
Esempio n. 9
0
def test_delete_record():
    """Create 3 records and delete the one in the middle"""
    clean_start()
    size = 3
    mf = MasterFile(testmst)
    for i in range(size):
        rec = MasterRecord()
        rec.update(test_data)
        rec.update({131: "flag %d" % i})
        rec.save(mf)
    mf.delete(2)
Esempio n. 10
0
def test_boolean_functions():
    """Test boolean evaluation functions P() and A()"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('p(v26)', 'True'),
        ('a(v26)', 'False'),
        ('P(v26)', 'True'),
        ('A(v26)', 'False'),
    )
    run_list(expr_list, record)
Esempio n. 11
0
def test_update():
    """Create a record, modify it and save it and check previous"""
    clean_start()
    mf = MasterFile(testmst)
    r = MasterRecord()
    r.update(test_data)
    r.save(mf)
    r[90] = "This is a new field"
    r.save(mf)
    prev = mf.previous(r)
    assert prev is not None
    assert len(prev) + 1 == len(r)
Esempio n. 12
0
def test_field_expressions():
    """Test field access expressions"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ("v30^a,v30^b", 'p. 211-224illus.'),
        ("v26^a", 'Paris'),
        ("v26^a*2", 'ris'),
        ("v26^a.2", 'Pa'),
        ("v26^a*1.3", 'ari'),
    )
    run_list(expr_list, record)
Esempio n. 13
0
def test_write_multiple_records():
    """Write multiple records in a newly created database."""
    clean_start()
    size = 381
    mf = MasterFile(testmst)
    for i in range(size):
        rec = MasterRecord()
        rec.update(test_data)
        rec.save(mf)
    mf.commit()
    assert len(mf) == size
    assert mf[90].v50.data == 'Incl. bibl.'
    del mf
Esempio n. 14
0
def test_numerical_expr():
    """Test Numerical expressions"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('0.155e+3', '155.0'),
        ('1e-3', '0.001'),
        ('2*3+9', '15'),
        ("2*(3+9)", '24'),
        ("10-(4*(2-1))", "6"),
        ("15*0.001", "0.015"),
    )
    run_list(expr_list, record)
Esempio n. 15
0
def test_unconditional_literals():
    """Test unconditional literals"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ("v30^a,' Belex ', v30^b", 'p. 211-224 Belex illus.'),
        ("v26^a,' Belex'", 'Paris Belex'),
        ("'Belex'", 'Belex'),
        ("mpu,'Belex'", 'BELEX'),
        ("'Belex ',v26^a", "Belex Paris"),
        ("'Belex 'v26^a", "Belex Paris"),
        ("v26^a' Belex'", "Paris Belex"),
        ("'Be''lex'", "Belex"),
    )
    run_list(expr_list, record)
Esempio n. 16
0
def test_strfuncs():
    record = MasterRecord(mfn=1)
    record.update(test_data)

    if platform == 'linux2':
        value = '1.131400E+00'
    else:
        value = '1.131400E+000'

    expr_list = (
        ("f(1.1314,2)", value),
        ("f(3.1415,10,5)", '   3.14150'),
        ("f(1.1314,3,0)", '  1'),
        ("s('Pa','ris')", 'Paris'),
        ("s(mfn,v26)", '000001^aParis^bUnesco^c-1965'),
    )
    run_list(expr_list, record)
Esempio n. 17
0
def test_undelete():
    """Create a record and undelete it"""
    clean_start()
    mf = MasterFile(testmst)
    r = MasterRecord()
    r.update(test_data)
    r.save(mf)
    mf.delete(1)
    mf.commit()
    r = mf[1]
    assert r.status == LOGICALLY_DELETED
    assert mf.xrf[1].status == 'logically deleted'
    assert len(mf) == 0
    mf.undelete(1)
    r = mf[1]
    assert r.status == ACTIVE
    assert mf.xrf[1].status == 'active'
    assert len(mf) == 1
Esempio n. 18
0
def test_restore_previous():
    """Create a record, modify it, save it and restore previous version"""
    clean_start()
    mf = MasterFile(testmst)
    r = MasterRecord()
    r.update(test_data)
    r.save(mf)
    r[90] = "This is a new field"
    r.save(mf)
    prev = mf.previous(r)
    prev.save(mf)
    old_r = mf[1]
    try:
        old_r[90]
        assert False, "Field with tag 90 should not exist anymore."
    except KeyError:
        pass
    assert r.status == ACTIVE
    assert len(old_r) == len(prev)
Esempio n. 19
0
def test_conditional_literals():
    """Test conditional literals"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('"Do not show"v1', ''),
        ('"Show"v26', 'Show^aParis^bUnesco^c-1965'),
        ('mpu,"Show"v26', 'SHOW^APARIS^BUNESCO^C-1965'),
        ('v1"Do not show"', ''),
        ('v26"Show"', '^aParis^bUnesco^c-1965Show'),
        ('"Do not show"v26^z', ''),
        ('"Show"v26^a', 'ShowParis'),
        ('v26^z"Do not show"', ''),
        ('v26^b"Show"', 'UnescoShow'),
        ('"Authors:"v70', 'Authors:Magalhaes, A.C.Franco, C.M.'),
        ('v70" (authors)"', 'Magalhaes, A.C.Franco, C.M. (authors)'),
        ('"->"x3v26', '->   ^aParis^bUnesco^c-1965'),
    )
    run_list(expr_list, record)
Esempio n. 20
0
def test_max_width_off():
    """Test max width==0 and field alignment"""
    record = MasterRecord()
    record.update(test_data)
    # Fake config and change default param MAX_LINE_WIDTH
    record.mst = Lyer()
    record.mst.config.INPUT_ENCODING = 'utf-8'
    record.mst.config.OUTPUT_ENCODING = 'utf-8'
    record.mst.config.MAX_LINE_WIDTH = 0
    record.mst.config.YACC_DEBUG = False
    expr_list = (
        ("v44",
         '\nMethodology of plant eco-physiology: proceedings of the Montpellier Symposium'
         ),
        ("v44(0,0)", ''),
        ("v44(10)", ''),
        ("v44(0,5)", ''),
        ("v44(10,5)", ''),
    )
    run_list(expr_list, record)
Esempio n. 21
0
def test_numfunc():
    """Test Numerical functions"""
    record = MasterRecord()
    record.update(test_data)
    record.v13 = ["a 10", "b 20", "c 30"]
    expr_list = (
        ('val(26)', '26'),
        ('val(v26)', '-1965'),
        ('val(V26)', '-1965'),
        ("v26^c*1", '1965'),
        ("val('xxxx7yyyy8zzzz')", "7"),
        ("val('water')", "0"),
        ("val(10)*val(2)", "20"),
        ("val('10')*val('2')", "20"),
        ("val('dfsdf sdfsdf sdfsdfds')=0", "True"),
        ("val('dfsdf sdfsdf sdfsdfds')", "0"),
        ("val(v26)/10*-1", "196.5"),
        ("val(val(1))", "1"),
        ("val(-1)", "-1"),
        ("rsum(10,20,30)", "60"),
        ("rmax(10,20,30)", "30"),
        ("rmin(10,20,30)", "10"),
        ("ravr(10,20,30)", "20"),
        ("RSUM(10,20,30)", "60"),
        ("RMAX(10,20,30)", "30"),
        ("RMIN(10,20,30)", "10"),
        ("RAVR(10,20,30)", "20"),
        ("rsum('10')", "10"),
        ("rsum(10)", "10"),
        ("rsum('10,20,30')", "60"),
        ("rsum('a,10,b,20,c,30')", "60"),
        ("rsum(v26)", "-1965"),
        ("rsum(v26,1965)", "0"),
        ("rsum(v70)", "0"),
        ("rsum(v13)", "60"),
        ("rmax(v13)", "30"),
        ("rmin(v13)", "10"),
        ("ravr(v13)", "20"),
        ("rsum(v30)", "-13"),
    )
    run_list(expr_list, record)
Esempio n. 22
0
def test_dummy_field():
    """Test Dummy field constructs Dt, Dt^x, Nt, Nt^x"""
    record = MasterRecord()
    record.update(test_data)
    expr_list = (
        ('"Ola:"V26^a', 'Ola:Paris'),
        ('"Ola:"D26^a', 'Ola:'),
        ('"Ola:"N26^a', ''),
        ('"Ola:"D23^a', ''),
        ('"Ola:"N23^a', 'Ola:'),
        ('"Ola:"v26^a', 'Ola:Paris'),
        ('"Ola:"d26^a', 'Ola:'),
        ('"Ola:"n26^a', ''),
        ('"Ola:"d23^a', ''),
        ('"Ola:"n23^a', 'Ola:'),
        ('"Ola:"v26', 'Ola:^aParis^bUnesco^c-1965'),
        ('"Ola:"d26', 'Ola:'),
        ('"Ola:"n26', ''),
        ('"Ola:"d23', ''),
        ('"Ola:"n23', 'Ola:'),
    )
    run_list(expr_list, record)
Esempio n. 23
0
def test_update_flagsFFI():
    """Test update flags (xrf and master files - FFI)"""

    xref_fd = join('fixtures', 'testflag.xrf')
    db_fd = join('fixtures', 'testflag.mst')
    ini_fd = join('fixtures', 'testflag.ini')

    if exists(xref_fd):
        remove(xref_fd)
    if exists(db_fd):
        remove(db_fd)

    f = open(ini_fd, "w")
    f.write(
        "[Engine]\nINPUT_ENCODING = cp850\nOUTPUT_ENCODING = utf-8\n[IsisDB]\nLEADER_XL=True"
    )
    f.write("\nDIR_MASK = iii\nLEADER_MASK_XL = iiHHiiHH")
    f.close()

    dbtest = MasterFile(db_fd)
    rec = MasterRecord()
    rec.update(test_data)
    rec.save(dbtest)

    rec = dbtest[1]
    xrf_rec = dbtest.xrf[1]
    assert xrf_rec.status == 'active'
    assert xrf_rec.new_flag == True
    assert xrf_rec.modified_flag == False

    assert rec.mfbwb == 0
    assert rec.mfbwp == 0

    rec = dbtest[1]
    rec[27] = 'Test new field'
    rec.save(dbtest)

    rec = dbtest[1]
    xrf_rec = dbtest.xrf[1]
    assert xrf_rec.new_flag == True
    assert xrf_rec.modified_flag == False

    assert rec.mfbwb == 0
    assert rec.mfbwp == 0

    dbtest.invertdb(expr='70 0 MHU,(V70/)')

    rec = dbtest[1]
    xrf_rec = dbtest.xrf[1]
    assert xrf_rec.new_flag == False
    assert xrf_rec.modified_flag == False

    assert rec.mfbwb == 0
    assert rec.mfbwp == 0

    rec[100] = 'new field 100'
    rec.save(dbtest)

    rec = dbtest[1]
    xrf_rec = dbtest.xrf[1]

    assert xrf_rec.new_flag == False
    assert xrf_rec.modified_flag == True

    assert rec.mfbwb > 0
    assert rec.mfbwp > 0

    dbtest.invertdb(expr='70 0 MHU,(V70/)')

    rec = dbtest[1]
    xrf_rec = dbtest.xrf[1]
    assert xrf_rec.new_flag == False
    assert xrf_rec.modified_flag == False

    assert rec.mfbwb == 0
    assert rec.mfbwp == 0
Esempio n. 24
0
def test_first_subfield():
    """Test sub-field acessor ^* in field with several subfields"""
    record = MasterRecord()
    record.update(test_data)
    first_subfield = format("v26^*", record)
    assert first_subfield == 'Paris', 'Failed to extract first subfield'