Exemplo n.º 1
0
def create_temporal_coverage(temporal: Mapping) -> PeriodOfTime:
    period = PeriodOfTime()

    period.start_date = parse_date(temporal["from"]).strftime("%Y-%m-%d")
    period.end_date = parse_date(temporal["to"]).strftime("%Y-%m-%d")

    return period
def test_to_graph_should_return_temporal_coverage() -> None:
    """It returns a temporal coverage graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    # Create PeriodOfTime:
    temporal_coverage = PeriodOfTime()
    temporal_coverage.start_date = "2019-12-31"
    temporal_coverage.end_date = "2020-12-31"
    # Add temporal_coverage to dataset:
    dataset.temporal_coverage = temporal_coverage

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:temporal [ a dct:PeriodOfTime ;
            dcat:startDate "2019-12-31"^^xsd:date ;
            dcat:endDate   "2020-12-31"^^xsd:date ;
        ]
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
def test_to_graph_should_return_start_date_as_graph() -> None:
    """It returns a start date graph isomorphic to spec."""
    period_of_time = PeriodOfTime()
    period_of_time.start_date = "2019-12-31"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    [] a dct:PeriodOfTime ;
        dcat:startDate "2019-12-31"^^xsd:date ;
    .
    """
    g1 = Graph().parse(data=period_of_time.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
def test_invalid_interval_end_date() -> None:
    """It does raise an InvalidDateIntervalError."""
    _period_of_time = PeriodOfTime()
    _period_of_time.end_date = "2020-04-06"
    with pytest.raises(InvalidDateIntervalError):
        _period_of_time.start_date = "2020-04-07"
def test_invalid_end_date() -> None:
    """It does raise an InvalidDateError."""
    _period_of_time = PeriodOfTime()
    with pytest.raises(InvalidDateError):
        _period_of_time.end_date = "9999-99-99"