<commit_before># Copyright 2016 ZEROFAIL
#
# This file is part of Goblin.
#
# Goblin is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Goblin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Goblin.  If not, see <http://www.gnu.org/licenses/>.

import pytest

import goblin
from goblin import element
from goblin.driver import serializer
from gremlin_python import process


def test_register_from_module(app):
    import register_models
    app.register_from_module(register_models)
    vertices, edges = app._vertices.values(), app._edges.values()
    assert register_models.TestRegisterVertex1 in vertices
    assert register_models.TestRegisterVertex2 in vertices
    assert register_models.TestRegisterEdge1 in edges
    assert register_models.TestRegisterEdge2 in edges


def test_register_from_module_string(app):
    app.register_from_module('register_models', package=__package__)
    vertices, edges = app._vertices.values(), app._edges.values()

    import register_models
    assert register_models.TestRegisterVertex1 in vertices
    assert register_models.TestRegisterVertex2 in vertices
    assert register_models.TestRegisterEdge1 in edges
    assert register_models.TestRegisterEdge2 in edges


@pytest.mark.asyncio
async def test_registry(app, person, place, knows, lives_in):
    assert len(app.vertices) ==  2
    assert len(app.edges) == 2
    assert person.__class__ == app.vertices['person']
    assert place.__class__ == app.vertices['place']
    assert knows.__class__ == app.edges['knows']
    assert lives_in.__class__ == app.edges['lives_in']
    await app.close()


@pytest.mark.asyncio
async def test_registry_defaults(app):
    vertex = app.vertices['unregistered']
    assert isinstance(vertex(), element.Vertex)
    edge = app.edges['unregistered']
    assert isinstance(edge(), element.Edge)
    await app.close()

@pytest.mark.asyncio
async def test_transaction_discovery(app):
    assert app._transactions is not None
    await app.close()<commit_msg>close app object in tests<commit_after># Copyright 2016 ZEROFAIL
#
# This file is part of Goblin.
#
# Goblin is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Goblin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Goblin.  If not, see <http://www.gnu.org/licenses/>.

import pytest

import goblin
from goblin import element
from goblin.driver import serializer
from gremlin_python import process


@pytest.mark.asyncio
async def test_register_from_module(app):
    import register_models
    app.register_from_module(register_models)
    vertices, edges = app._vertices.values(), app._edges.values()
    assert register_models.TestRegisterVertex1 in vertices
    assert register_models.TestRegisterVertex2 in vertices
    assert register_models.TestRegisterEdge1 in edges
    assert register_models.TestRegisterEdge2 in edges
    await app.close()

@pytest.mark.asyncio
async def test_register_from_module_string(app):
    app.register_from_module('register_models', package=__package__)
    vertices, edges = app._vertices.values(), app._edges.values()

    import register_models
    assert register_models.TestRegisterVertex1 in vertices
    assert register_models.TestRegisterVertex2 in vertices
    assert register_models.TestRegisterEdge1 in edges
    assert register_models.TestRegisterEdge2 in edges
    await app.close()


@pytest.mark.asyncio
async def test_registry(app, person, place, knows, lives_in):
    assert len(app.vertices) ==  2
    assert len(app.edges) == 2
    assert person.__class__ == app.vertices['person']
    assert place.__class__ == app.vertices['place']
    assert knows.__class__ == app.edges['knows']
    assert lives_in.__class__ == app.edges['lives_in']
    await app.close()


@pytest.mark.asyncio
async def test_registry_defaults(app):
    vertex = app.vertices['unregistered']
    assert isinstance(vertex(), element.Vertex)
    edge = app.edges['unregistered']
    assert isinstance(edge(), element.Edge)
    await app.close()

@pytest.mark.asyncio
async def test_transaction_discovery(app):
    assert app._transactions is not None
    await app.close()
{'fraction_non_alphanumeric': 0.07727544313881697, 'fraction_numerical': 0.005974905397331209, 'mean_word_length': 4.5676274944567625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2438458', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1398, 'n_words': 473}