Beispiel #1
0
    def test_matches_by_match_failure_with_message(self):

        matcher = re.compile('ab.*')
        try:
            Assert.matches("Absolutely", matcher, msg="failure message")
        except AssertionError as e:
            Assert.equal(e.msg, "'Absolutely' did not match 'ab.*'. failure message")
Beispiel #2
0
 def test_iterate_deep_equal(self):
     dict1 = {
         'a_string': 'fabulous',
         'an_int': 42,
         'a_float': 15.234,
         'enum_val': 'cat',
         'extra': 'value1'
     }
     dict2 = {
         'a_string': 'stupendous',
         'an_int': 76,
         'a_float': 678.834,
         'enum_val': 'dog',
         'extra': 'value2'
     }
     dict3 = {
         'a_string': 'superfluous',
         'an_int': 85,
         'a_float': 79.32,
         'enum_val': 'mouse',
         'extra': 'value3'
     }
     actual = [dict1, dict2, dict3]
     template = {
         'a_string': Expectation(Assert.matches, '.*ous$'),
         'an_int': Expectation(Assert.greater, 0),
         'a_float': Expectation(Assert.less, 10000),
         'enum_val': Expectation(Assert.contains, ['cat', 'dog', 'mouse'])
     }
     Assert.iterate(Assert.deep_equal, actual, template, ignore_extra_keys=True)
Beispiel #3
0
 def test_dict_does_not_contain_key_failure_with_message(self):
     dict3 = {
             'd': 'dvalue',
             'e': 'evalue',
             'f': 'fvalue',
         }
     try:
         Assert.does_not_contain('d', dict3, msg="failure message")
     except AssertionError as e:
         Assert.equal(e.msg, "%s should not be found in %s. failure message" % ('d', dict3))
Beispiel #4
0
 def test_deep_equals_ignore_extra_keys(self):
     # don't try to do it this way, it doesn't work
     # this is why we need Assert.complexly that does IGNORE_EXTRA_KEYS
     actual = {
         'an_integer': 32,
         'a_string': 'stupendous',
         'a_float': 14.34,
         'a_list': ['cat', 'dog', 'mouse'],
     }
     expected = {
         'a_string': 'stupendous',
     }
     Assert.deep_equal(actual, expected, ignore_extra_keys=True)
Beispiel #5
0
 def test_deep_equal_failure_missing_key_without_message(self):
     actual = {
         'an_integer': 32,
         'a_string': 'stupendous',
         'a_list': ['cat', 'dog', 'mouse'],
     }
     expected = {
         'an_integer': 32,
         'a_string': 'stupendous',
         'a_float': 14.342,
         'a_list': ['cat', 'dog', 'mouse'],
     }
     try:
         Assert.deep_equal(actual, expected)
     except AssertionError as e:
         expected = "expected keys ['a_float'] are absent in actual"
         Assert.contains(expected, e.msg, )
Beispiel #6
0
 def test_deep_equal_failure_extra_keys_with_message(self):
     actual = {
         'an_integer': 32,
         'a_string': 'stupendous',
         'a_float': 14.34,
         'a_list': ['cat', 'dog', 'mouse'],
         'a_thing': 'thing'
     }
     expected = {
         'an_integer': 32,
         'a_string': 'stupendous',
         'a_float': 14.342,
         'a_list': ['cat', 'dog', 'mouse'],
     }
     try:
         Assert.deep_equal(actual, expected, msg="not complexly equal")
     except AssertionError as e:
         Assert.equal(e.msg, "not complexly equal")
Beispiel #7
0
 def test_list_of_dicts_does_not_contain_dict(self):
     dict1 = {
             'a': 'avalue',
             'b': 'bvalue',
             'c': 'cvalue',
         }
     dict2 = {
             'a': 'dvalue',
             'b': 'evalue',
             'c': 'fvalue',
         }
     dict3 = {
             'd': 'dvalue',
             'e': 'evalue',
             'f': 'fvalue',
         }
     list_of_dicts = [ dict1, dict2 ]
     Assert.does_not_contain(dict3, list_of_dicts)
Beispiel #8
0
 def test_list_of_dicts_does_not_contain_dict_failure_no_message(self):
     dict1 = {
             'a': 'avalue',
             'b': 'bvalue',
             'c': 'cvalue',
         }
     dict2 = {
             'a': 'dvalue',
             'b': 'evalue',
             'c': 'fvalue',
         }
     dict3 = {
             'd': 'dvalue',
             'e': 'evalue',
             'f': 'fvalue',
         }
     list_of_dicts = [ dict1, dict2, dict3 ]
     try:
         Assert.does_not_contain(dict3, list_of_dicts)
     except AssertionError as e:
         Assert.equal(e.msg, "%s should not be found in %s. " % (dict3, list_of_dicts))
Beispiel #9
0
 def test_between_failure_without_message(self):
     try:
         Assert.between('along', 'alone', 'allow')
     except AssertionError as e:
         Assert.equal(e.msg, "along is not between alone and allow. ")
Beispiel #10
0
 def test_nearly_float(self):
     Assert.nearly(3.14, 3.14379, 0.005)
Beispiel #11
0
 def test_rounded_up(self):
     Assert.rounded(11, 10.8)
     Assert.rounded(14.53, 14.529)
Beispiel #12
0
 def test_iterate_matches(self):
     Assert.iterate(Assert.matches, ['stupendous', 'superfluous', 'sanctimonious'], '.*ous$')
Beispiel #13
0
 def test_nearly_failure_with_message(self):
     try:
         Assert.nearly(3.15, 3.14159265, "pi rounded improperly")
     except AssertionError as e:
         Assert.equal(e.msg, "3.15 is not within 0.005 of 3.14159256. pi rounded improperly")
Beispiel #14
0
 def test_matches_by_match(self):
     matcher = re.compile('ab.*', re.IGNORECASE)
     Assert.matches("Absolutely", matcher)
Beispiel #15
0
 def test_rounded_failure_no_message(self):
     try:
         Assert.rounded(14.983, 14.985)
     except AssertionError as e:
         Assert.equal(e.msg, "neither 14.983 nor 14.985 is a round of the other. ")
Beispiel #16
0
 def test_rounded_failure_with_message(self):
     try:
         Assert.rounded(13, 19, msg="failure message")
     except AssertionError as e:
         Assert.equal(e.msg, "neither 13 nor 19 is a round of the other. failure message")
Beispiel #17
0
 def test_rounded_down(self):
     Assert.rounded(14.53, 14.534)
     Assert.rounded(11, 11.3)
Beispiel #18
0
 def test_string_does_not_contain_letter(self):
     Assert.does_not_contain('a', 'bcd')
Beispiel #19
0
 def test_matches_by_string_begining(self):
     Assert.matches('absolutely', '^ab')
Beispiel #20
0
 def test_nearly_failure_without_message(self):
     try:
         Assert.nearly(34, 42, 3)
     except AssertionError as e:
         Assert.equal(e.msg, "34 is not within 3 of 42. ")
Beispiel #21
0
 def test_contains_failure_without_message(self):
     try:
         Assert.contains("a", "bcd")
     except AssertionError as e:
         Assert.equal(e.msg, "a is not found in bcd. ")
Beispiel #22
0
 def test_matches_by_string_end(self):
     Assert.matches('absolutely', 'ly$')
Beispiel #23
0
 def test_list_of_strings_does_not_contain_string(self):
     Assert.does_not_contain('turtle', ['dog', 'cat', 'guiny pig'])
Beispiel #24
0
 def test_matches_by_string_failure_no_message(self):
     try:
         Assert.matches('Absolutely', '^sol')
     except AssertionError as e:
         Assert.equal(e.msg, "'Absolutely' did not match '^sol'. ")
Beispiel #25
0
 def test_dict_does_not_contain_key(self):
     Assert.does_not_contain('a', { 'b': 'bvalue', 'c': 'cvalue', 'd': 'dvalue' })
Beispiel #26
0
 def test_between(self):
     Assert.between(7, 5, 10)
Beispiel #27
0
 def test_between_failure_with_message(self):
     try:
         Assert.between(11, 5, 10, msg='failure message')
     except AssertionError as e:
         Assert.equal(e.msg, "11 is not between 5 and 10. failure message")
Beispiel #28
0
 def test_nearly_integer(self):
     Assert.nearly(2345, 2346, 1)