• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.safe_repr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: assertcountmessage

 def assertcountmessage(self, request, nb, liste=False):
     messages = get_messages(request)
     actual = len([e.message for e in messages])
     if actual != nb:
         if liste:
             messages_str = "[\n"
             for m in messages:
                 messages_str += "\t'" + m.message + "',\n"
                 messages_str += "]"
             self.fail('Message count was %s, expected %s. list of messages: \n %s' % (actual, nb, messages_str))
         else:
             self.fail('Message count was %s, expected %s' % (safe_repr(actual), safe_repr(nb)))
开发者ID:pfrancois,项目名称:grisbi_django,代码行数:12,代码来源:test_base.py


示例17: assertSize

    def assertSize(self, obj, size, msg=None):  # pylint: disable=invalid-name
        """Same as ``self.assertEqual(len(obj), size)``, with a nicer default
        message."""
        try:
            obj_size = len(obj)
        except Exception:  # pylint: disable=broad-except
            logging.exception("Couldn't get object size")
            self.fail('Could not get {} size.'.format(safe_repr(obj)))
            return

        if size != obj_size:
            standard_msg = "{}'s size is {} != {}".format(safe_repr(obj),
                                                          obj_size, size)
            self.fail(self._formatMessage(msg, standard_msg))
开发者ID:pignacio,项目名称:pignacio_scripts,代码行数:14,代码来源:testcase.py


示例18: assertHTMLEqual

    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, "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))
            diff = "\n" + "\n".join(difflib.ndiff(six.text_type(dom1).splitlines(), six.text_type(dom2).splitlines()))
            standardMsg = self._truncateMessage(standardMsg, diff)
            self.fail(self._formatMessage(msg, standardMsg))
开发者ID:ccjuantrujillo,项目名称:django-web-oficial,代码行数:14,代码来源:testcases.py


示例19: assertXMLNotEqual

 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))
开发者ID:912,项目名称:M-new,代码行数:15,代码来源:testcases.py


示例20: assertIsNone

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unittest2.installHandler函数代码示例发布时间:2022-05-27
下一篇:
Python support.is_instance函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap