def test_list_elements_comma_separated():
    """Elements enumerated in config settings are parsed as lists."""
    config_dict["list_item_separator"] = ","
    sc = TAPStatementTemplate()
    sc.propertyID = "dcterms:creator,dcterms:date"
    sc._parse_elements_configured_as_list_elements(config_dict)
    assert sc.propertyID == ["dcterms:creator", "dcterms:date"]
def test_mandatory_and_repeatable_default_to_empty_strings():
    """The Boolean elements remain empty strings if no value is declared."""
    sc = TAPStatementTemplate()
    sc.propertyID = "wdt:P31"
    sc._normalize_booleans_mandatory_repeatable()
    assert sc.mandatory == ""
    assert sc.repeatable == ""
def test_valueConstraintType_picklist_parse_case_insensitive():
    """Value constraint types are case-insensitive."""
    st = TAPStatementTemplate()
    st.propertyID = "dcterms:creator"
    st.valueConstraintType = "PICKLIST"
    st.valueConstraint = "one two          three"  # extra whitespace
    st._valueConstraintType_picklist_parse(config_dict)
    assert st.valueConstraint == ["one", "two", "three"]
def test_valueConstraintType_picklist_parse():
    """If valueConstraintType picklist, valueConstraint parsed on whitespace."""
    st = TAPStatementTemplate()
    st.propertyID = "dcterms:creator"
    st.valueConstraintType = "picklist"
    st.valueConstraint = "one two three"
    st._valueConstraintType_picklist_parse(config_dict)
    assert st.valueConstraint == ["one", "two", "three"]
Example #5
0
def test_warn_if_valueNodeType_literal_used_with_any_value_shape():
    """@@@"""
    sc = TAPStatementTemplate()
    sc.propertyID = ":status"
    sc.valueNodeType = "literal"
    sc.valueShape = "Person"
    sc._valueDataType_warn_if_valueNodeType_literal_used_with_any_valueShape()
    assert len(sc.state_warns) == 1
Example #6
0
def test_warn_if_valueConstraintType_pattern_used_with_any_value_shape():
    """Regular expressions cannot conform to value shapes."""
    sc = TAPStatementTemplate()
    sc.propertyID = ":status"
    sc.valueConstraintType = "pattern"
    sc.valueShape = "Person"
    sc._valueConstraintType_pattern_warn_if_used_with_value_shape()
    assert len(sc.state_warns) == 1
def test_valueConstraintType_languagetag_parse():
    """If valueConstraintType list, valueConstraint parsed on whitespace."""
    sc = TAPStatementTemplate()
    sc.propertyID = "dcterms:creator"
    sc.valueConstraintType = "languagetag"
    sc.valueConstraint = "fr it de"
    sc._valueConstraintType_languageTag_parse(config_dict)
    assert sc.valueConstraint == ["fr", "it", "de"]
def test_valueConstraintType_pattern_warn_if_not_valid_regex():
    """For valueConstraintType pattern, warns if valueConstraint not valid regex."""
    sc = TAPStatementTemplate()
    sc.propertyID = ":status"
    sc.valueConstraintType = "pattern"
    sc.valueConstraint = "approved_(*"
    sc._valueConstraintType_pattern_warn_if_valueConstraint_not_valid_regex()
    assert len(sc.state_warns) == 1
def test_warn_if_propertyID_not_URI():
    """In DCTAP, propertyID _should_ be an IRI."""
    sc = TAPStatementTemplate()
    sc.propertyID = "P31"
    sc._warn_if_propertyID_or_valueDataType_not_IRIlike()
    print(sc.state_warns)
    print(dict(sc.state_warns))
    print(len(dict(sc.state_warns)))
    assert len(dict(sc.state_warns)) == 1
def test_mandatory_repeatable_true_given_supported_boolean_values():
    """Literal 'True' (case-insensitive) is a supported Boolean value."""
    sc = TAPStatementTemplate()
    sc.propertyID = "wdt:P31"
    sc.mandatory = "true"
    sc.repeatable = "TRUE"
    sc._normalize_booleans_mandatory_repeatable()
    assert sc.mandatory is "true"
    assert sc.repeatable is "true"
def test_mandatory_and_repeatable_one_zero_normalized_to_true_false():
    """The integers 0 and 1 are supported Boolean values."""
    sc = TAPStatementTemplate()
    sc.propertyID = "wdt:P31"
    sc.mandatory = "1"
    sc.repeatable = "0"
    sc._normalize_booleans_mandatory_repeatable()
    assert sc.mandatory is "true"
    assert sc.repeatable is "false"
def test_list_elements_single_space_is_default():
    """Space is default list item separator."""
    sc = TAPStatementTemplate()
    sc.propertyID = "dcterms:creator dcterms:date"
    sc.valueNodeType = "iri bnode"
    sc.valueDataType = "xsd:date xsd:time"
    sc.valueShape = "a b c d"
    sc._parse_elements_configured_as_list_elements(config_dict)
    assert sc.propertyID == ["dcterms:creator", "dcterms:date"]
    assert sc.valueNodeType == ["iri", "bnode"]
    assert sc.valueDataType == ["xsd:date", "xsd:time"]
    assert sc.valueShape == ["a", "b", "c", "d"]
def test_list_elements():
    """Elements enumerated in config settings are parsed as lists."""
    config_dict["list_item_separator"] = " "
    sc = TAPStatementTemplate()
    sc.propertyID = "dcterms:creator dcterms:date"
    sc.valueNodeType = "iri bnode"
    sc.valueDataType = "xsd:date xsd:time"
    sc.valueShape = "a b c d"
    sc._parse_elements_configured_as_list_elements(config_dict)
    assert sc.propertyID == ["dcterms:creator", "dcterms:date"]
    assert sc.valueNodeType == ["iri", "bnode"]
    assert sc.valueDataType == ["xsd:date", "xsd:time"]
    assert sc.valueShape == ["a", "b", "c", "d"]
def test_mandatory_and_repeatable_raise_warn_unsupported_boolean_values():
    """@@@"""
    sc = TAPStatementTemplate()
    sc.propertyID = "dc:creator"
    sc.mandatory = "WAHR"
    sc.repeatable = "WAHR"
    sc._normalize_booleans_mandatory_repeatable()
    print(sc.state_warns)
    print(dict(sc.state_warns))
    print(len(dict(sc.state_warns)))
    print(f"Mandatory: {sc.mandatory}")
    print(f"Repeatable: {sc.repeatable}")
    assert len(sc.state_warns) == 2
    assert sc.mandatory is "WAHR"
    assert sc.repeatable is "WAHR"
def test_valueConstraintType_pattern_is_valid_regex():
    """For valueConstraintType pattern, valueConstraint must be valid regex."""
    sc = TAPStatementTemplate()
    sc.propertyID = ":status"
    sc.valueConstraintType = "pattern"
    sc.valueConstraint = "approved_*"
    sc._valueConstraintType_pattern_warn_if_valueConstraint_not_valid_regex()
    assert sc.valueConstraint
    sc.valueConstraint = "/approved_*/"
    sc._valueConstraintType_pattern_warn_if_valueConstraint_not_valid_regex()
    assert sc.valueConstraint == "/approved_*/"
    sc.valueConstraint = "^2020 August"
    sc._valueConstraintType_pattern_warn_if_valueConstraint_not_valid_regex()
    assert sc.valueConstraint
    sc.valueConstraint = "'confidential'"
    sc._valueConstraintType_pattern_warn_if_valueConstraint_not_valid_regex()
    assert sc.valueConstraint == "'confidential'"
def test_valueConstraintType_warn_if_used_without_valueConstraint():
    sc = TAPStatementTemplate()
    sc.propertyID = ":status"
    sc.valueConstraintType = "pattern"
    sc._valueConstraintType_warn_if_used_without_valueConstraint()
    assert len(sc.state_warns) == 1