示例#1
0
def test_import_database(setup, rulesengine_db, create_one_ruleset):
    from src.praxxis.rulesengine import import_ruleset
    from src.praxxis.sqlite import sqlite_rulesengine
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.rulesengine import remove_ruleset

    name = "generated_one_ruleset"
    ruleset_path = sqlite_rulesengine.get_ruleset_path(rulesengine_db, name)

    name1 = dummy_object.make_dummy_ruleset(name, ruleset_path)

    sqlite_rulesengine.clear_ruleset_list(rulesengine_db)

    message = import_ruleset.import_ruleset(name1, name1.name, rulesengine_db)

    assert message == name1.name

    rulesets = sqlite_rulesengine.get_all_rulesets(rulesengine_db,
                                                   query_start=1,
                                                   query_end=5)

    assert len(rulesets) == 1
    assert len(rulesets[0]) == 2
    assert rulesets[0][0] == name1.name

    remove_ruleset.remove_ruleset(message, rulesengine_db)
示例#2
0
def delete_rule_from_ruleset(args, rulesengine_db):
    """prompts user through deleting a rule in a ruleset"""
    from src.praxxis.sqlite import sqlite_rulesengine
    from src.praxxis.display import display_rulesengine
    from src.praxxis.display import display_edit_ruleset
    from src.praxxis.rulesengine import rules

    if hasattr(args, "name"):
        name = args.name
    else:
        name = args

    # get ruleset info
    name = rules.get_ruleset_by_ordinal(name, rulesengine_db)
    ruleset_db = sqlite_rulesengine.get_ruleset_path(rulesengine_db, name)

    # give the user a list of rules and ask which one to delete
    rules_list = sqlite_rulesengine.list_rules_in_ruleset(ruleset_db)
    display_rulesengine.display_rule_list(name, rules_list)
    deletion = display_edit_ruleset.display_deletion_prompt()

    # get deletion info and delete
    deletion_name = get_rule_by_ordinal(deletion, rules_list)
    sqlite_rulesengine.delete_rule(ruleset_db, deletion_name)
    display_rulesengine.display_rule_deletion(name, deletion_name)

    return deletion_name
示例#3
0
def test_delete_rule(setup, monkeypatch, create_one_ruleset_one_rule, rulesengine_db, library_db, create_one_scene,current_scene_db, query_start, query_end):
    from src.praxxis.rulesengine import delete_rule_from_ruleset
    from src.praxxis.sqlite import sqlite_rulesengine
    from tests.src.praxxis.rulesengine import test_add_rule
    from tests.src.praxxis.util import dummy_object

    name1 = dummy_object.make_dummy_ruleset("generated_ruleset_with_rule")
    ruleset_path = sqlite_rulesengine.get_ruleset_path(rulesengine_db, name1.name)

    mock_in = "testing"
    with monkeypatch.context() as m:
        m.setattr("builtins.input", lambda _: mock_in)
        rulename = delete_rule_from_ruleset.delete_rule_from_ruleset(name1, rulesengine_db)
        
    assert rulename == mock_in

    # test database cleaning
    rules = sqlite_rulesengine.list_rules_in_ruleset(ruleset_path)
    filenames = sqlite_rulesengine.get_filenames(ruleset_path, rulename)
    outputs = sqlite_rulesengine.get_outputs(ruleset_path, rulename)
    predictions = sqlite_rulesengine.get_predictions(ruleset_path, [rulename])
    
    assert rules == [] 
    assert filenames == []
    assert outputs == []
    assert predictions == [] 
示例#4
0
def view_rules(args, rulesengine_db):
    """view rules in a given ruleset"""
    from src.praxxis.sqlite import sqlite_rulesengine
    from src.praxxis.display import display_rulesengine
    from src.praxxis.rulesengine import rules

    if hasattr(args, "name"):
        name = args.name
    else:
        name = args

    name = rules.get_ruleset_by_ordinal(name, rulesengine_db)

    ruleset_db = sqlite_rulesengine.get_ruleset_path(rulesengine_db, name)

    rules_list = sqlite_rulesengine.list_rules_in_ruleset(ruleset_db)
    display_rulesengine.display_rule_list(name, rules_list)

    return rules_list
示例#5
0
def create_one_ruleset_one_rule(rulesengine_root, rulesengine_db):
    from src.praxxis.rulesengine import new_ruleset
    from src.praxxis.rulesengine import remove_ruleset
    from src.praxxis.sqlite import sqlite_rulesengine
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.util import error

    name1 = dummy_object.make_dummy_ruleset("generated_ruleset_with_rule")
    new_ruleset.new_ruleset(name1, rulesengine_root, rulesengine_db)
    # ADD RULE TO SQLITE
    ruleset_path = sqlite_rulesengine.get_ruleset_path(rulesengine_db,
                                                       name1.name)
    sqlite_rulesengine.add_rule(ruleset_path, "testing",
                                ["test_notebook", "f3"], [""],
                                [('testing', 1, 'pred1', 'lib', None),
                                 ('testing', 2, 'pred2', 'lib', None)])
    yield
    try:
        remove_ruleset.remove_ruleset(name1, rulesengine_db)
    except error.RulesetNotFoundError:
        pass
示例#6
0
def add_rule_to_ruleset(args, rulesengine_db, library_db, current_scene_db,
                        query_start, query_end):
    """prompts user through adding a rule, given a ruleset"""
    from src.praxxis.sqlite import sqlite_rulesengine
    from src.praxxis.display import display_rulesengine
    from src.praxxis.display import display_edit_ruleset
    from src.praxxis.rulesengine import rules
    from src.praxxis.display.display_error import predictions_ordinal_not_in_list_error
    from src.praxxis.notebook.list_notebook import list_notebook

    if hasattr(args, "name"):
        name = args.name
    else:
        name = args

    name = rules.get_ruleset_by_ordinal(name, rulesengine_db)

    ruleset_db = sqlite_rulesengine.get_ruleset_path(rulesengine_db, name)

    # get a name for the rule
    rulename = display_edit_ruleset.display_get_rule_name()

    # get filenames
    list_notebook(library_db, current_scene_db, query_start, query_end)
    filenames_raw = display_edit_ruleset.display_filename_input()
    filenames_with_ords = [
        string.strip().strip('"').strip('\'')
        for string in filenames_raw.split(",")
    ]
    filenames = get_filenames_from_ordinals(filenames_with_ords,
                                            current_scene_db)
    display_edit_ruleset.display_filenames(filenames)

    # get output strings
    output_raw = display_edit_ruleset.display_output_input()
    output = [
        item.strip().strip('"').strip('\'') for item in output_raw.split(",")
    ]
    display_edit_ruleset.display_outputs(output)

    # get predicted notebooks
    list_notebook(library_db, current_scene_db, query_start, query_end)
    predicted_raw = display_edit_ruleset.display_predicted_notebooks_input()
    predicted_with_ords = [
        prediction.strip() for prediction in predicted_raw.split(",")
    ]
    predicted = get_fileinfo_from_ordinals(predicted_with_ords,
                                           current_scene_db, rulename)
    while predicted == 1:
        predictions_ordinal_not_in_list_error()

        predicted_raw = display_edit_ruleset.display_predicted_notebooks_input(
        )
        predicted_with_ords = [
            prediction.strip() for prediction in predicted_raw.split(",")
        ]
        predicted = get_fileinfo_from_ordinals(predicted_with_ords,
                                               current_scene_db, rulename)

    display_edit_ruleset.display_prediction_list(predicted)

    # display total rule and add it to db
    display_rulesengine.display_rule(rulename, filenames, output, predicted)
    sqlite_rulesengine.add_rule(ruleset_db, rulename, filenames, output,
                                predicted)

    return rulename