<commit_before>from indra.pipeline import AssemblyPipeline, RunnableArgument
from indra.pipeline.pipeline import jsonify_arg_input
from indra.tests.test_assemble_corpus import st1, st2, st3, st4
from indra.tools.assemble_corpus import *
from indra.preassembler.custom_preassembly import location_matches, \
    location_refinement
from indra.belief.wm_scorer import *
from indra.belief import BeliefScorer
from indra.preassembler.hierarchy_manager import get_wm_hierarchies
from indra.statements import Activation


stmts = [st1, st2, st3, st4]


def test_running_pipeline():
    # From json file
    ap = AssemblyPipeline.from_json_file('pipeline_test.json')
    assert ap
    # AssemblyPipeline has methods for length and iteration
    assert len(ap) == 5
    for step in ap:
        assert step
    assembled_stmts = ap.run(stmts)
    assert assembled_stmts
    assert len(assembled_stmts) == 2
    # By manually adding steps
    ap2 = AssemblyPipeline()
    ap2.append(filter_no_hypothesis)
    ap2.append(map_grounding)
    ap2.append(filter_grounded_only)
    ap2.append(map_sequence)
    ap2.append(run_preassembly, return_toplevel=False)
    assembled_stmts2 = ap2.run(stmts)
    assert assembled_stmts2
    assert len(assembled_stmts2) == 2


def test_pipeline_methods():
    ap = AssemblyPipeline()
    assert len(ap) == 0
    ap.append(filter_grounded_only)
    assert len(ap) == 1
    ap.insert(0, filter_no_hypothesis)
    assert len(ap) == 2
    assert ap.steps[0] == {'function': 'filter_no_hypothesis'}
    # Append functions with arguments and runnable arguments<commit_msg>Create a path to a json in tests<commit_after>import os
from indra.pipeline import AssemblyPipeline, RunnableArgument
from indra.pipeline.pipeline import jsonify_arg_input
from indra.tests.test_assemble_corpus import st1, st2, st3, st4
from indra.tools.assemble_corpus import *
from indra.preassembler.custom_preassembly import location_matches, \
    location_refinement
from indra.belief.wm_scorer import *
from indra.belief import BeliefScorer
from indra.preassembler.hierarchy_manager import get_wm_hierarchies
from indra.statements import Activation


stmts = [st1, st2, st3, st4]
path_this = os.path.dirname(os.path.abspath(__file__))
test_json = os.path.join(path_this, 'pipeline_test.json')


def test_running_pipeline():
    # From json file
    ap = AssemblyPipeline.from_json_file(test_json)
    assert ap
    # AssemblyPipeline has methods for length and iteration
    assert len(ap) == 5
    for step in ap:
        assert step
    assembled_stmts = ap.run(stmts)
    assert assembled_stmts
    assert len(assembled_stmts) == 2
    # By manually adding steps
    ap2 = AssemblyPipeline()
    ap2.append(filter_no_hypothesis)
    ap2.append(map_grounding)
    ap2.append(filter_grounded_only)
    ap2.append(map_sequence)
    ap2.append(run_preassembly, return_toplevel=False)
    assembled_stmts2 = ap2.run(stmts)
    assert assembled_stmts2
    assert len(assembled_stmts2) == 2


def test_pipeline_methods():
    ap = AssemblyPipeline()
    assert len(ap) == 0
    ap.append(filter_grounded_only)
    assert len(ap) == 1
    ap.insert(0, filter_no_hypothesis)
    assert len(ap) == 2
    assert ap.steps[0] == {'function': 'filter_no_hypothesis'}
    # Append functions with arguments and runnable arguments
{'fraction_non_alphanumeric': 0.07938424388771506, 'fraction_numerical': 0.01569574403863568, 'mean_word_length': 4.406199021207178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '215133', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1098, 'n_words': 257}