Пример #1
0
def test_element():
    """Test the `BasisData.element` property."""
    element = 'Ar'
    basis = BasisData(io.BytesIO(b'basis'))
    assert basis.element is None

    element = 'He'
    basis.element = element
    assert basis.element == element

    with pytest.raises(ValueError, match=r'.* is not a valid element'):
        basis.element = 'Aa'

    basis.store()

    with pytest.raises(
            ModificationNotAllowed,
            match='the attributes of a stored entity are immutable'):
        basis.element = element
Пример #2
0
def test_md5():
    """Test the `BasisData.md5` property."""
    stream = io.BytesIO(b'basis')
    md5 = md5_from_filelike(stream)
    stream.seek(0)

    basis = BasisData(stream)
    basis.element = 'Ar'
    assert basis.md5 == md5

    with pytest.raises(ValueError,
                       match=r'md5 does not match that of stored file.*'):
        basis.md5 = 'abcdef0123456789'

    basis.store()

    with pytest.raises(
            ModificationNotAllowed,
            match='the attributes of a stored entity are immutable'):
        basis.md5 = md5
Пример #3
0
def test_store():
    """Test the `BasisData.store` method."""
    stream = io.BytesIO(b'basis')
    md5_correct = md5_from_filelike(stream)
    md5_incorrect = 'abcdef0123456789'
    stream.seek(0)

    basis = BasisData(io.BytesIO(b'basis'))

    with pytest.raises(StoringNotAllowed,
                       match='no valid element has been defined.'):
        basis.store()

    basis.element = 'Ar'
    basis.set_attribute(BasisData._key_md5, md5_incorrect)  # pylint: disable=protected-access

    with pytest.raises(StoringNotAllowed,
                       match=r'md5 does not match that of stored file:'):
        basis.store()

    basis.md5 = md5_correct
    result = basis.store()
    assert result is basis
    assert basis.is_stored