Beispiel #1
0
def test_Dataset_write(tmpdir):
    ds = StructureDataset.from_metadata(str(tmpdir))
    ds.write(ValueTable=[])
    assert (tmpdir / 'values.csv').exists()
    ds.validate()
    ds.add_sources("@misc{ky,\ntitle={the title}\n}")
    ds.write(ValueTable=[{
        'ID': '1',
        'Language_ID': 'abcd1234',
        'Parameter_ID': 'f1',
        'Value': 'yes',
        'Source': ['key[1-20]', 'ky'],
    }])
    ds2 = StructureDataset.from_metadata(
        str(tmpdir.join('StructureDataset-metadata.json')))
    assert ds2['ValueTable'].common_props['dc:extent'] == 1
    assert {s[1]: s[2] for s in ds.stats()}['ValueTable'] == 1
    ds['ValueTable'].common_props['dc:extent'] = 3
    assert {s[1]: s[2] for s in ds.stats()}['ValueTable'] == 3
    with pytest.raises(ValueError):
        ds.validate()
    ds.sources.add("@misc{key,\ntitle={the title}\n}")
    ds.write(ValueTable=({
        'ID': '1',
        'Language_ID': 'abcd1234',
        'Parameter_ID': 'f1',
        'Value': 'yes',
        'Source': ['key[1-20]'],
    } for _ in range(1)))
    ds.validate()
    ds.add_component('ExampleTable')
    ds.write(ValueTable=[{
        'ID': '1',
        'Language_ID': 'abcd1234',
        'Parameter_ID': 'f1',
        'Value': 'yes',
        'Source': ['key[1-20]'],
    }],
             ExampleTable=[{
                 'ID': '1',
                 'Language_ID': 'abcd1234',
                 'Primary': 'si',
                 'Translation': 'yes',
                 'Analyzed': ['morph1', 'morph2', 'morph3'],
                 'Gloss': ['gl1', 'gl2'],
             }])
    with pytest.raises(ValueError):
        ds.validate()
    ds['ExampleTable'].write([{
        'ID': '1',
        'Language_ID': 'abcd1234',
        'Primary_Text': 'si',
        'Translated_Text': 'yes',
        'Analyzed_Word': ['morph1', 'morph2', 'morph3'],
        'Gloss': ['gl1', 'gl2', 'gl3'],
    }])
    ds.validate()
Beispiel #2
0
def test_Dataset_validate_missing_table(tmpdir, mocker):
    ds = StructureDataset.from_metadata(str(tmpdir))
    ds.tablegroup.tables = []
    ds.write()
    log = mocker.Mock()
    ds.validate(log=log)
    assert log.warn.called
Beispiel #3
0
def test_Dataset_validate_missing_table(tmpdir, mocker):
    ds = StructureDataset.from_metadata(str(tmpdir))
    ds.tablegroup.tables = []
    ds.write()
    log = mocker.Mock()
    ds.validate(log=log)
    assert log.warn.called
Beispiel #4
0
def test_Dataset_write(tmpdir):
    ds = StructureDataset.from_metadata(str(tmpdir))
    ds.write(ValueTable=[])
    assert (tmpdir / 'values.csv').exists()
    ds.validate()
    ds.add_sources("@misc{ky,\ntitle={the title}\n}")
    ds.write(ValueTable=[
        {
            'ID': '1',
            'Language_ID': 'abcd1234',
            'Parameter_ID': 'f1',
            'Value': 'yes',
            'Source': ['key[1-20]', 'ky'],
        }])
    ds2 = StructureDataset.from_metadata(
        str(tmpdir.join('StructureDataset-metadata.json')))
    assert ds2['ValueTable'].common_props['dc:extent'] == 1
    assert {s[1]: s[2] for s in ds.stats()}['ValueTable'] == 1
    ds['ValueTable'].common_props['dc:extent'] = 3
    assert {s[1]: s[2] for s in ds.stats()}['ValueTable'] == 3
    with pytest.raises(ValueError):
        ds.validate()
    ds.sources.add("@misc{key,\ntitle={the title}\n}")
    ds.write(ValueTable=(
        {
            'ID': '1',
            'Language_ID': 'abcd1234',
            'Parameter_ID': 'f1',
            'Value': 'yes',
            'Source': ['key[1-20]'],
        } for _ in range(1)))
    ds.validate()
    ds.add_component('ExampleTable')
    ds.write(
        ValueTable=[
            {
                'ID': '1',
                'Language_ID': 'abcd1234',
                'Parameter_ID': 'f1',
                'Value': 'yes',
                'Source': ['key[1-20]'],
            }],
        ExampleTable=[
            {
                'ID': '1',
                'Language_ID': 'abcd1234',
                'Primary': 'si',
                'Translation': 'yes',
                'Analyzed': ['morph1', 'morph2', 'morph3'],
                'Gloss': ['gl1', 'gl2'],
            }])
    with pytest.raises(ValueError):
        ds.validate()
    ds['ExampleTable'].write([
        {
            'ID': '1',
            'Language_ID': 'abcd1234',
            'Primary_Text': 'si',
            'Translated_Text': 'yes',
            'Analyzed_Word': ['morph1', 'morph2', 'morph3'],
            'Gloss': ['gl1', 'gl2', 'gl3'],
        }])
    ds.validate()