예제 #1
0
 def testMatchesDictionaryContainingMultipleKeysWithMatchingValues(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries("a", equal_to(1), "b", equal_to(2)), target)
     self.assert_matches("has c & a", has_entries("c", equal_to(3), "a", equal_to(1)), target)
     self.assert_does_not_match(
         "no d:3", has_entries("b", equal_to(3), "d", equal_to(3)), target
     )
예제 #2
0
 def testMatchesUsingSingleDictionaryArgument(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries({"a": equal_to(1), "b": equal_to(2)}), target)
     self.assert_matches("has c & a", has_entries({"c": equal_to(3), "a": equal_to(1)}), target)
     self.assert_does_not_match(
         "no d:3", has_entries({"b": equal_to(2), "d": equal_to(3)}), target
     )
예제 #3
0
    def testMatchesDictLike(self):
        class DictLike(object):
            def __getitem__(self, key):
                return "value: " + str(key)

            def __contains__(self, key):
                return True

        self.assert_matches(
            "matches a dictionary-like object", has_entries("a", equal_to("value: a")), DictLike()
        )
예제 #4
0
def then_i_get_a_list_containing_the_following_cti_profiles(step):
    profile_response = world.response.data
    expected_profiles = _perform_casts(step.hashes)

    assert_that(profile_response, has_key('items'))
    profiles = profile_response['items']

    for expected_profile in expected_profiles:
        corresponding = _get_by_id(profiles, int(expected_profile['id']))
        assert_that(corresponding, not_none())
        assert_that(corresponding, has_entries(expected_profile))
예제 #5
0
 def testDescribeMismatchOfNonDictionaryShowsActualArgument(self):
     self.assert_describe_mismatch("'bad' is not a mapping object", has_entries("a", 1), "bad")
예제 #6
0
 def testMismatchDescriptionOfDictionaryWithNonMatchingValue(self):
     self.assert_mismatch_description("value for 'a' was <2>", has_entries("a", 1), {"a": 2})
예제 #7
0
 def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
     self.assert_no_mismatch_description(has_entries("a", 1), {"a": 1})
예제 #8
0
 def testHasReadableDescription(self):
     self.assert_description(
         "a dictionary containing {'a': <1>, 'b': <2>}", has_entries("a", 1, "b", 2)
     )
예제 #9
0
 def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries("a", 1, "b", 2), target)
     self.assert_matches("has c & a", has_entries("c", 3, "a", 1), target)
     self.assert_does_not_match("no d:4", has_entries("b", 3, "d", 4), target)
예제 #10
0
 def testDescribeMismatchOfDictionaryWithNonMatchingValue(self):
     self.assert_describe_mismatch("value for 'a' was <2>", has_entries("a", 1), {"a": 2})
예제 #11
0
 def testMatchesKwargsWithImplicitEqualTo(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries(a=1, b=2), target)
     self.assert_matches("has c & a", has_entries(c=3, a=1), target)
     self.assert_does_not_match("no d:3", has_entries(b=2, d=3), target)
예제 #12
0
 def testMatchesUsingKwargs(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries(a=equal_to(1), b=equal_to(2)), target)
     self.assert_matches("has c & a", has_entries(c=equal_to(3), a=equal_to(1)), target)
     self.assert_does_not_match("no d:3", has_entries(b=equal_to(2), d=equal_to(3)), target)
예제 #13
0
 def testMatcheSingleDictionaryArgumentWithImplicitEqualTo(self):
     target = {"a": 1, "b": 2, "c": 3}
     self.assert_matches("has a & b", has_entries({"a": 1, "b": 2}), target)
     self.assert_matches("has c & a", has_entries({"c": 3, "a": 1}), target)
     self.assert_does_not_match("no d:3", has_entries({"b": 2, "d": 3}), target)
예제 #14
0
 def testDoesNotMatchNonDictionary(self):
     self.assert_does_not_match("non-dictionary", has_entries("a", equal_to(1)), object())
예제 #15
0
def then_i_get_a_cti_profile_with_the_following_parameters(step):
    profile_response = world.response.data
    expected_profile = _perform_casts(step.hashes)[0]
    assert_that(profile_response, has_entries(expected_profile))
예제 #16
0
 def testMatchesDictionaryContainingSingleKeyWithMatchingValue(self):
     target = {"a": 1, "b": 2}
     self.assert_matches("has a:1", has_entries("a", equal_to(1)), target)
     self.assert_matches("has b:2", has_entries("b", equal_to(2)), target)
     self.assert_does_not_match("no b:3", has_entries("b", equal_to(3)), target)
     self.assert_does_not_match("no c:2", has_entries("c", equal_to(2)), target)
예제 #17
0
 def testDescribeMismatchOfDictionaryWithoutKey(self):
     d = {"a": 1, "c": 3}
     self.assert_describe_mismatch("no 'b' key in <%s>" % (d,), has_entries("a", 1, "b", 2), d)