예제 #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_exception(capsys):
    journal_init(JOURNAL_CFG_FPATH, context)
    with pytest.raises(ZeroDivisionError):
        div_zero()

    captured = capsys.readouterr()
    # Clean up the output as logging subsystem adds exception information to the output.
    msg = captured[0].split("\n")[0]

    expected = {
        "tag": "JOURNAL_MSG_JSON",
        "format": "0.2.0",
        "objective": "int_add_objective",
        "context": {
            "service_ctx": {
                "name": "Test Service",
                "version": "0.1.0"
            },
            "implementation_ctx": {
                "name": "Simple Model",
                "version": "0.1.0"
            },
        },
        "arguments": {},
        "exception": {
            "type": "ZeroDivisionError",
            "msg": "division by zero",
            "file":
            "/home/some_user/projects/callable-journal/test/journal_test.py",
            "line": "52",
        },
    }

    msg = json.loads(msg)
    selector = EndsWithSelector("exception/file")
    normalizer = PathNormalizer(num_components=3, selectors=selector)
    result = Differ().diff(expected,
                           msg,
                           normalizers=normalizer,
                           max_col_width=50)
    print(result.support)
    if not result:
        print(result.support)
        assert False
예제 #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_default(capsys):
    journal_init(JOURNAL_CFG_FPATH, context)
    a, b = 10, 20
    c = int_add(a, b)
    assert c == a + b
    captured = capsys.readouterr()
    msg = captured[0]

    expected = {
        "tag": "JOURNAL_MSG_JSON",
        "format": "0.2.0",
        "objective": "int_add",
        "context": {
            "service_ctx": {
                "name": "Test Service",
                "version": "0.1.0"
            },
            "implementation_ctx": {
                "name": "Simple Model",
                "version": "0.1.0"
            },
        },
        "arguments": {
            "a": 10,
            "b": 20
        },
        "results": {
            "sum": 30
        },
    }

    msg = json.loads(msg)
    result = Differ().diff(expected, msg)
    if not result:
        print(result.support)
        assert False
예제 #5
0
def float_mismatch():
    differ = Differ()
    result = differ.diff(OBJ_1, OBJ_2)
    assert not result
    print(result.support)
예제 #6
0
def float_match():
    differ = Differ()
    float_round_normalizer = FloatRoundNormalizer(places=1)
    result = differ.diff(OBJ_1, OBJ_2, normalizers=[float_round_normalizer])
    assert result
    print(result.support)