Esempio n. 1
0
def test_definesdb_should_not_create_a_db_file_when_only_reading():
    db = DefinesDB()

    db.clear()
    assert not file_exists(DBNAME)

    assert db.get('some-key', None) is None
    assert not file_exists(DBNAME)
Esempio n. 2
0
def test_definesdb_clear_removes_all_keys():
    db = DefinesDB()
    db.open()
    db.update({'KEY1': 'VALUE1'})

    db.clear()

    assert 'KEY1' not in db

    db.close()
Esempio n. 3
0
def test_process_include_file_should_not_load_database_keys_into_instance_defines_dictionary(
):
    db = DefinesDB()
    db.clear()

    p = Preprocessor()
    p.use_db(db)

    p.process_include_file(resolve_relative_path('fixtures/incl.h'))

    # a bit hackish to reference instance-internal state
    # but it's important to verify this, as we otherwise run out of memory on device
    assert 'CONST2' not in p._defines
Esempio n. 4
0
def test_preprocess_should_ensure_no_definesdb_is_created_when_only_reading_from_it(
):
    content = """\
    #define CONST 42
    move r1, CONST"""

    # remove any existing db
    db = DefinesDB()
    db.clear()
    assert not file_exists(DBNAME)

    # now preprocess using db
    p = Preprocessor()
    p.use_db(db)

    result = p.preprocess(content)

    assert "move r1, 42" in result

    assert not file_exists(DBNAME)
Esempio n. 5
0
def test_preprocess_should_use_definesdb_when_provided():
    p = Preprocessor()

    content = """\
#define LOCALCONST 42

entry:
    move r1, LOCALCONST
    move r2, DBKEY
"""

    # first try without db
    result = p.preprocess(content)

    assert "move r1, 42" in result
    assert "move r2, DBKEY" in result
    assert "move r2, 99" not in result

    # now try with db
    db = DefinesDB()
    db.clear()
    db.update({'DBKEY': '99'})
    p.use_db(db)

    result = p.preprocess(content)

    assert "move r1, 42" in result
    assert "move r2, 99" in result
    assert "move r2, DBKEY" not in result
Esempio n. 6
0
def test_process_include_file_using_database():
    db = DefinesDB()
    db.clear()

    p = Preprocessor()
    p.use_db(db)

    p.process_include_file(resolve_relative_path('fixtures/incl.h'))
    p.process_include_file(resolve_relative_path('fixtures/incl2.h'))

    assert db['CONST1'] == '42', "constant from incl.h"
    assert db['CONST2'] == '123', "constant overridden by incl2.h"
    assert db['CONST3'] == '777', "constant from incl2.h"

    db.close()
Esempio n. 7
0
def test_preprocess_should_ensure_the_definesdb_is_properly_closed_after_use():
    content = """\
    #define CONST 42
    move r1, CONST"""

    # remove any existing db
    db = DefinesDB()
    db.open()
    assert db.is_open()

    # now preprocess using db
    p = Preprocessor()
    p.use_db(db)

    p.preprocess(content)

    assert not db.is_open()
Esempio n. 8
0
def test_definesdb_persists_data_across_instantiations():
    db = DefinesDB()
    db.open()
    db.clear()

    db.update({'KEY1': 'VALUE1'})

    assert 'KEY1' in db

    db.close()
    del db
    db = DefinesDB()
    db.open()

    assert db.get('KEY1', None) == 'VALUE1'

    db.close()