<commit_before>from neomodel import (StructuredNode, StringProperty, IntegerProperty,
    ReadOnlyNode)
from neomodel.exception import RequiredProperty


class User(StructuredNode):
    email = StringProperty(unique_index=True, required=True)
    age = IntegerProperty(index=True)

    @property
    def email_alias(self):
        return self.email

    @email_alias.setter
    def email_alias(self, value):
        self.email = value


def test_required():
    try:
        User(age=3).save()
    except RequiredProperty:
        assert True
    else:
        assert False


def test_get():
    u = User(email='<EMAIL>', age=3)
    assert u.save()
    rob = User.index.get(email='<EMAIL>')
    assert rob.email == '<EMAIL>'
    assert rob.age == 3


def test_search():
    assert User(email='<EMAIL>', age=3).save()
    assert User(email='<EMAIL>', age=3).save()
    users = User.index.search(age=3)
    assert len(users)


def test_save_to_model():
    u = User(email='<EMAIL>', age=3)
    assert u.save()
    assert u.__node__
    assert u.email == '<EMAIL>'
    assert u.age == 3


def test_unique():
    User(email='<EMAIL>', age=3).save()
    try:
        User(email='<EMAIL>', age=3).save()
    except Exception, e:
        assert e.__class__.__name__ == 'UniqueProperty'
    else:
        assert False


def test_update():
    user = User(email='<EMAIL>', age=3).save()
    assert user
    user.email = '<EMAIL>'
    user.save()
    jim = User.index.get(email='<EMAIL>')
    assert jim
    assert jim.email == '<EMAIL>'


def test_save_through_magic_property():
    user = User(email_alias='<EMAIL>', age=8).save()
    assert user.email_alias == '<EMAIL>'
    user = User.index.get(email='<EMAIL>')
    assert user.email == '<EMAIL>'
    assert user.email_alias == '<EMAIL>'

    user1 = User(email='<EMAIL>', age=8).save()
    assert user1.email_alias == '<EMAIL>'
    user1.email_alias = '<EMAIL>'
    assert user1.save()
    user2 = User.index.get(email='<EMAIL>')
    assert user2


def test_readonly_definition():
    # create user
    class MyNormalUser(StructuredNode):
        _index_name = 'readonly_test'
        name = StringProperty(index=True)
    MyNormalUser(name='bob').save()

    class MyReadOnlyUser(ReadOnlyNode):
        _index_name = 'readonly_test'
        name = StringProperty(index=True)

    # reload as readonly from same index
    bob = MyReadOnlyUser.index.get(name='bob')
    assert bob.name == 'bob'

    try:
        bob.delete()
    except Exception, e:
        assert e.__class__.__name__ == 'ReadOnlyError'
    else:
        assert False

    try:
        bob.save()
    except Exception, e:
        assert e.__class__.__name__ == 'ReadOnlyError'
    else:
        assert False
<commit_msg>Fix exception syntax for python 3<commit_after>from neomodel import (StructuredNode, StringProperty, IntegerProperty,
    ReadOnlyNode)
from neomodel.exception import RequiredProperty


class User(StructuredNode):
    email = StringProperty(unique_index=True, required=True)
    age = IntegerProperty(index=True)

    @property
    def email_alias(self):
        return self.email

    @email_alias.setter
    def email_alias(self, value):
        self.email = value


def test_required():
    try:
        User(age=3).save()
    except RequiredProperty:
        assert True
    else:
        assert False


def test_get():
    u = User(email='<EMAIL>', age=3)
    assert u.save()
    rob = User.index.get(email='<EMAIL>')
    assert rob.email == '<EMAIL>'
    assert rob.age == 3


def test_search():
    assert User(email='<EMAIL>', age=3).save()
    assert User(email='<EMAIL>', age=3).save()
    users = User.index.search(age=3)
    assert len(users)


def test_save_to_model():
    u = User(email='<EMAIL>', age=3)
    assert u.save()
    assert u.__node__
    assert u.email == '<EMAIL>'
    assert u.age == 3


def test_unique():
    User(email='<EMAIL>', age=3).save()
    try:
        User(email='<EMAIL>', age=3).save()
    except Exception as e:
        assert e.__class__.__name__ == 'UniqueProperty'
    else:
        assert False


def test_update():
    user = User(email='<EMAIL>', age=3).save()
    assert user
    user.email = '<EMAIL>'
    user.save()
    jim = User.index.get(email='<EMAIL>')
    assert jim
    assert jim.email == '<EMAIL>'


def test_save_through_magic_property():
    user = User(email_alias='<EMAIL>', age=8).save()
    assert user.email_alias == '<EMAIL>'
    user = User.index.get(email='<EMAIL>')
    assert user.email == '<EMAIL>'
    assert user.email_alias == '<EMAIL>'

    user1 = User(email='<EMAIL>', age=8).save()
    assert user1.email_alias == '<EMAIL>'
    user1.email_alias = '<EMAIL>'
    assert user1.save()
    user2 = User.index.get(email='<EMAIL>')
    assert user2


def test_readonly_definition():
    # create user
    class MyNormalUser(StructuredNode):
        _index_name = 'readonly_test'
        name = StringProperty(index=True)
    MyNormalUser(name='bob').save()

    class MyReadOnlyUser(ReadOnlyNode):
        _index_name = 'readonly_test'
        name = StringProperty(index=True)

    # reload as readonly from same index
    bob = MyReadOnlyUser.index.get(name='bob')
    assert bob.name == 'bob'

    try:
        bob.delete()
    except Exception as e:
        assert e.__class__.__name__ == 'ReadOnlyError'
    else:
        assert False

    try:
        bob.save()
    except Exception as e:
        assert e.__class__.__name__ == 'ReadOnlyError'
    else:
        assert False

{'fraction_non_alphanumeric': 0.13851474335638878, 'fraction_numerical': 0.007098653076083, 'mean_word_length': 2.984771573604061, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4398249', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1785, 'n_words': 398}