예제 #1
0
def selector_multiple_match():
    differ = Differ()

    a_selector = ListLastComponentSelector(component_names=["a"])
    b_selector = ListLastComponentSelector(component_names=["b"])
    float_round_normalizer = FloatRoundNormalizer(
        places=1, selectors=[a_selector, b_selector])

    result = differ.diff(OBJ_1, OBJ_2, normalizers=[float_round_normalizer])
    assert result
    print(result.support)
예제 #2
0
def test_not_sorted():
    unsorted = {"a": [2, 1], "b": [2, 1]}
    expected = {"a": [1, 2], "b": [1, 2]}
    selector = ListLastComponentSelector(component_names=["a"])
    sorter = FilteringNoSortListSorter(selectors=selector)
    sorted_dict = Sorter.sorted(unsorted, sorters=sorter)
    assert json.dumps(sorted_dict) == json.dumps(expected)
예제 #3
0
def float_two_precision_match():
    differ = Differ()
    # Normalize the 'a' element to 1 decimal place.
    a_selector = ListLastComponentSelector(component_names=["a"])
    one_float_round_normalizer = FloatRoundNormalizer(places=1,
                                                      selectors=[a_selector])

    # Normalize the 'b' element to 2 decimal places.
    b_selector = ListLastComponentSelector(component_names=["b"])
    two_float_round_normalizer = FloatRoundNormalizer(places=2,
                                                      selectors=[b_selector])

    result = differ.diff(
        OBJ_1,
        OBJ_2,
        normalizers=[two_float_round_normalizer, one_float_round_normalizer],
    )
    assert result
    print(result.support)
예제 #4
0
def test_no_sort_path_no_match():
    selector = ListLastComponentSelector(["b"])
    sorter = NoSortListSorter(selectors=selector)
    path = Path("a")
    result = sorter.sorted([2, 1], path, sorters=[sorter])
    assert result == [1, 2]
예제 #5
0
def test_negative():
    selector = ListLastComponentSelector(["a"])
    neg_selector = NegativeSelector(selector=selector)
    assert not neg_selector.match(A_TEST_PATH, [neg_selector])
    assert neg_selector.match(B_TEST_PATH, [neg_selector])
예제 #6
0
def test_chained():
    any_selector = ListLastComponentSelector(["c"])
    regex_selector = RegExSelector("a/b")
    assert regex_selector.match(BC_TEST_PATH, [any_selector, regex_selector])
예제 #7
0
def test_list_any_selector_empty_list():
    selector = ListLastComponentSelector([])
    assert not selector.match(AB_TEST_PATH, [selector])
예제 #8
0
def test_list_last_selector_base():
    selector = ListLastComponentSelector(["a"])
    assert selector.match(A_TEST_PATH, [selector])
    assert not selector.match(B_TEST_PATH, [selector])
예제 #9
0
def test_round_normalizer_no_match():
    path = Path("a")
    selector = ListLastComponentSelector(["b"])
    normalizer = FloatRoundNormalizer(2, selectors=selector)
    result = normalizer.normalize(1.0001, path, normalizers=[normalizer])
    assert result == 1.0001
예제 #10
0
def test_no_sort():
    selector = ListLastComponentSelector(component_names=["no_sort"])
    sorter = NoSortListSorter(selectors=selector)
    sorted_dict = Sorter.sorted(NO_SORT, sorters=sorter)
    assert json.dumps(sorted_dict) == json.dumps(NO_SORT_RESULT)