예제 #1
0
def test_ranges_gte_at_most(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"count(courses)": {"$gte": 1, "at_most": True}}, c=c)
    result = x.input_size_range(maximum=5)
    assert list(result) == [1]
예제 #2
0
def test_ranges_lte(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"count(courses)": {"$lte": 5}}, c=c)
    result = x.input_size_range(maximum=7)
    assert list(result) == [0, 1, 2, 3, 4, 5]
예제 #3
0
def test_load_predicate_constant_expands_to_several_nested():
    ppm = tuple(['saxophone', 'jazz saxophone'])
    constants = Constants(primary_performing_medium=ppm)
    ctx = RequirementContext()
    input_data = {'name': {'$in': ['piano', '$primary-performing-medium']}}

    c = load_predicate(input_data, c=constants, mode=DataType.Course, ctx=ctx)
    assert isinstance(c, Predicate)

    assert list(c.expected) == ['piano', 'saxophone', 'jazz saxophone']
예제 #4
0
def test_clause__grade_code():
    c = Constants(matriculation_year=2000)

    clause = load_clause({"grade_code": {"$in": ["P", "IP", "S"]}}, c=c)

    y_course = course_from_str(s="CSCI 296", grade_code="P")
    n_course = course_from_str(s="CSCI 296", grade_code="F")

    assert clause.apply(y_course) is True
    assert clause.apply(n_course) is False
예제 #5
0
def test_clauses(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)

    x = load_clause({"attributes": {"$eq": "csci_elective"}}, c=c)
    expected_single = SingleClause(key="attributes", expected="csci_elective", expected_verbatim="csci_elective", operator=Operator.EqualTo)
    assert x == expected_single

    crs = course_from_str(s="CSCI 121", attributes=["csci_elective"])

    assert x.apply(crs) is True
예제 #6
0
def test_clauses_in(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)
    course = course_from_str(s="CSCI 296")

    values = tuple([296, 298, 396, 398])
    x = load_clause({"number": {"$in": values}}, c=c)
    expected_single = SingleClause(key="number", expected=values, expected_verbatim=values, operator=Operator.In)
    assert x == expected_single

    assert x.apply(course) is True
예제 #7
0
def test_ranges_eq(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)
    ctx = RequirementContext()

    x = Assertion.load({"assert": {
        "count(courses)": {
            "$eq": 1
        }
    }},
                       c=c,
                       ctx=ctx,
                       data_type=DataType.Course,
                       path=['$'])
    result = x.input_size_range(maximum=5)
    assert list(result) == [1]
예제 #8
0
def test_clauses_in(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)
    ctx = RequirementContext()
    course = course_from_str(s="CSCI 296")

    values = tuple([296, 298, 396, 398])
    x = load_predicate({"number": {
        "$in": values
    }},
                       c=c,
                       ctx=ctx,
                       mode=DataType.Course)
    expected_single = Predicate.from_args(key="number",
                                          expected=values,
                                          original=values,
                                          operator=Operator.In)
    assert x == expected_single

    assert x.apply(course) is True
예제 #9
0
def test_clauses(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)
    ctx = RequirementContext()

    x = load_predicate({"attributes": {
        "$eq": "csci_elective"
    }},
                       c=c,
                       ctx=ctx,
                       mode=DataType.Course)
    expected_single = Predicate.from_args(key="attributes",
                                          expected="csci_elective",
                                          original="csci_elective",
                                          operator=Operator.EqualTo)
    assert x == expected_single

    crs = course_from_str(s="CSCI 121", attributes=["csci_elective"])

    assert x.apply(crs) is True
예제 #10
0
def test_resolution(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)
    ctx = RequirementContext()

    x = Assertion.load({"assert": {
        "count(items)": {
            "$eq": 1
        }
    }},
                       c=c,
                       ctx=ctx,
                       data_type=DataType.Recital,
                       path=['$'])

    result = x.audit_and_resolve(tuple([IntThing()]), ctx=ctx)
    assert result.ok() is True

    result = x.audit_and_resolve(tuple([IntThing(), IntThing()]), ctx=ctx)
    assert result.ok() is False
예제 #11
0
def test_ranges_eq_2(caplog):
    """ensure that a solution with fewer matching courses than requested is still proposed"""
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    result = load_clause({"count(courses)": {"$eq": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]

    result = load_clause({"count(courses)": {"$neq": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = load_clause({"count(courses)": {"$lt": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = load_clause({"count(courses)": {"$lte": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2, 3]

    result = load_clause({"count(courses)": {"$gt": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]

    result = load_clause({"count(courses)": {"$gte": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]
예제 #12
0
def test_resolution(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)

    class IntThing(Clausable):
        def apply_single_clause(self):
            pass
        def to_dict(self):
            pass
        def sort_order(self):
            return (hash(self))

    x = load_clause({"count(items)": {"$eq": 1}}, c=c)
    expected_single = SingleClause(key="count(items)", expected=1, expected_verbatim=1, operator=Operator.EqualTo)
    assert x == expected_single

    result = x.compare_and_resolve_with(tuple([IntThing()]))
    assert result.ok() is True

    result = x.compare_and_resolve_with(tuple([IntThing(), IntThing()]))
    assert result.ok() is False
예제 #13
0
from dp.area import AreaOfStudy
from dp.data.student import Student
from dp.data.course import course_from_str
from dp.constants import Constants
import io
import yaml

c = Constants(matriculation_year=2000)


def test_limit__at_most_1_course():
    test_data = io.StringIO("""
        limit:
          - at_most: 1
            where: {number: {$eq: 201}}

        result:
          from: courses
          where: {number: {$eq: 201}}
          assert: {count(courses): {$gte: 1}}
    """)

    area = AreaOfStudy.load(specification=yaml.load(stream=test_data, Loader=yaml.SafeLoader), c=c)

    course_1 = course_from_str("BIO 201")
    course_2 = course_from_str("ABC 201")
    transcript = [course_1, course_2]

    solutions = list(area.solutions(student=Student.load(dict(courses=transcript)), exceptions=[]))
    course_sets = set(frozenset(s.solution.output) for s in solutions)
예제 #14
0
def test_ranges_eq_2(caplog):
    """ensure that a solution with fewer matching courses than requested is still proposed"""
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)
    ctx = RequirementContext()

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$eq": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [2]

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$neq": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$lt": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$lte": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2, 3]

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$gt": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [2]

    result = Assertion.load({
        "assert": {
            "count(courses)": {
                "$gte": 3
            }
        }
    },
                            c=c,
                            ctx=ctx,
                            data_type=DataType.Course,
                            path=['$']).input_size_range(maximum=2)
    assert list(result) == [2]