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
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
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
def test_missing_complex(schema, entity_id, period): """All same except for one missing item.""" fixture: Dict = { "outer": [ { "the_folder": { "inner": [{ "some_text": "foo" }] } }, { "the_folder": { "inner": [{ "some_text": "bar" }] } }, ] } observed: Dict = {} expected: Outcome = Outcome() expected.missings.append( MissingValue(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
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
def test_null_actual(schema, period, entity_id): """Everything should be reported as missing.""" fixture: Dict = { "some_multiple_text": ["x", "y"], "outer": { "some_multiple_text": ["xx", "yy"], "inner": { "some_multiple_text": ["xxx", "yyy"], } } } expected: Outcome = Outcome() expected.missings.append( MissingValue(entity_id, period, "/some_multiple_text", "MultipleText", json.dumps(fixture["some_multiple_text"]))) expected.missings.append( MissingValue(entity_id, period, "/outer/some_multiple_text", "MultipleText", json.dumps(fixture["outer"]["some_multiple_text"]))) expected.missings.append( MissingValue( 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, None, actual, period) crawl() assert expected == actual
def test_not_tested_complex(schema, entity_id, period): """All tested fields same, but one field is omitted from fixture.""" fixture: Dict = {} observed: Dict = { "outer": [ { "the_folder": { "inner": [{ "some_text": "foo" }] } }, { "the_folder": { "inner": [{ "some_text": "bar" }] } }, ] } expected: Outcome = Outcome() actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed, actual, period) crawl() assert expected == actual
def test_fixture_undefined_complex_raises(schema, period, entity_id): """Fixture contains an undefined field, resulting in an error state.""" """All same except for one missing item.""" fixture: Dict = { "outer": [ { "not_a_thing": { "inner": [{ "some_text": "foo" }] } }, { "the_folder": { "inner": [{ "some_text": "bar" }] } }, ] } observed: Dict = copy.deepcopy(fixture) outcome: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed, outcome, period) with pytest.raises(ValueError): crawl()
def test_null_actual(schema, period, entity_id): """Everything should be reported as missing.""" fixture: Dict = { "some_text": "foo", "outer": { "some_text": "bar", "inner": { "some_text": "baz" } } } expected: Outcome = Outcome() expected.missings.append( MissingValue(entity_id, period, "/some_text", "Text", "foo")) expected.missings.append( MissingValue(entity_id, period, "/outer/some_text", "Text", "bar")) expected.missings.append( MissingValue(entity_id, period, "/outer/inner/some_text", "Text", "baz")) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, None, actual, period) crawl() assert expected == actual
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
def test_fixture_undefined_raises(schema, period, entity_id, observation): """Fixture contains an undefined field, resulting in an error state.""" fixture: Dict = {"not a thing": "blah blah"} outcome: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, outcome, period) with pytest.raises(ValueError): crawl()
def test_fixture_undefined_records_invalid(schema, period, entity_id, observation): """Fixture contains an undefined field, resulting in an error state.""" fixture: Dict = { "not a thing": "blah blah" } expected: Outcome = Outcome() expected.invalids.append(InvalidPath(entity_id, "/not a thing", "immutable", "blah blah")) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period) crawl()
def test_empty_both(schema, period, entity_id): """Outcomes should remain empty.""" fixture: Dict = {} observed: Dict = {} expected: Outcome = Outcome() actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed, actual, period) crawl() assert expected == actual
def test_explicit_null_mismatch(schema, period, entity_id, f_val, o_val): fixture: Dict = {"some_text": f_val} observation: Dict = {"some_text": o_val} expected: Outcome = Outcome() expected.mismatches.append(ValueMismatch(entity_id, period, "/some_text", "Text", f_val, o_val)) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period) crawl() assert expected == actual
def test_explicit_null_missing(schema, period, entity_id): fixture: Dict = {"some_text": None} observation: Dict = {} expected: Outcome = Outcome() expected.missings.append(MissingValue(entity_id, period, "/some_text", "Text", None)) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period) crawl() assert expected == actual
def test_mismatch_complex(schema, entity_id, period): """All same except for one item.""" fixture: Dict = { "outer": [ { "the_folder": { "inner": [{ "some_multiple_text": ["foo"] }] } }, { "the_folder": { "inner": [{ "some_multiple_text": ["bar"] }] } }, ] } observed: Dict = { "outer": [ { "the_folder": { "inner": [{ "some_multiple_text": ["123", "456"] }] } }, { "the_folder": { "inner": [{ "some_multiple_text": ["bar"] }] } }, ] } expected: Outcome = Outcome() expected.mismatches.append( ValueMismatch(entity_id, period, "/outer", "List", json.dumps(fixture["outer"]), json.dumps(observed["outer"]))) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed, actual, period) crawl() assert expected == actual
def test_explicit_null_match(schema, period, entity_id): fixture: Dict = {"some_multiple_text": None} observation: Dict = {"some_multiple_text": None} expected: Outcome = Outcome() expected.matches.append( ValueMatch(entity_id, period, "/some_multiple_text", "MultipleText", None)) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period) crawl() assert expected == actual
def _crawl(self, schema: Schema, fixture: Composite, actual: Composite) -> None: for period in fixture.periods: f_period: Dict = fixture.content[period] a_period: Optional[Dict] = actual.content.get(period) crawl_period: CrawlPeriod = CrawlPeriod(self.entity_id, schema, f_period, a_period, self.outcome, period) crawl_period() if "immutable" in fixture.content: f_immutable: Dict = fixture.content["immutable"] a_immutable: Optional[Dict] = actual.content.get("immutable") crawl_immutable: CrawlImmutable = CrawlImmutable( self.entity_id, schema, f_immutable, a_immutable, self.outcome) crawl_immutable()
def test_explicit_null_mismatch(schema, period, entity_id, f_val, o_val): fixture: Dict = {"some_multiple_text": f_val} observation: Dict = {"some_multiple_text": o_val} expected: Outcome = Outcome() expected.mismatches.append( ValueMismatch(entity_id, period, "/some_multiple_text", "MultipleText", None if f_val is None else json.dumps(f_val), None if o_val is None else json.dumps(o_val))) actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observation, actual, period) crawl() assert expected == actual
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
def test_empty_fixture(schema, period, entity_id): """Outcomes should remain empty, even though actual has values.""" fixture: Dict = {} observed: Dict = { "some_text": "foo", "outer": { "some_text": "bar", "inner": { "some_text": "baz" } } } expected: Outcome = Outcome() actual: Outcome = Outcome() crawl: CrawlPeriod = CrawlPeriod(entity_id, schema, fixture, observed, actual, period) crawl() assert expected == actual
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