コード例 #1
0
def test_mismatch_simple(schema, period, entity_id):
    """All same except for one item."""
    fixture: Dict = {
        "some_text": "foo",
        "outer": {
            "some_text": "bar",
            "inner": {
                "some_text": "baz"
            }
        }
    }
    observation: Dict = {
        "some_text": "foo",
        "outer": {
            "some_text": "123",
            "inner": {
                "some_text": "baz"
            }
        }
    }

    # 2 matches, 1 mismatch
    expected: Outcome = Outcome()
    expected.matches.append(ValueMatch(entity_id, period, "/some_text", "Text", "foo"))
    expected.matches.append(ValueMatch(entity_id, period, "/outer/inner/some_text", "Text", "baz"))
    expected.mismatches.append(ValueMismatch(entity_id, period, "/outer/some_text", "Text", "bar", "123"))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period)
    crawl()

    assert expected == actual
コード例 #2
0
def test_both_have_everything_equal():
    p: Outcome = Outcome()

    p_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    p.matches.append(p_match)

    p_mismatch: ValueMismatch = ValueMismatch("the_entity_id", "the_period",
                                              "/path/to/var", "Text", "foo",
                                              "bar")
    p.mismatches.append(p_mismatch)

    p_missing: MissingValue = MissingValue("the_entity_id", "the_period",
                                           "/path/to/var", "Text", None)
    p.missings.append(p_missing)

    q: Outcome = Outcome()

    q_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    q.matches.append(q_match)

    q_mismatch: ValueMismatch = ValueMismatch("the_entity_id", "the_period",
                                              "/path/to/var", "Text", "foo",
                                              "bar")
    q.mismatches.append(q_mismatch)

    q_missing: MissingValue = MissingValue("the_entity_id", "the_period",
                                           "/path/to/var", "Text", None)
    q.missings.append(q_missing)

    assert p == q
コード例 #3
0
def test_identical_simple(schema, period, entity_id):
    """Everything should be reported as matches."""
    fixture: Dict = {
        "some_text": "foo",
        "outer": {
            "some_text": "bar",
            "inner": {
                "some_text": "baz"
            }
        }
    }
    observation: Dict = copy.deepcopy(fixture)

    # 3 Matches
    expected: Outcome = Outcome()
    expected.matches.append(ValueMatch(entity_id, period, "/some_text", "Text", "foo"))
    expected.matches.append(ValueMatch(entity_id, period, "/outer/some_text", "Text", "bar"))
    expected.matches.append(ValueMatch(entity_id, period, "/outer/inner/some_text", "Text", "baz"))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period)
    crawl()

    assert expected == actual
コード例 #4
0
def test_identical_simple(schema, period, entity_id):
    """Everything should be reported as matches."""
    fixture: Dict = {
        "some_multiple_text": ["x", "y"],
        "outer": {
            "some_multiple_text": ["xx", "yy"],
            "inner": {
                "some_multiple_text": ["xxx", "yyy"],
            }
        }
    }
    observation: Dict = copy.deepcopy(fixture)

    # 3 Matches
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, period, "/some_multiple_text", "MultipleText",
                   json.dumps(fixture["some_multiple_text"])))
    expected.matches.append(
        ValueMatch(entity_id, period, "/outer/some_multiple_text",
                   "MultipleText",
                   json.dumps(fixture["outer"]["some_multiple_text"])))
    expected.matches.append(
        ValueMatch(entity_id, period, "/outer/inner/some_multiple_text",
                   "MultipleText",
                   json.dumps(
                       fixture["outer"]["inner"]["some_multiple_text"])))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation,
                                     actual, period)
    crawl()

    assert expected == actual
コード例 #5
0
def test_identical_simple(schema, entity_id):
    """Everything should be reported as matches."""
    fixture: Dict = {
        "some_multiple_text": ["foo"],
        "outer": {
            "some_multiple_text": ["bar", "baq"],
            "inner": {
                "some_multiple_text": ["baz"]
            }
        }
    }
    observation: Dict = copy.deepcopy(fixture)

    # 3 Matches
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/some_multiple_text",
                   "MultipleText", json.dumps(["foo"])))
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/outer/some_multiple_text",
                   "MultipleText", json.dumps(["bar", "baq"])))
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/outer/inner/some_multiple_text",
                   "MultipleText", json.dumps(["baz"])))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture,
                                           observation, actual)
    crawl()

    assert expected == actual
コード例 #6
0
def test_matches(outcomes):
    expected: List[ValueMatch] = [
        ValueMatch("entity_2", "period_1",
                   "/temporal_folder/temporal_folder_text", "Text", "000"),
        ValueMatch("entity_4", "immutable", "/immutable_root_text", "Text",
                   "PQR"),
        ValueMatch("entity_4", "immutable",
                   "/immutable_folder/immutable_folder_text", "Text", "333"),
    ]
    actual: List[ValueMatch] = list(outcomes.matches)
    assert actual == expected
コード例 #7
0
def test_both_have_same_match_equal():
    p: Outcome = Outcome()
    p_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    p.matches.append(p_match)

    q: Outcome = Outcome()
    q_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    q.matches.append(q_match)

    assert p == q
コード例 #8
0
def test_each_has_different_match_not_equal():
    p: Outcome = Outcome()
    p_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    p.matches.append(p_match)

    q: Outcome = Outcome()
    q_match: ValueMatch = ValueMatch("the_entity_id", "a_different_period",
                                     "/path/to/var", "Text", "foo")
    q.matches.append(q_match)

    assert p != q
コード例 #9
0
def test_not_tested_simple(schema, period, entity_id):
    """One mismatch, one field omitted from fixture."""
    fixture: Dict = {
        "some_text": "foo",
        "outer": {
            "inner": {
                "some_text": "123"
            }
        }
    }
    observation: Dict = {
        "some_text": "foo",
        "outer": {
            "some_text": "bar",
            "inner": {
                "some_text": "baz"
            }
        }
    }

    # 1 match, 1 mismatch
    expected: Outcome = Outcome()
    expected.matches.append(ValueMatch(entity_id, period, "/some_text", "Text", "foo"))
    expected.mismatches.append(ValueMismatch(entity_id, period, "/outer/inner/some_text", "Text", "123", "baz"))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period)
    crawl()

    assert expected == actual
コード例 #10
0
def test_identical_complex(schema, period, entity_id):
    """Everything should be reported as matches."""
    fixture: Dict = {
        "outer": [
            {
                "the_folder": {
                    "inner": [{
                        "some_text": "foo"
                    }]
                }
            },
            {
                "the_folder": {
                    "inner": [{
                        "some_text": "bar"
                    }]
                }
            },
        ]
    }
    observed: Dict = copy.deepcopy(fixture)

    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, period, "/outer", "List",
                   json.dumps(fixture["outer"])))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed,
                                     actual, period)
    crawl()

    assert expected == actual
コード例 #11
0
def test_folder_na_present_as_none_mismatch(simple_track, empty_track,
                                            entity_id):
    """If the fixture has an explicit |--|NA|--| and the item is present in the actual with the value None, count it
    as a mismatch."""
    schema: Schema = Schema(empty_track, simple_track)
    fixture: Dict = {
        "some_text": "bar",
        "outer": {
            "some_text": POLYTROPOS_NA,
        }
    }
    observation: Dict = {
        "some_text": "bar",
        "outer": {
            "some_text": None,
        }
    }
    expected: Outcome = Outcome()
    expected.mismatches.append(
        ValueMismatch(entity_id, "immutable", "/outer/some_text", "Text",
                      POLYTROPOS_NA, None))
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/some_text", "Text", "bar"))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture,
                                           observation, actual)
    crawl()

    assert expected == actual
コード例 #12
0
def test_list_na_absent_match(complex_track, empty_track, entity_id):
    """If the fixture has an explicit |--|NA|--| and the item is missing in the actual, count it as a match."""
    schema: Schema = Schema(empty_track, complex_track)
    fixture: Dict = {
        "outer": [{
            "the_folder": {
                "inner": [{
                    "some_text": "foo"
                }, {
                    "some_text": POLYTROPOS_NA
                }],
            }
        }]
    }
    observed: Dict = {
        "outer": [{
            "the_folder": {
                "inner": [{
                    "some_text": "foo"
                }, {}],
            }
        }]
    }
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/outer", "List",
                   json.dumps(fixture["outer"])))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture,
                                           observed, actual)
    crawl()

    assert expected == actual
コード例 #13
0
def test_simple_na_present_with_value_mismatch(simple_track, empty_track, entity_id):
    """If the fixture has an explicit |--|NA|--| and the item is present in the actual with a non-null value, count it
    as a mismatch."""
    schema: Schema = Schema(empty_track, simple_track)
    fixture: Dict = {
        "some_multiple_text": POLYTROPOS_NA,
        "outer": {
            "some_multiple_text": ["foo", "bar"]
        }
    }
    observation: Dict = {
        "some_multiple_text": ["123"],
        "outer": {
            "some_multiple_text": ["foo", "bar"]
        }
    }
    expected: Outcome = Outcome()
    expected.mismatches.append(ValueMismatch(entity_id, "immutable", "/some_multiple_text", "MultipleText", POLYTROPOS_NA, json.dumps(["123"])))
    expected.matches.append(ValueMatch(entity_id, "immutable", "/outer/some_multiple_text", "MultipleText", json.dumps(["foo", "bar"])))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture, observation, actual)
    crawl()

    assert expected == actual
コード例 #14
0
def test_one_has_match_not_equal():
    p: Outcome = Outcome()
    p_match: ValueMatch = ValueMatch("the_entity_id", "the_period",
                                     "/path/to/var", "Text", "foo")
    p.matches.append(p_match)

    q: Outcome = Outcome()

    assert p != q
コード例 #15
0
ファイル: crawl.py プロジェクト: falconandy/polytropos
    def _record_match(self, path: ListType, data_type: str,
                      value: Optional[Any]) -> None:
        if not _is_simple_value(value):
            value = json.dumps(value, sort_keys=True)

        path_str = nesteddicts.path_to_str(path)
        match: ValueMatch = ValueMatch(self.entity_id, self.label, path_str,
                                       data_type, value)
        self.outcome.matches.append(match)
コード例 #16
0
def test_mismatch_simple(schema, period, entity_id):
    """All same except for one item."""
    fixture: Dict = {
        "some_multiple_text": ["x", "y"],
        "outer": {
            "some_multiple_text": ["xx", "yy"],
            "inner": {
                "some_multiple_text": ["xxx", "yyy"],
            }
        }
    }
    observation: Dict = {
        "some_multiple_text": ["x", "y"],
        "outer": {
            "some_multiple_text": ["aa"],
            "inner": {
                "some_multiple_text": ["xxx", "yyy"],
            }
        }
    }

    # 2 matches, 1 mismatch
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, period, "/some_multiple_text", "MultipleText",
                   json.dumps(fixture["some_multiple_text"])))
    expected.matches.append(
        ValueMatch(entity_id, period, "/outer/inner/some_multiple_text",
                   "MultipleText",
                   json.dumps(
                       fixture["outer"]["inner"]["some_multiple_text"])))
    expected.mismatches.append(
        ValueMismatch(entity_id, period, "/outer/some_multiple_text",
                      "MultipleText",
                      json.dumps(fixture["outer"]["some_multiple_text"]),
                      json.dumps(["aa"])))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation,
                                     actual, period)
    crawl()

    assert expected == actual
コード例 #17
0
def test_simple_na_absent_match(simple_track, empty_track, entity_id):
    """If the fixture has an explicit |--|NA|--| and the item is missing in the actual, count it as a match."""
    schema: Schema = Schema(empty_track, simple_track)
    fixture: Dict = {"some_text": POLYTROPOS_NA, "outer": {"some_text": "foo"}}
    observation: Dict = {"outer": {"some_text": "foo"}}
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/some_text", "Text",
                   POLYTROPOS_NA))
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/outer/some_text", "Text", "foo"))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture,
                                           observation, actual)
    crawl()

    assert expected == actual
コード例 #18
0
def test_whole_folder_absent_match(simple_track, empty_track, entity_id):
    """If the fixture has an explicit |--|NA|--| nested inside a folder, and the whole folder is absent, that is a match
    (at least for that variable)."""
    schema: Schema = Schema(empty_track, simple_track)
    fixture: Dict = {"some_text": "bar", "outer": {"some_text": POLYTROPOS_NA}}
    observation: Dict = {"some_text": "bar"}
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/outer/some_text", "Text",
                   POLYTROPOS_NA))
    expected.matches.append(
        ValueMatch(entity_id, "immutable", "/some_text", "Text", "bar"))

    actual: Outcome = Outcome()

    crawl: CrawlImmutable = CrawlImmutable(entity_id, schema, fixture,
                                           observation, actual)
    crawl()

    assert expected == actual
コード例 #19
0
def test_explicit_null_match(schema, period, entity_id):
    fixture: Dict = {"some_text": None}
    observation: Dict = {"some_text": None}

    expected: Outcome = Outcome()
    expected.matches.append(ValueMatch(entity_id, period, "/some_text", "Text", None))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period)
    crawl()

    assert expected == actual
コード例 #20
0
def test_not_tested_simple(schema, period, entity_id):
    """One mismatch, one field omitted from fixture."""
    fixture: Dict = {
        "some_multiple_text": ["x", "y"],
        "outer": {
            "inner": {
                "some_multiple_text": ["xxx", "yyy"],
            }
        }
    }
    observation: Dict = {
        "some_multiple_text": ["x", "y"],
        "outer": {
            "some_multiple_text": ["xx", "yy"],
            "inner": {
                "some_multiple_text": ["aaa"],
            }
        }
    }

    # 1 match, 1 mismatch
    expected: Outcome = Outcome()
    expected.matches.append(
        ValueMatch(entity_id, period, "/some_multiple_text", "MultipleText",
                   json.dumps(fixture["some_multiple_text"])))
    expected.mismatches.append(
        ValueMismatch(
            entity_id, period, "/outer/inner/some_multiple_text",
            "MultipleText",
            json.dumps(fixture["outer"]["inner"]["some_multiple_text"]),
            json.dumps(["aaa"])))

    actual: Outcome = Outcome()

    crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation,
                                     actual, period)
    crawl()

    assert expected == actual
コード例 #21
0
 def _record_match(self, path: ListType, data_type: str, value: Optional[Any]) -> None:
     path_str = nesteddicts.path_to_str(path)
     match: ValueMatch = ValueMatch(self.entity_id, self.label, path_str, data_type, value)
     self.outcome.matches.append(match)