def test_one_temporal(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {"t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context, schema, criteria)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    expected: List[Composite] = [copy.copy(composite_list[2])]
    del expected[0].content["period_2"]
    assert actual == expected
def test_t_and_i_temporal_wrong(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "I(folder)",
        "t_text_in_folder": "Not the real value"
    }
    the_filter: Filter = HasAllSpecificValues(context, schema, criteria)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    assert len(list(f_iter(composite_list))) == 0
def test_two_temporal_no_match(schema, composites, context):
    composite_list = list(composites)
    # Both values occur in Composite 3, but not in the same period
    criteria: Dict = {"t_text_in_folder": "1111", "t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              narrows=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    assert len(list(f_iter(composite_list))) == 0
def test_immutable(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "I(folder)"
    }
    the_filter: Filter = HasAllSpecificValues(context, schema, criteria)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    expected: List = [composite_list[3]]
    assert actual == expected
def test_two_temporal_match(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {"t_text_in_folder": "aaaa", "t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    expected: List[Composite] = make_c3_expected(composite_list)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected
def test_one_temporal(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {"t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              narrows=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    expected: List = [composite_list[2]]
    assert actual == expected
def test_no_narrow(schema, composites, context):
    composite_list = list(composites)
    expected: Dict = copy.deepcopy(composite_list[2].content)
    criteria: Dict = {"t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              narrows=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    outcome: List[Composite] = list(f_iter(composite_list))
    actual: Dict = outcome[0].content
    assert actual == expected
def test_temporal_and_immutable_match(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "I(folder)",
        "t_text_in_folder": "P1(folder)"
    }
    the_filter: Filter = HasAllSpecificValues(context, schema, criteria)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    expected: List[Composite] = [copy.copy(composite_list[3])]
    del expected[0].content["period_2"]
    assert actual == expected
def test_two_temporal_no_match(schema, composites, context):
    composite_list = list(composites)

    criteria: Dict = {"t_text_in_folder": "cccc", "t_text_in_root": "bbbb"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])

    # Because the criteria contain no immutable variables, only temporal periods are purged
    expected: List[Composite] = purge_all_periods(composite_list)

    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected
def test_immutable(schema, composites, context):
    composite_list = list(composites)
    expected: List[Composite] = [copy.copy(c) for c in composite_list]

    # Because the criteria contain immutable variables, everything is purged
    for composite in expected[:-1]:
        composite.content = {}

    criteria: Dict = {"i_text_in_folder": "I(folder)"}
    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected
def test_t_and_i_immutable_wrong(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "Not the real value",
        "t_text_in_folder": "P1(folder)"
    }

    # Because the immutable value is wrong in Composite 4, every period is purged in every composite
    expected: List[Composite] = [copy.copy(c) for c in composite_list]
    for composite in expected:
        composite.content = {}

    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected
def test_temporal_and_immutable_match(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "I(folder)",
        "t_text_in_folder": "P1(folder)"
    }

    # Because the criteria contain immutable variables, everything is purged for composites 1-3. For composite 4, the
    # non-matching period is also purged.
    expected: List[Composite] = [copy.copy(c) for c in composite_list]
    for composite in expected[:-1]:
        composite.content = {}
    del expected[3].content["period_2"]

    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected
def test_t_and_i_temporal_wrong(schema, composites, context):
    composite_list = list(composites)
    criteria: Dict = {
        "i_text_in_folder": "I(folder)",
        "t_text_in_folder": "Not the real value"
    }

    # Because the immutable value is right in Composite 4, the immutable values remain in that composite; everything
    # else is purged from all of the composites
    expected: List[Composite] = [copy.copy(c) for c in composite_list]
    for composite in expected[:-1]:
        composite.content = {}
    for period in expected[-1].periods:
        del expected[-1].content[period]

    the_filter: Filter = HasAllSpecificValues(context,
                                              schema,
                                              criteria,
                                              filters=False)
    f_iter: InMemoryFilterIterator = InMemoryFilterIterator([the_filter])
    actual: List[Composite] = list(f_iter(composite_list))
    assert actual == expected