Пример #1
0
def test_delete_rule_nonexistent(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
    from src.praxxis.util import error
    from src.praxxis.display import display_error

    name1 = dummy_object.make_dummy_ruleset("generated_ruleset_with_rule")

    with monkeypatch.context() as m:
        mock_in = "2"
        m.setattr("builtins.input", lambda _: mock_in)
        try:
            delete_rule_from_ruleset.delete_rule_from_ruleset(name1, rulesengine_db)
            assert 0 # if no error thrown
        except error.RuleNotFoundError as e:
            assert str(e) == display_error.rule_not_found_error(mock_in)

    with monkeypatch.context() as m:
        mock_in = "bad rulename"
        m.setattr("builtins.input", lambda _: mock_in)
        try:
            delete_rule_from_ruleset.delete_rule_from_ruleset(name1, rulesengine_db)
            assert 0 # if no error thrown
        except error.RuleNotFoundError as e:
            assert str(e) == display_error.rule_not_found_error(mock_in)
Пример #2
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)
Пример #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 test_remove_ruleset(setup, create_one_ruleset, rulesengine_db):
    from src.praxxis.rulesengine import remove_ruleset
    from tests.src.praxxis.util import dummy_object

    name1 = dummy_object.make_dummy_ruleset("generated_one_ruleset")
    message = remove_ruleset.remove_ruleset(name1, rulesengine_db)

    assert message == name1.name
Пример #5
0
def test_new_ruleset(setup, rulesengine_root, rulesengine_db):
    name1 = dummy_object.make_dummy_ruleset("one_ruleset")
    entry_rulesengine.new_ruleset(name1, rulesengine_root, rulesengine_db)

    from src.praxxis.sqlite import sqlite_rulesengine
    ruleset_list = sqlite_rulesengine.get_all_rulesets(rulesengine_db, query_start=1, query_end=10)

    assert ruleset_list[0][0] == name1.name
    
    sqlite_rulesengine.clear_ruleset_list(rulesengine_db)
Пример #6
0
def test_activate_ruleset_nonexistent(setup, rulesengine_db):
    from src.praxxis.rulesengine import activate_ruleset
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.util import error
    from src.praxxis.display import display_error
    name1 = dummy_object.make_dummy_ruleset("nonexistent_ruleset")

    try:
        activate_ruleset.activate_ruleset(name1, rulesengine_db)
    except error.RulesetNotFoundError as e:
        assert str(e) == display_error.ruleset_not_found_error(name1.name)
Пример #7
0
def test_deactivate_ruleset_already_inactive(setup, rulesengine_db, create_deactivated_ruleset):
    from src.praxxis.rulesengine import deactivate_ruleset
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.display import display_error
    from src.praxxis.util import error

    name1 = dummy_object.make_dummy_ruleset("generated_deactivated_ruleset")

    try:
        deactivate_ruleset.deactivate_ruleset(name1, rulesengine_db)
    except error.RulesetNotActiveError as e:
        assert str(e) == display_error.ruleset_not_active_error(name1.name)
Пример #8
0
def test_activate_ruleset(setup, create_deactivated_ruleset, rulesengine_db):
    """
    tests activate_ruleset functionality. Requires that setup is run and there is a ruleset inactive.
    """
    from src.praxxis.rulesengine import activate_ruleset
    from tests.src.praxxis.util import dummy_object
    import os

    name1 = dummy_object.make_dummy_ruleset("generated_deactivated_ruleset")

    result = activate_ruleset.activate_ruleset(name1, rulesengine_db)

    assert result == name1.name
Пример #9
0
def create_one_ruleset(rulesengine_root, rulesengine_db):
    from src.praxxis.rulesengine import new_ruleset
    from src.praxxis.rulesengine import remove_ruleset
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.util import error

    name1 = dummy_object.make_dummy_ruleset("generated_one_ruleset")
    new_ruleset.new_ruleset(name1, rulesengine_root, rulesengine_db)
    yield
    try:
        remove_ruleset.remove_ruleset(name1, rulesengine_db)
    except error.RulesetNotFoundError:
        pass
Пример #10
0
def test_list_rulesets(setup, create_one_ruleset, create_one_ruleset_one_rule, create_deactivated_ruleset, rulesengine_db, query_start, query_end):
    from src.praxxis.rulesengine import list_rulesets
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.sqlite import sqlite_rulesengine


    name1 = dummy_object.make_dummy_ruleset("generated_one_ruleset")
    name2 = dummy_object.make_dummy_ruleset("generated_ruleset_with_rule")
    name3 = dummy_object.make_dummy_ruleset("generated_deactivated_ruleset")
    
    result = list_rulesets.list_rulesets(name1, rulesengine_db, query_start, query_end)

    assert len(result) == 3
    for info in result:
        assert len(info) == 2
    assert result[0][0] == name1.name
    assert result[0][1] == 1 # active
    assert result[1][0] == name2.name
    assert result[1][1] == 1 # active
    assert result[2][0] == name3.name
    assert result[2][1] == 0 # inactive    
    
Пример #11
0
def test_remove_ruleset(setup, rulesengine_root, rulesengine_db, create_one_ruleset):
    name1 = dummy_object.make_dummy_ruleset("generated_one_ruleset")

    from src.praxxis.sqlite import sqlite_rulesengine
    ruleset_list = sqlite_rulesengine.get_all_rulesets(rulesengine_db, query_start=1, query_end=10)

    assert ruleset_list[0][0] == name1.name
    entry_rulesengine.remove_ruleset(name1, rulesengine_db)
    
    ruleset_list = sqlite_rulesengine.get_all_rulesets(rulesengine_db, query_start=1, query_end=10)

    assert len(ruleset_list) == 0
    
Пример #12
0
def test_activate_ruleset_already_active(setup, create_one_ruleset,
                                         rulesengine_db):
    from src.praxxis.rulesengine import activate_ruleset
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.util import error
    from src.praxxis.display import display_error
    import os

    name1 = dummy_object.make_dummy_ruleset("generated_one_ruleset")

    try:
        activate_ruleset.activate_ruleset(name1, rulesengine_db)
    except error.RulesetActiveError as e:
        assert str(e) == display_error.ruleset_active_error(name1.name)
Пример #13
0
def test_view_rules(setup, create_one_ruleset_one_rule, rulesengine_db):
    from src.praxxis.rulesengine import view_rules
    from tests.src.praxxis.util import dummy_object

    name1 = dummy_object.make_dummy_ruleset("generated_ruleset_with_rule")
    ##
    # The rule in create_one_ruleset_one_rule:
    # "testing": ["f1, f3"]["out1","out2"] = [('testing', 1, 'pred1', 'lib', None),('testing', 2, 'pred2', 'lib', None)])
    ## 
    message = view_rules.view_rules(name1, rulesengine_db)

    assert len(message) == 1
    assert message[0][0] == "testing"
    
Пример #14
0
def test_new_ruleset(setup, rulesengine_root, rulesengine_db, query_start,
                     query_end):
    from src.praxxis.rulesengine import new_ruleset
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.sqlite import sqlite_rulesengine

    name1 = dummy_object.make_dummy_ruleset("new_ruleset")
    message = new_ruleset.new_ruleset(name1, rulesengine_root, rulesengine_db)

    assert message == name1.name

    rulesets = sqlite_rulesengine.get_all_rulesets(rulesengine_db, query_start,
                                                   query_end)
    assert len(rulesets) == 1
    assert rulesets[0][0] == name1.name

    sqlite_rulesengine.clear_ruleset_list(rulesengine_db)
Пример #15
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