How to use clld - 10 common examples

To help you get started, we’ve selected a few clld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clld / clld / tests / test_web_util_multiselect.py View on Github external
def test_MultiSelect(env):
    from clld.web.util.multiselect import MultiSelect

    ms = MultiSelect(env['request'], common.Language, 'x', url='/')
    ms.render()
    ms.render(selected=[common.Language.first()])
    ms.format_result(common.Language(id='x'))
github clld / clld / tests / test_web_util_multiselect.py View on Github external
def test_MultiSelect(env):
    from clld.web.util.multiselect import MultiSelect

    ms = MultiSelect(env['request'], common.Language, 'x', url='/')
    ms.render()
    ms.render(selected=[common.Language.first()])
    ms.format_result(common.Language(id='x'))
github clld / clld / tests / test_db_models.py View on Github external
def test_Data(db):
    from clld.db.models.common import Language, Language_data

    l = Language(id='abc', name='Name')
    l.data.append(Language_data(key='abstract', value='c'))
    DBSession.add(l)
    DBSession.flush()
    DBSession.refresh(l)
    assert l.datadict()['abstract'] == 'c'
github clld / clld / tests / test_db_meta.py View on Github external
def test_Base_jsondata(db):
    l = Language(id='abc', name='Name')
    VersionedDBSession.add(l)
    VersionedDBSession.flush()
    l.update_jsondata(a=1)
    assert 'a' in l.jsondata
    l.update_jsondata(b=1)
    assert 'b' in l.jsondata and 'a' in l.jsondata
    assert 'b' in l.__json__(None)['jsondata']
github clld / clld / tests / test_db_models.py View on Github external
def test_Language():
    from clld.db.models.common import Language

    d = Language(id='abc')
    assert d.glottocode is None
    assert d.iso_code is None
github clld / clld / tests / test_scripts_util.py View on Github external
def test_Data(mocker):
    from clld.db.models.common import Language
    from clld.scripts.util import Data

    session = set()
    mocker.patch('clld.scripts.util.DBSession', session)
    d = Data(jsondata={})
    d.add(Language, 'l', id='l', name='l')
    assert session
    d.add(Language, 'l2', _obj=5)
    with pytest.raises(ValueError):
        d.add(Language, 'l3', id='l.3')
github clld / clld / tests / test_db_util.py View on Github external
def test_compute_language_sources(data):
    from clld.db.util import compute_language_sources
    from clld.db.models.common import Source, Sentence, Language, SentenceReference
    from clld.db.meta import DBSession

    s = Sentence(id='sentenced', language=Language(id='newlang'))
    sr = SentenceReference(sentence=s, source=Source.first())
    DBSession.add(sr)
    DBSession.flush()
    compute_language_sources()
github clld / clld / tests / test_web_adapters_cldf.py View on Github external
def test_source2source(env):
    from clld.web.adapters.cldf import source2source

    for source in DBSession.query(Source):
        res = source2source(env['request'], source)
        assert len(res) >= 1
github clld / clld / tests / test_db_meta.py View on Github external
def test_CsvMixin(db):
    l1 = Language(id='abc', name='Name', latitude=12.4, jsondata=dict(a=None))
    DBSession.add(l1)
    DBSession.flush()
    l1 = Language.csv_query(DBSession).first()
    cols = l1.csv_head()
    row = l1.to_csv()
    for k, v in zip(cols, row):
        if k == 'jsondata':
            assert 'a' in json.loads(v)
    l2 = Language.from_csv(row)
    assert pytest.approx(l1.latitude) == l2.latitude
    row[cols.index('latitude')] = '3,5'
    l2 = Language.from_csv(row)
    assert l2.latitude < l1.latitude
github clld / glottolog3 / tests / test_cli.py View on Github external
def testdb(mocker):
    subprocess.check_call(['dropdb', '-U', 'postgres', '--if-exists', TEST_DB])
    subprocess.check_call(['createdb', '-U', 'postgres', TEST_DB])
    engine = create_engine('postgresql://postgres@/' + TEST_DB)
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    mocker.patch('glottolog3.__main__.db_url', mocker.Mock(return_value=engine.url))
    mocker.patch('glottolog3.__main__.with_session')

    yield DBSession
    DBSession.close_all()
    DBSession.remove()
    engine.dispose()
    subprocess.check_call(['dropdb', '-U', 'postgres', '--if-exists', TEST_DB])