def has_len(matcher): """Match len of a value. assert_that([1, 2], has_len(2)) will pass but assert_that([1, 2], has_len(1)) will fail with an assertion error. """ return has_feature("len", len, matcher)
def has_len(matcher): """Match len of a value. assert_that([1, 2], has_len(2)) will pass but assert_that([1, 2], has_len(1)) will fail with an assertion error. """ return has_feature("len", len, matcher)
def description_contains_description_of_property(): matcher = has_feature("name", lambda user: user.username, equal_to("bob")) assert_equal("name: 'bob'", matcher.describe())
def submatcher_is_coerced_to_matcher(): matcher = has_feature("name", lambda user: user.username, "bob") assert_equal(unmatched("name: was 'bobbity'"), matcher.match(User("bobbity")))
def explanation_of_mismatch_contains_mismatch_of_feature(): matcher = has_feature("name", lambda user: user.username, equal_to("bob")) assert_equal(unmatched("name: was 'bobbity'"), matcher.match(User("bobbity")))
def mismatches_when_feature_extraction_fails(): # TODO: return matcher = has_feature("name", lambda user: user.username, equal_to("bob")) assert_equal(unmatched(""), matcher.match("bobbity"))
def matches_when_feature_has_correct_value(): matcher = has_feature("name", lambda user: user.username, equal_to("bob")) assert_equal(matched(), matcher.match(User("bob")))
def has_str(matcher): return has_feature("str", str, matcher)