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


Python util.safe_repr函数代码示例

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


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

示例1: assertAllIn

 def assertAllIn(self, iterable, container, msg=None):
     """Check for all the item in iterable to be in the given container"""
     for member in iterable:
         if member not in container:
             if member not in container:
                 standardMsg = '%s not found in %s' % (safe_repr(member), safe_repr(container))
                 self.fail(self._formatMessage(msg, standardMsg))
开发者ID:danielepantaleone,项目名称:eddy,代码行数:7,代码来源:__init__.py

示例2: simple_equality

 def simple_equality(cls, first, second, msg=None):
     """
     Classmethod equivalent to unittest.TestCase method (longMessage = False.)
     """
     if not first==second:
         standardMsg = '%s != %s' % (safe_repr(first), safe_repr(second))
         raise cls.failureException(msg or standardMsg)
开发者ID:mforbes,项目名称:holoviews,代码行数:7,代码来源:comparison.py

示例3: test_diff_output

    def test_diff_output(self):
        self._create_conf()
        self._create_rpmnew()
        self._create_rpmsave()

        with self.rpmconf_plugin as rpmconf, mock.patch("sys.stdout", new_callable=StringIO) as stdout:
            rpmconf.diff = True
            rpmconf.run()

            lines = stdout.getvalue().splitlines()

        expected_lines = [
            "--- {0}".format(*self.conf_file),
            "+++ {0}".format(*self.conf_file_rpmnew),
            "@@ -1,3 +1,2 @@",
            " package = good",
            " true = false",
            '-what = "tahw"',
            "--- {0}".format(*self.conf_file_rpmsave),
            "+++ {0}".format(*self.conf_file),
            "@@ -1,2 +1,3 @@",
            "-package = bad",
            "-true = true",
            "+package = good",
            "+true = false",
            '+what = "tahw"',
        ]

        msg_tmpl = "{0} does not start with {1}"
        for line, expected_line in zip_longest(lines, expected_lines, fillvalue=""):
            if not line.startswith(expected_line):
                self.fail(msg_tmpl.format(safe_repr(line), safe_repr(expected_line)))
开发者ID:pghmcfc,项目名称:dnf-plugins-extras,代码行数:32,代码来源:test_rpmconf.py

示例4: assertDictContainsSubset

    def assertDictContainsSubset(self, expected, actual, msg=None):
        missing, mismatched = [], []

        for key, value in items(expected):
            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

        standard_msg = ''
        if missing:
            standard_msg = 'Missing: %s' % ','.join(map(safe_repr, missing))

        if mismatched:
            if standard_msg:
                standard_msg += '; '
            standard_msg += 'Mismatched values: %s' % (
                ','.join(mismatched))

        self.fail(self._formatMessage(msg, standard_msg))
开发者ID:imcom,项目名称:celery,代码行数:25,代码来源:case.py

示例5: assertLess

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

示例6: assertGreaterEqual

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

示例7: 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:infrae,项目名称:infrae.testing,代码行数:30,代码来源:testmethods.py

示例8: 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:infrae,项目名称:infrae.testing,代码行数:25,代码来源:testmethods.py

示例9: assertItemsEqual

    def assertItemsEqual(self, expected_seq, actual_seq, msg=None):
        missing = unexpected = None
        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)
        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:imcom,项目名称:celery,代码行数:26,代码来源:case.py

示例10: assertHTMLNotEqual

    def assertHTMLNotEqual(self, html1, html2, msg=None):
        """Asserts that two HTML snippets are not semantically equivalent."""
        dom1 = assert_and_parse_html(self, html1, msg, "First argument is not valid HTML:")
        dom2 = assert_and_parse_html(self, html2, msg, "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))
开发者ID:ccjuantrujillo,项目名称:django-web-oficial,代码行数:8,代码来源:testcases.py

示例11: assertAnyIn

 def assertAnyIn(self, iterable, container, msg=None):
     """Check for at least a one of the item in iterable to be in the given container"""
     for member in iterable:
         if member in container:
             break
     else:
         standardMsg = 'no item of %s found in %s' % (safe_repr(iterable), safe_repr(container))
         self.fail(self._formatMessage(msg, standardMsg))
开发者ID:danielepantaleone,项目名称:eddy,代码行数:8,代码来源:__init__.py

示例12: 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:infrae,项目名称:infrae.testing,代码行数:8,代码来源:testmethods.py

示例13: assertIn

 def assertIn(self, member, container, msg=None):
     """
     Just like self.assertTrue(a in b), but with a nicer default message.
     Backported from Python 2.7 unittest library.
     """
     if member not in container:
         standardMsg = '%s not found in %s' % (safe_repr(member),
                                               safe_repr(container))
         self.fail(self._formatMessage(msg, standardMsg))
开发者ID:aptivate,项目名称:pysolr,代码行数:9,代码来源:admin.py

示例14: assertDictEqual

    def assertDictEqual(self, d1, d2, msg=None):
        self.assertIsInstance(d1, dict, 'First argument is not a dictionary')
        self.assertIsInstance(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:infrae,项目名称:infrae.testing,代码行数:11,代码来源:testmethods.py

示例15: assertEqual

 def assertEqual(self, val1, val2, msg=None, exact=False):
     if val1 == val2:
         return
     if not exact and isinstance(val1, str) and isinstance(val2, str):
         self.assertSimilarStrings(val1, val2, msg)
     elif (not exact and isinstance(val1, (int, float)) and
           isinstance(val2, (int, float))):
         if abs(val2 - val1) <= UnitTestedAssignment.DELTA:
             return
     standardMsg = "{} != {}".format(safe_repr(val1), safe_repr(val2))
     self.fail(msg, standardMsg)
开发者ID:RealTimeWeb,项目名称:skulpt,代码行数:11,代码来源:vpl_unittest.py


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