Пример #1
0
def test_schema():
    simple_schema = Schema(test=TEXT, user=ID)
    names = simple_schema.names()
    items = simple_schema.items()

    assert len(simple_schema) == 2
    assert len(names) == 2
    assert 'test' in names
    assert 'user' in names
    assert len(items) == 2

    assert isinstance(simple_schema['test'], TEXT)
    assert isinstance(simple_schema['user'], ID)
    with pytest.raises(KeyError):
        simple_schema['no_item']

    for field in simple_schema:
        assert isinstance(field, FieldType)

    assert 'test' in simple_schema
    assert 'text' not in simple_schema

    with pytest.raises(FieldConfigurationError):
        simple_schema.add("_test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", object)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", str)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", IndexWriter)

    with pytest.raises(ValueError):
        NUMERIC(num_type=str)
    with pytest.raises(NotImplementedError):
        FieldType().equals('a', 'b')
    with pytest.raises(ValueError):
        list(NUMERIC().analyse('notanumber'))

    f = NUMERIC(num_type=float)
    assert f.equals('1', '1.0')

    dt = DATETIME(analyser=DateTimeAnalyser(datetime_formats=['HH:mm DD/MM/YYYY']))
    assert dt.value_of('10:05 01/12/2016') == '2016-12-01T10:05:00z'
    assert dt.equals('10:05 01/12/2016', '10:05 01/12/2016')
    assert dt.gt('10:06 01/12/2016', '10:05 01/12/2016')
    assert dt.gte('10:05 01/12/2016', '10:05 01/12/2016')
    assert dt.gte('10:05 02/12/2016', '10:05 01/12/2016')
    assert dt.lt('01:05 01/12/2016', '10:05 01/12/2016')
    assert dt.lte('10:05 01/12/2016', '10:05 01/12/2016')
    assert dt.lte('10:05 01/12/2015', '10:05 01/12/2016')

    assert list(BOOLEAN().analyse('1'))[0].value is True
Пример #2
0
def test_schema():
    simple_schema = Schema(test=TEXT, user=ID)
    names = simple_schema.names()
    items = simple_schema.items()

    assert len(simple_schema) == 2
    assert len(names) == 2
    assert "test" in names
    assert "user" in names
    assert len(items) == 2

    assert isinstance(simple_schema["test"], TEXT)
    assert isinstance(simple_schema["user"], ID)
    with pytest.raises(KeyError):
        simple_schema["no_item"]

    for field in simple_schema:
        assert isinstance(field, FieldType)

    assert "test" in simple_schema
    assert "text" not in simple_schema

    with pytest.raises(FieldConfigurationError):
        simple_schema.add("_test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("a test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", object)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", str)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", IndexWriter)

    with pytest.raises(ValueError):
        NUMERIC(num_type=str)
    with pytest.raises(NotImplementedError):
        FieldType().equals("a", "b")
    with pytest.raises(ValueError):
        list(NUMERIC().analyse("notanumber"))

    f = NUMERIC(num_type=float)
    assert f.equals("1", "1.0")

    assert list(BOOLEAN().analyse("1"))[0].value is True
Пример #3
0
def test_schema():
    simple_schema = Schema(test=TEXT, user=ID)
    names = simple_schema.names()
    items = simple_schema.items()

    assert len(simple_schema) == 2
    assert len(names) == 2
    assert 'test' in names
    assert 'user' in names
    assert len(items) == 2

    assert isinstance(simple_schema['test'], TEXT)
    assert isinstance(simple_schema['user'], ID)
    with pytest.raises(KeyError):
        simple_schema['no_item']

    for field in simple_schema:
        assert isinstance(field, FieldType)

    assert 'test' in simple_schema
    assert 'text' not in simple_schema

    with pytest.raises(FieldConfigurationError):
        simple_schema.add("_test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("test", TEXT)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", object)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", str)
    with pytest.raises(FieldConfigurationError):
        simple_schema.add("text", IndexWriter)

    with pytest.raises(ValueError):
        NUMERIC(num_type=str)
    with pytest.raises(NotImplementedError):
        FieldType().equals('a', 'b')
    with pytest.raises(ValueError):
        list(NUMERIC().analyse('notanumber'))

    f = NUMERIC(num_type=float)
    assert f.equals('1', '1.0')

    assert list(BOOLEAN().analyse('1'))[0].value is True