当前位置: 首页>>代码示例>>Python>>正文


Python util.safe_repr函数代码示例

本文整理汇总了Python中unittest2.util.safe_repr函数的典型用法代码示例。如果您正苦于以下问题:Python safe_repr函数的具体用法?Python safe_repr怎么用?Python safe_repr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safe_repr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assertAlmostEqual

 def assertAlmostEqual(self, first, second, places = 7, msg = None):
     if first == second:
         return
     if round(abs(second - first), places) != 0:
         standardMsg = '%s != %s within %r places' % (safe_repr(first), safe_repr(second), places)
         msg = self._formatMessage(msg, standardMsg)
         raise self.failureException(msg)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:7,代码来源:case.py

示例2: assertNotAlmostEqual

    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)
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:30,代码来源:case.py

示例3: assertDictContainsSubset

    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))
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:25,代码来源:case.py

示例4: assertItemsEqual

    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))
开发者ID:justinabrahms,项目名称:test_generators,代码行数:34,代码来源:case.py

示例5: assertNotEqual

 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)
开发者ID:justinabrahms,项目名称:test_generators,代码行数:7,代码来源:case.py

示例6: assertDictEqual

    def assertDictEqual(self, d1, d2, msg=None):
        self.assert_(isinstance(d1, dict), "First argument is not a dictionary")
        self.assert_(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))
开发者ID:justinabrahms,项目名称:test_generators,代码行数:9,代码来源:case.py

示例7: assertMultiLineEqual

    def assertMultiLineEqual(self, first, second, msg=None):
        """Assert that two multi-line strings are equal."""
        self.assert_(isinstance(first, basestring), ("First argument is not a string"))
        self.assert_(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))
开发者ID:justinabrahms,项目名称:test_generators,代码行数:10,代码来源:case.py

示例8: assertDictEqual

    def assertDictEqual(self, d1, d2, msg=None):
        self.assertTrue(IsMappingType(d1), 'First argument is not a dictionary')
        self.assertTrue(IsMappingType(d2), '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))
开发者ID:locsmith,项目名称:xcamshift,代码行数:11,代码来源:test_python_utils.py

示例9: assertDictEqual

    def assertDictEqual(self, d1, d2, msg=None):
        self.assert_(isinstance(d1, dict), 'First argument is not a dictionary')
        self.assert_(isinstance(d2, dict), 'Second argument is not a dictionary')

        if d1 != d2:
            standardMsg = '{0!s} != {1!s}'.format(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))
开发者ID:runt18,项目名称:swift-lldb,代码行数:11,代码来源:case.py

示例10: assertMultiLineEqual

    def assertMultiLineEqual(self, first, second, msg=None):
        """Assert that two multi-line strings are equal."""
        self.assert_(isinstance(first, six.string_types), (
                'First argument is not a string'))
        self.assert_(isinstance(second, six.string_types), (
                '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))
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:13,代码来源:case.py

示例11: assertDictContainsSubset

    def assertDictContainsSubset(self, expected, actual, msg=None):
        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))
开发者ID:Reve,项目名称:eve,代码行数:21,代码来源:case.py

示例12: assertSameElements

    def assertSameElements(self, expected_seq, actual_seq, msg = None):
        try:
            expected = set(expected_seq)
            actual = set(actual_seq)
            missing = list(expected.difference(actual))
            unexpected = list(actual.difference(expected))
            missing.sort()
            unexpected.sort()
        except TypeError:
            expected = list(expected_seq)
            actual = list(actual_seq)
            expected.sort()
            actual.sort()
            missing, unexpected = sorted_list_difference(expected, actual)

        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))
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:23,代码来源:case.py

示例13: assertAlmostEqual

    def assertAlmostEqual(self, first, second, places=None, msg=None, delta=None):
        """Fail if the two objects are unequal 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 more than the given delta.

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

           If the two objects compare equal then they will automatically
           compare almost equal.
        """
        if first == second:
            # shortcut
            return
        if delta is not None and places is not None:
            raise TypeError("specify delta or places not both")
        
        if delta is not None:
            if abs(first - second) <= delta:
                return
        
            standardMsg = '{0!s} != {1!s} within {2!s} delta'.format(safe_repr(first), 
                                                        safe_repr(second), 
                                                        safe_repr(delta))
        else:
            if places is None:
                places = 7
                
            if round(abs(second-first), places) == 0:
                return
        
            standardMsg = '{0!s} != {1!s} within {2!r} places'.format(safe_repr(first), 
                                                          safe_repr(second), 
                                                          places)
        msg = self._formatMessage(msg, standardMsg)
        raise self.failureException(msg)
开发者ID:runt18,项目名称:swift-lldb,代码行数:37,代码来源:case.py

示例14: assertIsNot

 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))
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:5,代码来源:case.py

示例15: assertIs

 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))
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:5,代码来源:case.py


注:本文中的unittest2.util.safe_repr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。