示例#1
0
def test_resolve_with_ordering():
    rule_path = get_rule_file('test_resolve_with_ordering.json')
    ruleset = rules.parse_file(rule_path.as_posix())
    assert len(ruleset.rules) == 5

    context = resolver.make_context()
    result = resolver.resolve(ruleset, context)
    assert len(result.goals) == 5
    assert all(goal.points == 1 for goal in result.goals)
示例#2
0
def test_resolve_basic():
    rule_path = get_rule_file('test_resolve_basic.json')
    ruleset = rules.parse_file(rule_path.as_posix())
    assert len(ruleset.rules) == 1

    context = resolver.make_context()
    result = resolver.resolve(ruleset, context)
    assert any(goal.name == 'resolve-basic-goal' and goal.points == 1
               for goal in result.goals)
    assert len(result.goals) == 1
示例#3
0
def test_resolve_two_to_same():
    rule_path = get_rule_file('test_resolve_two_to_same.json')
    ruleset = rules.parse_file(rule_path.as_posix())
    assert len(ruleset.rules) == 2

    context = resolver.make_context()
    result = resolver.resolve(ruleset, context)
    assert len(result.goals) == 1
    goal = result.goals[0]
    assert goal.name == 'resolve-two-of-same' and goal.points == 2 and \
        len(goal.resolved_rules) == 2 and len(goal.non_resolved_rules) == 0
示例#4
0
 def handle_student(student):
     kattis = aaps.KattisResult()
     if is_student:
         kattis.resolve_sessions_with_input()
     add_sub = lambda sub: kattis.add_submission(sub)
     util.map_now(add_sub, student.submissions)
     context = resolver.make_context()
     plugins = kattis.get_plugins()
     add_plugin = lambda c, r: resolver.context_add_plugin(context, c, r)
     util.starmap_now(add_plugin, plugins)
     result = resolver.resolve(ruleset, context)
     return make_student_result(student, ruleset, kattis, context, result)
示例#5
0
def test_custom_plugin():
    def checker(context, tree):
        return isinstance(tree, dict) and 'identity' in tree

    def handler(context, tree):
        return tree['identity']

    rule_path = get_rule_file('test_custom_plugin.json')
    ruleset = rules.parse_file(rule_path.as_posix())
    assert len(ruleset.rules) == 1

    context = resolver.make_context()
    resolver.context_add_plugin(context, checker, handler)
    result = resolver.resolve(ruleset, context)
    assert len(result.goals) == 1
    assert all(goal.points == 42 for goal in result.goals)
示例#6
0
def resolve_for_result(kattis, ruleset):
    context = resolver.make_context()
    plugins = kattis.get_plugins()
    func = lambda c, h: resolver.context_add_plugin(context, c, h)
    util.starmap_now(func, plugins)
    return resolver.resolve(ruleset, context)