def value(rhs: RightHandSideValueType) -> RightHandSideValue: if isinstance(rhs, RightHandSideValue): return rhs if Null.accepts_rhs(rhs): return Null() if String.accepts_rhs(rhs): return String(rhs) if Number.accepts_rhs(rhs): return Number(rhs) if DateTime.accepts_rhs(rhs): return DateTime(rhs) if Boolean.accepts_rhs(rhs): return Boolean(rhs) if Collection.accepts_rhs(rhs): return Collection(rhs) if Mapping.accepts_rhs(rhs): return Mapping(rhs) raise TypeError('Right-hand side value type is not supported: {}'.format( type(rhs).__name__))
def test_string_match_should_not_accept_invalid_lhs(lhs): with pytest.raises(LeftHandSideTypeError) as e: String('foo.bar').match(lhs) assert '[String.match] Could not apply left-hand side <{}>'.format( type(lhs).__name__) in str(e.value)
def test_string_should_not_accept_invalid_rhs(rhs): with pytest.raises(RightHandSideTypeError) as e: String(rhs) assert '[String] Invalid right-hand side <{}>'.format( type(rhs).__name__) in str(e.value)
def test_empty_string_rhs_should_match_string_lhs(lhs): assert String('').match(lhs) is True
def test_empty_string_rhs_should_be_equal_to_string_lhs(lhs): assert String('').equal(lhs) is True
def test_string_rhs_should_not_match_string_lhs(rhs, lhs): assert String(rhs).match(lhs) is False
def test_string_rhs_should_not_be_equal_to_string_lhs(rhs, lhs): assert String(rhs).equal(lhs) is False
def test_string_rhs_should_be_equal_to_string_lhs(value): assert String(value).equal(value) is True