예제 #1
0
파일: case.py 프로젝트: JWW81/stochss
    def assertItemsEqual(self, expected_seq, actual_seq, msg=None):
        """An unordered sequence specific comparison. It asserts that
        expected_seq and actual_seq contain the same elements. It is
        the equivalent of::

            self.assertEqual(sorted(expected_seq), sorted(actual_seq))

        Raises with an error message listing which elements of expected_seq
        are missing from actual_seq and vice versa if any.

        Asserts that each element has the same count in both sequences.
        Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.
        """
        try:
            expected = sorted(expected_seq)
            actual = sorted(actual_seq)
        except TypeError:
            # Unsortable items (example: set(), complex(), ...)
            expected = list(expected_seq)
            actual = list(actual_seq)
            missing, unexpected = unorderable_list_difference(expected, actual, ignore_duplicate=False)
        else:
            return self.assertSequenceEqual(expected, actual, msg=msg)

        errors = []
        if missing:
            errors.append("Expected, but missing:\n    %s" % safe_repr(missing))
        if unexpected:
            errors.append("Unexpected, but present:\n    %s" % safe_repr(unexpected))
        if errors:
            standardMsg = "\n".join(errors)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #2
0
파일: case.py 프로젝트: JWW81/stochss
    def assertNotAlmostEqual(self, first, second, places=None, msg=None, delta=None):
        """Fail if the two objects are equal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           between the two objects is less than the given delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most signficant digit).

           Objects that are equal automatically fail.
        """
        if delta is not None and places is not None:
            raise TypeError("specify delta or places not both")
        if delta is not None:
            if not (first == second) and abs(first - second) > delta:
                return
            standardMsg = "%s == %s within %s delta" % (safe_repr(first), safe_repr(second), safe_repr(delta))
        else:
            if places is None:
                places = 7
            if not (first == second) and round(abs(second - first), places) != 0:
                return
            standardMsg = "%s == %s within %r places" % (safe_repr(first), safe_repr(second), places)

        msg = self._formatMessage(msg, standardMsg)
        raise self.failureException(msg)
예제 #3
0
파일: case.py 프로젝트: 007lva/mmddpp
    def assertDictContainsSubset(self, expected, actual, msg=None):
        """Checks whether actual is a superset of expected."""
        missing = []
        mismatched = []
        for key, value in expected.iteritems():
            if key not in actual:
                missing.append(key)
            elif value != actual[key]:
                mismatched.append('%s, expected: %s, actual: %s' %
                                  (safe_repr(key), safe_repr(value),
                                   safe_repr(actual[key])))

        if not (missing or mismatched):
            return

        standardMsg = ''
        if missing:
            standardMsg = 'Missing: %s' % ','.join(safe_repr(m) for m in
                                                    missing)
        if mismatched:
            if standardMsg:
                standardMsg += '; '
            standardMsg += 'Mismatched values: %s' % ','.join(mismatched)

        self.fail(self._formatMessage(msg, standardMsg))
예제 #4
0
파일: case.py 프로젝트: JWW81/stochss
 def assertNotEqual(self, first, second, msg=None):
     """Fail if the two objects are equal as determined by the '=='
        operator.
     """
     if not first != second:
         msg = self._formatMessage(msg, "%s == %s" % (safe_repr(first), safe_repr(second)))
         raise self.failureException(msg)
예제 #5
0
파일: case.py 프로젝트: yekhneek/django-old
    def assertNotAlmostEqual(self,
                             first,
                             second,
                             places=None,
                             msg=None,
                             delta=None):
        """Fail if the two objects are equal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           between the two objects is less than the given delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most signficant digit).

           Objects that are equal automatically fail.
        """
        if delta is not None and places is not None:
            raise TypeError("specify delta or places not both")
        if delta is not None:
            if not (first == second) and abs(first - second) > delta:
                return
            standardMsg = '%s == %s within %s delta' % (
                safe_repr(first), safe_repr(second), safe_repr(delta))
        else:
            if places is None:
                places = 7
            if not (first
                    == second) and round(abs(second - first), places) != 0:
                return
            standardMsg = '%s == %s within %r places' % (
                safe_repr(first), safe_repr(second), places)

        msg = self._formatMessage(msg, standardMsg)
        raise self.failureException(msg)
예제 #6
0
파일: case.py 프로젝트: yekhneek/django-old
    def assertDictContainsSubset(self, expected, actual, msg=None):
        """Checks whether actual is a superset of expected."""
        missing = []
        mismatched = []
        for key, value in expected.iteritems():
            if key not in actual:
                missing.append(key)
            else:
                try:
                    are_equal = (value == actual[key])
                except UnicodeDecodeError:
                    are_equal = False
                if not are_equal:
                    mismatched.append('%s, expected: %s, actual: %s' %
                                      (safe_repr(key), safe_repr(value),
                                       safe_repr(actual[key])))

        if not (missing or mismatched):
            return

        standardMsg = ''
        if missing:
            standardMsg = 'Missing: %s' % ','.join(
                [safe_repr(m) for m in missing])
        if mismatched:
            if standardMsg:
                standardMsg += '; '
            standardMsg += 'Mismatched values: %s' % ','.join(mismatched)

        self.fail(self._formatMessage(msg, standardMsg))
예제 #7
0
    def assertHTMLNotEqual(self, html1, html2, msg=None):
        """Asserts that two HTML snippets are not semantically equivalent."""
        dom1 = assert_and_parse_html(self, html1, msg, u"First argument is not valid HTML:")
        dom2 = assert_and_parse_html(self, html2, msg, u"Second argument is not valid HTML:")

        if dom1 == dom2:
            standardMsg = "%s == %s" % (safe_repr(dom1, True), safe_repr(dom2, True))
            self.fail(self._formatMessage(msg, standardMsg))
예제 #8
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertNotEqual(self, first, second, msg=None):
     """Fail if the two objects are equal as determined by the '=='
        operator.
     """
     if not first != second:
         msg = self._formatMessage(
             msg, '%s == %s' % (safe_repr(first), safe_repr(second)))
         raise self.failureException(msg)
예제 #9
0
파일: case.py 프로젝트: JWW81/stochss
    def assertDictEqual(self, d1, d2, msg=None):
        self.assertTrue(isinstance(d1, dict), "First argument is not a dictionary")
        self.assertTrue(isinstance(d2, dict), "Second argument is not a dictionary")

        if d1 != d2:
            standardMsg = "%s != %s" % (safe_repr(d1, True), safe_repr(d2, True))
            diff = "\n" + "\n".join(difflib.ndiff(pprint.pformat(d1).splitlines(), pprint.pformat(d2).splitlines()))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #10
0
파일: case.py 프로젝트: JWW81/stochss
    def assertMultiLineEqual(self, first, second, msg=None):
        """Assert that two multi-line strings are equal."""
        self.assertTrue(isinstance(first, basestring), ("First argument is not a string"))
        self.assertTrue(isinstance(second, basestring), ("Second argument is not a string"))

        if first != second:
            standardMsg = "%s != %s" % (safe_repr(first, True), safe_repr(second, True))
            diff = "\n" + "".join(difflib.ndiff(first.splitlines(True), second.splitlines(True)))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #11
0
파일: case.py 프로젝트: Myxir20/django
    def assertDictEqual(self, d1, d2, msg=None):
        self.assertTrue(isinstance(d1, dict), 'First argument is not a dictionary')
        self.assertTrue(isinstance(d2, dict), 'Second argument is not a dictionary')

        if d1 != d2:
            standardMsg = '%s != %s' % (safe_repr(d1, True), safe_repr(d2, True))
            diff = ('\n' + '\n'.join(difflib.ndiff(
                           pprint.pformat(d1).splitlines(),
                           pprint.pformat(d2).splitlines())))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #12
0
    def assertHTMLNotEqual(self, html1, html2, msg=None):
        """Asserts that two HTML snippets are not semantically equivalent."""
        dom1 = assert_and_parse_html(self, html1, msg,
                                     u'First argument is not valid HTML:')
        dom2 = assert_and_parse_html(self, html2, msg,
                                     u'Second argument is not valid HTML:')

        if dom1 == dom2:
            standardMsg = '%s == %s' % (
                safe_repr(dom1, True), safe_repr(dom2, True))
            self.fail(self._formatMessage(msg, standardMsg))
예제 #13
0
파일: case.py 프로젝트: Myxir20/django
    def assertMultiLineEqual(self, first, second, msg=None):
        """Assert that two multi-line strings are equal."""
        self.assertTrue(isinstance(first, basestring), (
                'First argument is not a string'))
        self.assertTrue(isinstance(second, basestring), (
                'Second argument is not a string'))

        if first != second:
            standardMsg = '%s != %s' % (safe_repr(first, True), safe_repr(second, True))
            diff = '\n' + ''.join(difflib.ndiff(first.splitlines(True),
                                                       second.splitlines(True)))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #14
0
    def assertHTMLEqual(self, html1, html2, msg=None):
        """
        Asserts that two HTML snippets are semantically the same.
        Whitespace in most cases is ignored, and attribute ordering is not
        significant. The passed-in arguments must be valid HTML.
        """
        dom1 = assert_and_parse_html(self, html1, msg, u"First argument is not valid HTML:")
        dom2 = assert_and_parse_html(self, html2, msg, u"Second argument is not valid HTML:")

        if dom1 != dom2:
            standardMsg = "%s != %s" % (safe_repr(dom1, True), safe_repr(dom2, True))
            diff = "\n" + "\n".join(difflib.ndiff(unicode(dom1).splitlines(), unicode(dom2).splitlines()))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #15
0
파일: testcases.py 프로젝트: Moped/django
 def assertXMLNotEqual(self, xml1, xml2, msg=None):
     """
     Asserts that two XML snippets are not semantically equivalent.
     Whitespace in most cases is ignored, and attribute ordering is not
     significant. The passed-in arguments must be valid XML.
     """
     try:
         result = compare_xml(xml1, xml2)
     except Exception as e:
         standardMsg = 'First or second argument is not valid XML\n%s' % e
         self.fail(self._formatMessage(msg, standardMsg))
     else:
         if result:
             standardMsg = '%s == %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
             self.fail(self._formatMessage(msg, standardMsg))
예제 #16
0
 def assertXMLNotEqual(self, xml1, xml2, msg=None):
     """
     Asserts that two XML snippets are not semantically equivalent.
     Whitespace in most cases is ignored, and attribute ordering is not
     significant. The passed-in arguments must be valid XML.
     """
     try:
         result = compare_xml(xml1, xml2)
     except Exception as e:
         standardMsg = 'First or second argument is not valid XML\n%s' % e
         self.fail(self._formatMessage(msg, standardMsg))
     else:
         if result:
             standardMsg = '%s == %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
             self.fail(self._formatMessage(msg, standardMsg))
예제 #17
0
    def assertHTMLEqual(self, html1, html2, msg=None):
        """
        Asserts that two html snippets are semantically the same, e.g. whitespace
        in most cases is ignored, attribute ordering is not significant. The
        passed in arguments must be valid HTML.
        """
        dom1 = self._assert_and_parse_html(html1, msg,
            u'First argument is no valid html:')
        dom2 = self._assert_and_parse_html(html2, msg,
            u'Second argument is no valid html:')

        if dom1 != dom2:
            standardMsg = '%s != %s' % (safe_repr(dom1, True), safe_repr(dom2, True))
            diff = ('\n' + '\n'.join(difflib.ndiff(
                           unicode(dom1).splitlines(),
                           unicode(dom2).splitlines())))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #18
0
    def assertHTMLEqual(self, html1, html2, msg=None):
        """
        Asserts that two HTML snippets are semantically the same.
        Whitespace in most cases is ignored, and attribute ordering is not
        significant. The passed-in arguments must be valid HTML.
        """
        dom1 = assert_and_parse_html(self, html1, msg,
                                     u'First argument is not valid HTML:')
        dom2 = assert_and_parse_html(self, html2, msg,
                                     u'Second argument is not valid HTML:')

        if dom1 != dom2:
            standardMsg = '%s != %s' % (
                safe_repr(dom1, True), safe_repr(dom2, True))
            diff = ('\n' + '\n'.join(difflib.ndiff(
                           unicode(dom1).splitlines(),
                           unicode(dom2).splitlines())))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #19
0
파일: case.py 프로젝트: yekhneek/django-old
    def assertItemsEqual(self, expected_seq, actual_seq, msg=None):
        """An unordered sequence specific comparison. It asserts that
        expected_seq and actual_seq contain the same elements. It is
        the equivalent of::
        
            self.assertEqual(sorted(expected_seq), sorted(actual_seq))

        Raises with an error message listing which elements of expected_seq
        are missing from actual_seq and vice versa if any.
        
        Asserts that each element has the same count in both sequences.
        Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.
        """
        try:

            expected = expected_seq[:]
            expected.sort()
            actual = actual_seq[:]
            actual.sort()
        except (TypeError, AttributeError):
            # Unsortable items (example: set(), complex(), ...)
            expected = list(expected_seq)
            actual = list(actual_seq)
            missing, unexpected = unorderable_list_difference(
                expected, actual, ignore_duplicate=False)
        else:
            return self.assertSequenceEqual(expected, actual, msg=msg)

        errors = []
        if missing:
            errors.append('Expected, but missing:\n    %s' %
                          safe_repr(missing))
        if unexpected:
            errors.append('Unexpected, but present:\n    %s' %
                          safe_repr(unexpected))
        if errors:
            standardMsg = '\n'.join(errors)
            self.fail(self._formatMessage(msg, standardMsg))
예제 #20
0
파일: case.py 프로젝트: JWW81/stochss
 def assertFalse(self, expr, msg=None):
     "Fail the test if the expression is true."
     if expr:
         msg = self._formatMessage(msg, "%s is not False" % safe_repr(expr))
         raise self.failureException(msg)
예제 #21
0
파일: case.py 프로젝트: 007lva/mmddpp
 def assertLessEqual(self, a, b, msg=None):
     """Just like self.assertTrue(a <= b), but with a nicer default message."""
     if not a <= b:
         standardMsg = '%s not less than or equal to %s' % (safe_repr(a), safe_repr(b))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #22
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertTrue(self, expr, msg=None):
     """Fail the test unless the expression is true."""
     if not expr:
         msg = self._formatMessage(msg, "%s is not True" % safe_repr(expr))
         raise self.failureException(msg)
예제 #23
0
파일: case.py 프로젝트: yekhneek/django-old
 def _baseAssertEqual(self, first, second, msg=None):
     """The default assertEqual implementation, not type specific."""
     if not first == second:
         standardMsg = '%s != %s' % (safe_repr(first), safe_repr(second))
         msg = self._formatMessage(msg, standardMsg)
         raise self.failureException(msg)
예제 #24
0
파일: case.py 프로젝트: JWW81/stochss
 def assertGreaterEqual(self, a, b, msg=None):
     """Just like self.assertTrue(a >= b), but with a nicer default message."""
     if not a >= b:
         standardMsg = "%s not greater than or equal to %s" % (safe_repr(a), safe_repr(b))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #25
0
파일: case.py 프로젝트: JWW81/stochss
 def assertIs(self, expr1, expr2, msg=None):
     """Just like self.assertTrue(a is b), but with a nicer default message."""
     if expr1 is not expr2:
         standardMsg = "%s is not %s" % (safe_repr(expr1), safe_repr(expr2))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #26
0
파일: case.py 프로젝트: 007lva/mmddpp
 def assertIn(self, member, container, msg=None):
     """Just like self.assertTrue(a in b), but with a nicer default message."""
     if member not in container:
         standardMsg = '%s not found in %s' % (safe_repr(member),
                                                safe_repr(container))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #27
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertIs(self, expr1, expr2, msg=None):
     """Just like self.assertTrue(a is b), but with a nicer default message."""
     if expr1 is not expr2:
         standardMsg = '%s is not %s' % (safe_repr(expr1), safe_repr(expr2))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #28
0
파일: case.py 프로젝트: JWW81/stochss
 def _baseAssertEqual(self, first, second, msg=None):
     """The default assertEqual implementation, not type specific."""
     if not first == second:
         standardMsg = "%s != %s" % (safe_repr(first), safe_repr(second))
         msg = self._formatMessage(msg, standardMsg)
         raise self.failureException(msg)
예제 #29
0
파일: case.py 프로젝트: JWW81/stochss
 def assertTrue(self, expr, msg=None):
     """Fail the test unless the expression is true."""
     if not expr:
         msg = self._formatMessage(msg, "%s is not True" % safe_repr(expr))
         raise self.failureException(msg)
예제 #30
0
파일: case.py 프로젝트: JWW81/stochss
 def assertNotIn(self, member, container, msg=None):
     """Just like self.assertTrue(a not in b), but with a nicer default message."""
     if member in container:
         standardMsg = "%s unexpectedly found in %s" % (safe_repr(member), safe_repr(container))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #31
0
파일: case.py 프로젝트: JWW81/stochss
    def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None, max_diff=80 * 8):
        """An equality assertion for ordered sequences (like lists and tuples).

        For the purposes of this function, a valid ordered sequence type is one
        which can be indexed, has a length, and has an equality operator.

        Args:
            seq1: The first sequence to compare.
            seq2: The second sequence to compare.
            seq_type: The expected datatype of the sequences, or None if no
                    datatype should be enforced.
            msg: Optional message to use on failure instead of a list of
                    differences.
            max_diff: Maximum size off the diff, larger diffs are not shown
        """
        if seq_type is not None:
            seq_type_name = seq_type.__name__
            if not isinstance(seq1, seq_type):
                raise self.failureException("First sequence is not a %s: %s" % (seq_type_name, safe_repr(seq1)))
            if not isinstance(seq2, seq_type):
                raise self.failureException("Second sequence is not a %s: %s" % (seq_type_name, safe_repr(seq2)))
        else:
            seq_type_name = "sequence"

        differing = None
        try:
            len1 = len(seq1)
        except (TypeError, NotImplementedError):
            differing = "First %s has no length.    Non-sequence?" % (seq_type_name)

        if differing is None:
            try:
                len2 = len(seq2)
            except (TypeError, NotImplementedError):
                differing = "Second %s has no length.    Non-sequence?" % (seq_type_name)

        if differing is None:
            if seq1 == seq2:
                return

            seq1_repr = repr(seq1)
            seq2_repr = repr(seq2)
            if len(seq1_repr) > 30:
                seq1_repr = seq1_repr[:30] + "..."
            if len(seq2_repr) > 30:
                seq2_repr = seq2_repr[:30] + "..."
            elements = (seq_type_name.capitalize(), seq1_repr, seq2_repr)
            differing = "%ss differ: %s != %s\n" % elements

            for i in xrange(min(len1, len2)):
                try:
                    item1 = seq1[i]
                except (TypeError, IndexError, NotImplementedError):
                    differing += "\nUnable to index element %d of first %s\n" % (i, seq_type_name)
                    break

                try:
                    item2 = seq2[i]
                except (TypeError, IndexError, NotImplementedError):
                    differing += "\nUnable to index element %d of second %s\n" % (i, seq_type_name)
                    break

                if item1 != item2:
                    differing += "\nFirst differing element %d:\n%s\n%s\n" % (i, item1, item2)
                    break
            else:
                if len1 == len2 and seq_type is None and type(seq1) != type(seq2):
                    # The sequences are the same, but have differing types.
                    return

            if len1 > len2:
                differing += "\nFirst %s contains %d additional " "elements.\n" % (seq_type_name, len1 - len2)
                try:
                    differing += "First extra element %d:\n%s\n" % (len2, seq1[len2])
                except (TypeError, IndexError, NotImplementedError):
                    differing += "Unable to index element %d " "of first %s\n" % (len2, seq_type_name)
            elif len1 < len2:
                differing += "\nSecond %s contains %d additional " "elements.\n" % (seq_type_name, len2 - len1)
                try:
                    differing += "First extra element %d:\n%s\n" % (len1, seq2[len1])
                except (TypeError, IndexError, NotImplementedError):
                    differing += "Unable to index element %d " "of second %s\n" % (len1, seq_type_name)
        standardMsg = differing
        diffMsg = "\n" + "\n".join(difflib.ndiff(pprint.pformat(seq1).splitlines(), pprint.pformat(seq2).splitlines()))

        standardMsg = self._truncateMessage(standardMsg, diffMsg)
        msg = self._formatMessage(msg, standardMsg)
        self.fail(msg)
예제 #32
0
파일: case.py 프로젝트: JWW81/stochss
 def assertIsNone(self, obj, msg=None):
     """Same as self.assertTrue(obj is None), with a nicer default message."""
     if obj is not None:
         standardMsg = "%s is not None" % (safe_repr(obj),)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #33
0
파일: case.py 프로젝트: yekhneek/django-old
    def assertSequenceEqual(self,
                            seq1,
                            seq2,
                            msg=None,
                            seq_type=None,
                            max_diff=80 * 8):
        """An equality assertion for ordered sequences (like lists and tuples).

        For the purposes of this function, a valid ordered sequence type is one
        which can be indexed, has a length, and has an equality operator.

        Args:
            seq1: The first sequence to compare.
            seq2: The second sequence to compare.
            seq_type: The expected datatype of the sequences, or None if no
                    datatype should be enforced.
            msg: Optional message to use on failure instead of a list of
                    differences.
            max_diff: Maximum size off the diff, larger diffs are not shown
        """
        if seq_type is not None:
            seq_type_name = seq_type.__name__
            if not isinstance(seq1, seq_type):
                raise self.failureException('First sequence is not a %s: %s' %
                                            (seq_type_name, safe_repr(seq1)))
            if not isinstance(seq2, seq_type):
                raise self.failureException('Second sequence is not a %s: %s' %
                                            (seq_type_name, safe_repr(seq2)))
        else:
            seq_type_name = "sequence"

        differing = None
        try:
            len1 = len(seq1)
        except (TypeError, NotImplementedError):
            differing = 'First %s has no length.    Non-sequence?' % (
                seq_type_name)

        if differing is None:
            try:
                len2 = len(seq2)
            except (TypeError, NotImplementedError):
                differing = 'Second %s has no length.    Non-sequence?' % (
                    seq_type_name)

        if differing is None:
            if seq1 == seq2:
                return

            seq1_repr = repr(seq1)
            seq2_repr = repr(seq2)
            if len(seq1_repr) > 30:
                seq1_repr = seq1_repr[:30] + '...'
            if len(seq2_repr) > 30:
                seq2_repr = seq2_repr[:30] + '...'
            elements = (seq_type_name.capitalize(), seq1_repr, seq2_repr)
            differing = '%ss differ: %s != %s\n' % elements

            for i in xrange(min(len1, len2)):
                try:
                    item1 = seq1[i]
                except (TypeError, IndexError, NotImplementedError):
                    differing += (
                        '\nUnable to index element %d of first %s\n' %
                        (i, seq_type_name))
                    break

                try:
                    item2 = seq2[i]
                except (TypeError, IndexError, NotImplementedError):
                    differing += (
                        '\nUnable to index element %d of second %s\n' %
                        (i, seq_type_name))
                    break

                if item1 != item2:
                    differing += ('\nFirst differing element %d:\n%s\n%s\n' %
                                  (i, item1, item2))
                    break
            else:
                if (len1 == len2 and seq_type is None
                        and type(seq1) != type(seq2)):
                    # The sequences are the same, but have differing types.
                    return

            if len1 > len2:
                differing += ('\nFirst %s contains %d additional '
                              'elements.\n' % (seq_type_name, len1 - len2))
                try:
                    differing += ('First extra element %d:\n%s\n' %
                                  (len2, seq1[len2]))
                except (TypeError, IndexError, NotImplementedError):
                    differing += ('Unable to index element %d '
                                  'of first %s\n' % (len2, seq_type_name))
            elif len1 < len2:
                differing += ('\nSecond %s contains %d additional '
                              'elements.\n' % (seq_type_name, len2 - len1))
                try:
                    differing += ('First extra element %d:\n%s\n' %
                                  (len1, seq2[len1]))
                except (TypeError, IndexError, NotImplementedError):
                    differing += ('Unable to index element %d '
                                  'of second %s\n' % (len1, seq_type_name))
        standardMsg = differing
        diffMsg = '\n' + '\n'.join(
            difflib.ndiff(
                pprint.pformat(seq1).splitlines(),
                pprint.pformat(seq2).splitlines()))

        standardMsg = self._truncateMessage(standardMsg, diffMsg)
        msg = self._formatMessage(msg, standardMsg)
        self.fail(msg)
예제 #34
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertLess(self, a, b, msg=None):
     """Just like self.assertTrue(a < b), but with a nicer default message."""
     if not a < b:
         standardMsg = '%s not less than %s' % (safe_repr(a), safe_repr(b))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #35
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertNotIn(self, member, container, msg=None):
     """Just like self.assertTrue(a not in b), but with a nicer default message."""
     if member in container:
         standardMsg = '%s unexpectedly found in %s' % (
             safe_repr(member), safe_repr(container))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #36
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertIsNone(self, obj, msg=None):
     """Same as self.assertTrue(obj is None), with a nicer default message."""
     if obj is not None:
         standardMsg = '%s is not None' % (safe_repr(obj), )
         self.fail(self._formatMessage(msg, standardMsg))
예제 #37
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertIsNot(self, expr1, expr2, msg=None):
     """Just like self.assertTrue(a is not b), but with a nicer default message."""
     if expr1 is expr2:
         standardMsg = 'unexpectedly identical: %s' % (safe_repr(expr1), )
         self.fail(self._formatMessage(msg, standardMsg))
예제 #38
0
파일: case.py 프로젝트: JWW81/stochss
 def assertLess(self, a, b, msg=None):
     """Just like self.assertTrue(a < b), but with a nicer default message."""
     if not a < b:
         standardMsg = "%s not less than %s" % (safe_repr(a), safe_repr(b))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #39
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertIsInstance(self, obj, cls, msg=None):
     """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
     default message."""
     if not isinstance(obj, cls):
         standardMsg = '%s is not an instance of %r' % (safe_repr(obj), cls)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #40
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertNotIsInstance(self, obj, cls, msg=None):
     """Included for symmetry with assertIsInstance."""
     if isinstance(obj, cls):
         standardMsg = '%s is an instance of %r' % (safe_repr(obj), cls)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #41
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertGreaterEqual(self, a, b, msg=None):
     """Just like self.assertTrue(a >= b), but with a nicer default message."""
     if not a >= b:
         standardMsg = '%s not greater than or equal to %s' % (safe_repr(a),
                                                               safe_repr(b))
         self.fail(self._formatMessage(msg, standardMsg))
예제 #42
0
파일: case.py 프로젝트: yekhneek/django-old
 def assertFalse(self, expr, msg=None):
     "Fail the test if the expression is true."
     if expr:
         msg = self._formatMessage(msg, "%s is not False" % safe_repr(expr))
         raise self.failureException(msg)
예제 #43
0
파일: case.py 프로젝트: JWW81/stochss
 def assertIsInstance(self, obj, cls, msg=None):
     """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
     default message."""
     if not isinstance(obj, cls):
         standardMsg = "%s is not an instance of %r" % (safe_repr(obj), cls)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #44
0
파일: case.py 프로젝트: JWW81/stochss
 def assertIsNot(self, expr1, expr2, msg=None):
     """Just like self.assertTrue(a is not b), but with a nicer default message."""
     if expr1 is expr2:
         standardMsg = "unexpectedly identical: %s" % (safe_repr(expr1),)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #45
0
파일: case.py 프로젝트: JWW81/stochss
 def assertNotIsInstance(self, obj, cls, msg=None):
     """Included for symmetry with assertIsInstance."""
     if isinstance(obj, cls):
         standardMsg = "%s is an instance of %r" % (safe_repr(obj), cls)
         self.fail(self._formatMessage(msg, standardMsg))
예제 #46
0
def assert_equal_line_by_line(test_case, expected_text, text, msg = None):
    """
    Asserts that text equals expected_text. Compares expected_text to text line-by-line for better output. Convenient for long texts.
    :param test_case: TestCase-like object which has assertTrue and assertEqual methods
    :param expected_text: expected value
    :type expected_text: str
    :param text: actual value
    :type text: str
    :param msg: optional message to append to the output of error
    :type msg: str
    """
    msg = msg and "\n%s" % msg or ""
    expected_lines = expected_text.splitlines(True)
    text_lines = text.splitlines(True)
    expected_lines_count = len(expected_lines)
    lines_error = ""
    if expected_lines_count != len(text_lines):
        lines_error = "Expected number of lines: %s, but was: %s" % (expected_lines_count, len(text_lines))
    for i in range(min(expected_lines_count, len(text_lines))):
        actual_line = text_lines[i]
        expected_line = expected_lines[i]
        test_case.assertEqual(expected_line, actual_line, "\nLine %s.\nExpected: %s\nActual:   %s\n%s%s" % (i, safe_repr(expected_line), safe_repr(actual_line), lines_error, msg))