Beispiel #1
0
def test_get_enums():
    s = Schema({"properties": {"a": {"enum": ["x"]}, "b": {"enum": ["y"]}}})
    assert s.get_enums() == ["a", "b"]
    s = Schema({"properties": {"a": {"type": "string", "enum": ["x"]}}})
    assert s.get_enums() == ["a"]
    s = Schema({"properties": {"a": {"type": "string"}}})
    assert not s.get_enums()
Beispiel #2
0
def basic_json_schema(data_source: str,
                      items_numbers: List[int] = None) -> Schema:
    """Print a json schema based on the provided job_key and item numbers

    Args:
        data_source: a collection or job key
        items_numbers: array of item numbers to create schema from
    """
    schema = create_json_schema(data_source, items_numbers)
    return Schema(schema)
Beispiel #3
0
def test_schema(get_schema):
    s = Schema(get_schema)
    assert s.allowed_tags == {
        "unique",
        "category",
        "name_field",
        "product_url_field",
        "product_price_field",
        "product_price_was_field",
    }
    assert s.raw == get_schema
    assert not s.enums
    assert not s.tags
Beispiel #4
0
def test_schema_repr():
    assert Schema({
        "definitions": {
            "float": {
                "pattern": r"^-?[0-9]+\.[0-9]{2}$"
            }
        },
        "properties": {
            "name": {}
        },
        "additionalProperties": False,
    }).__repr__() == (
        "{'additionalProperties': False,\n"
        " 'definitions': {'float': {'pattern': '^-?[0-9]+\\\\.[0-9]{2}$'}},\n"
        " 'properties': {'name': {}}}")
Beispiel #5
0
def test_dqr_empty_report(mocker, get_job_items, get_schema):
    mocker.patch(
        "arche.data_quality_report.DataQualityReport.plot_to_notebook",
        autospec=True)
    mocker.patch(
        "arche.tools.api.get_response_status_count",
        return_value=(10, 0, 0, 0),
        autospec=True,
    )
    mocker.patch("arche.tools.api.get_runtime_s",
                 return_value=60,
                 autospec=True)
    mocker.patch("arche.tools.api.get_items_count",
                 return_value=1000,
                 autospec=True)
    mocker.patch("arche.tools.api.get_requests_count",
                 return_value=1000,
                 autospec=True)
    dqr = DataQualityReport(items=get_job_items,
                            schema=Schema(get_schema),
                            report=Report())
    assert len(dqr.figures) == 4
Beispiel #6
0
def test_schema_json(capsys):
    s = Schema({
        "definitions": {
            "float": {
                "pattern": r"^-?[0-9]+\.[0-9]{2}$"
            }
        },
        "properties": {
            "name": {}
        },
        "additionalProperties": False,
    })
    s.json()
    assert (capsys.readouterr().out == """{
    "definitions": {
        "float": {
            "pattern": "^-?[0-9]+\\\\.[0-9]{2}$"
        }
    },
    "properties": {
        "name": {}
    },
    "additionalProperties": false
}\n""")
Beispiel #7
0
 def schema(self, schema_source):
     self.schema_source = schema_source
     self._schema = Schema(schema_source)
Beispiel #8
0
 def schema(self):
     if not self._schema and self.schema_source:
         self._schema = Schema(self.schema_source)
     return self._schema
Beispiel #9
0
def test_schema_tags(schema, expected_tags):
    assert Schema(schema).tags == expected_tags
Beispiel #10
0
def test_schema_no_properties(schema):
    with pytest.raises(ValueError) as excinfo:
        Schema(source=schema)
    assert str(excinfo.value) == "The schema does not have any 'properties'"