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

Python xunit.Xunit类代码示例

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

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



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

示例1: TestEscaping

class TestEscaping(unittest.TestCase):

    def setUp(self):
        self.x = Xunit()

    def test_all(self):
        eq_(self.x._quoteattr(
            '''<baz src="http://foo?f=1&b=2" quote="inix hubris 'maximus'?" />'''),
            ('"&lt;baz src=&quot;http://foo?f=1&amp;b=2&quot; '
                'quote=&quot;inix hubris \'maximus\'?&quot; /&gt;"'))

    def test_unicode_is_utf8_by_default(self):
        if not UNICODE_STRINGS:
            eq_(self.x._quoteattr(u'Ivan Krsti\u0107'),
                '"Ivan Krsti\xc4\x87"')

    def test_unicode_custom_utf16_madness(self):
        self.x.encoding = 'utf-16'
        utf16 = self.x._quoteattr(u'Ivan Krsti\u0107')[1:-1]

        if UNICODE_STRINGS:
            # If all internal strings are unicode, then _quoteattr shouldn't
            # have changed anything.
            eq_(utf16, u'Ivan Krsti\u0107')
        else:
            # to avoid big/little endian bytes, assert that we can put it back:
            eq_(utf16.decode('utf16'), u'Ivan Krsti\u0107')

    def test_control_characters(self):
        # quoting of \n, \r varies in diff. python versions
        n = saxutils.quoteattr('\n')[1:-1]
        r = saxutils.quoteattr('\r')[1:-1]
        eq_(self.x._quoteattr('foo\n\b\f\r'), '"foo%s??%s"' % (n, r))
        eq_(escape_cdata('foo\n\b\f\r'), 'foo\n??\r')
开发者ID:ahmedelsb,项目名称:nose,代码行数:34,代码来源:test_xunit.py


示例2: BaseTestXMLOutputWithXML

class BaseTestXMLOutputWithXML(unittest.TestCase):
    def configure(self, args):
        parser = optparse.OptionParser()
        self.x.add_options(parser, env={})
        (options, args) = parser.parse_args(args)
        self.x.configure(options, Config())

    def setUp(self):
        self.xmlfile = os.path.abspath(
            os.path.join(os.path.dirname(__file__),
                            'support', 'xunit.xml'))
        self.x = Xunit()

        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree

    def tearDown(self):
        os.unlink(self.xmlfile)

    def get_xml_report(self):
        class DummyStream:
            pass
        self.x.report(DummyStream())
        f = open(self.xmlfile, 'rb')
        data = f.read()
        f.close()
        return data
开发者ID:Averroes,项目名称:nose,代码行数:31,代码来源:test_xunit.py


示例3: run_tests

def run_tests(spider, output_file, settings):
    """
    Helper for running test contractors for a spider and output an
    XUnit file (for CI)

    For using offline input the HTTP cache is enabled
    """

    settings.overrides.update({
        "HTTPCACHE_ENABLED": True,
        "HTTPCACHE_EXPIRATION_SECS": 0,
    })

    crawler = CrawlerProcess(settings)

    contracts = build_component_list(
        crawler.settings['SPIDER_CONTRACTS_BASE'],
        crawler.settings['SPIDER_CONTRACTS'],
    )

    xunit = Xunit()
    xunit.enabled = True
    xunit.configure(AttributeDict(xunit_file=output_file), Config())
    xunit.stopTest = lambda *x: None

    check = CheckCommand()
    check.set_crawler(crawler)
    check.settings = settings
    check.conman = ContractsManager([load_object(c) for c in contracts])
    check.results = xunit
    # this are specially crafted requests that run tests as callbacks
    requests = check.get_requests(spider)

    crawler.install()
    crawler.configure()
    crawler.crawl(spider, requests)
    log.start(loglevel='DEBUG')

    # report is called when the crawler finishes, it creates the XUnit file
    report = lambda: check.results.report(check.results.error_report_file)
    dispatcher.connect(report, signals.engine_stopped)

    crawler.start()
开发者ID:SpazioDati,项目名称:scrapyrwiki,代码行数:43,代码来源:test_helpers.py


示例4: setUp

    def setUp(self):
        self.xmlfile = os.path.abspath(
            os.path.join(os.path.dirname(__file__),
                            'support', 'xunit.xml'))
        self.x = Xunit()

        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree
开发者ID:Averroes,项目名称:nose,代码行数:12,代码来源:test_xunit.py


示例5: TestEscaping

class TestEscaping(unittest.TestCase):
    
    def setUp(self):
        self.x = Xunit()
    
    def test_all(self):
        eq_(self.x._xmlsafe(
            '''<baz src="http://foo?f=1&b=2" quote="inix hubris 'maximus'?" />'''),
            ('&lt;baz src=&quot;http://foo?f=1&amp;b=2&quot; '
                'quote=&quot;inix hubris &#39;maximus&#39;?&quot; /&gt;'))

    
    def test_unicode_is_utf8_by_default(self):
        eq_(self.x._xmlsafe(u'Ivan Krsti\u0107'),
            'Ivan Krsti\xc4\x87')

    
    def test_unicode_custom_utf16_madness(self):
        self.x.encoding = 'utf-16'
        utf16 = self.x._xmlsafe(u'Ivan Krsti\u0107')
        
        # to avoid big/little endian bytes, assert that we can put it back:
        eq_(utf16.decode('utf16'), u'Ivan Krsti\u0107')
开发者ID:LucianU,项目名称:kuma-lib,代码行数:23,代码来源:test_xunit.py


示例6: setUp

    def setUp(self):
        self.xmlfile = os.path.abspath(os.path.join(os.path.dirname(__file__), "support", "xunit.xml"))
        parser = optparse.OptionParser()
        self.x = Xunit()
        self.x.add_options(parser, env={})
        (options, args) = parser.parse_args(["--with-xunit", "--xunit-file=%s" % self.xmlfile])
        self.x.configure(options, Config())

        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:14,代码来源:test_xunit.py


示例7: test_prefix_from_environ

 def test_prefix_from_environ(self):
     parser = optparse.OptionParser()
     x = Xunit()
     x.add_options(parser, env={'NOSE_XUNIT_PREFIX_WITH_TESTSUITE_NAME': 'true'})
     (options, args) = parser.parse_args([])
     eq_(options.xunit_prefix_class, True)
开发者ID:Averroes,项目名称:nose,代码行数:6,代码来源:test_xunit.py


示例8: test_file_from_opt

 def test_file_from_opt(self):
     parser = optparse.OptionParser()
     x = Xunit()
     x.add_options(parser, env={})
     (options, args) = parser.parse_args(["--xunit-file=blagojevich.xml"])
     eq_(options.xunit_file, "blagojevich.xml")
开发者ID:Averroes,项目名称:nose,代码行数:6,代码来源:test_xunit.py


示例9: test_file_from_environ

 def test_file_from_environ(self):
     parser = optparse.OptionParser()
     x = Xunit()
     x.add_options(parser, env={'NOSE_XUNIT_FILE': "kangaroo.xml"})
     (options, args) = parser.parse_args([])
     eq_(options.xunit_file, "kangaroo.xml")
开发者ID:Averroes,项目名称:nose,代码行数:6,代码来源:test_xunit.py


示例10: test_defaults

 def test_defaults(self):
     parser = optparse.OptionParser()
     x = Xunit()
     x.add_options(parser, env={})
     (options, args) = parser.parse_args([])
     eq_(options.xunit_file, "nosetests.xml")
开发者ID:Averroes,项目名称:nose,代码行数:6,代码来源:test_xunit.py


示例11: test_prefix_from_opt

 def test_prefix_from_opt(self):
     parser = optparse.OptionParser()
     x = Xunit()
     x.add_options(parser, env={})
     (options, args) = parser.parse_args(["--xunit-prefix-with-testsuite-name"])
     eq_(options.xunit_prefix_class, True)
开发者ID:Averroes,项目名称:nose,代码行数:6,代码来源:test_xunit.py


示例12: TestXMLOutputWithXML

class TestXMLOutputWithXML(unittest.TestCase):
    
    def setUp(self):
        self.xmlfile = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 
                            'support', 'xunit.xml'))
        parser = optparse.OptionParser()
        self.x = Xunit()
        self.x.add_options(parser, env={})
        (options, args) = parser.parse_args([
            "--with-xunit",
            "--xunit-file=%s" % self.xmlfile
        ])
        self.x.configure(options, Config())
        
        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree
    
    def tearDown(self):
        os.unlink(self.xmlfile)
    
    def get_xml_report(self):
        class DummyStream:
            pass
        self.x.report(DummyStream())
        f = open(self.xmlfile, 'r')
        return f.read()
        f.close()
            
    def test_addFailure(self):
        test = mktest()
        self.x.startTest(test)
        try:
            raise AssertionError("one is not 'equal' to two")
        except AssertionError:
            some_err = sys.exc_info()
            
        self.x.addFailure(test, some_err)
        
        result = self.get_xml_report()
        print result
        
        if self.ET:
            tree = self.ET.fromstring(result)
            eq_(tree.attrib['name'], "nosetests")
            eq_(tree.attrib['tests'], "1")
            eq_(tree.attrib['errors'], "0")
            eq_(tree.attrib['failures'], "1")
            eq_(tree.attrib['skip'], "0")
        
            tc = tree.find("testcase")
            eq_(tc.attrib['classname'], "test_xunit.TC")
            eq_(tc.attrib['name'], "test_xunit.TC.runTest")
            assert int(tc.attrib['time']) >= 0
        
            err = tc.find("failure")
            eq_(err.attrib['type'], "exceptions.AssertionError")
            err_lines = err.text.strip().split("\n")
            eq_(err_lines[0], 'Traceback (most recent call last):')
            eq_(err_lines[-1], 'AssertionError: one is not \'equal\' to two')
            eq_(err_lines[-2], '    raise AssertionError("one is not \'equal\' to two")')
        else:            
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert '<testsuite name="nosetests" tests="1" errors="0" failures="1" skip="0">' in result
            assert '<testcase classname="test_xunit.TC" name="test_xunit.TC.runTest"' in result
            assert '<failure type="exceptions.AssertionError">' in result
            assert 'AssertionError: one is not &#39;equal&#39; to two' in result
            assert 'AssertionError(&quot;one is not &#39;equal&#39; to two&quot;)' in result
            assert '</failure></testcase></testsuite>' in result
            
    def test_addFailure_early(self):
        test = mktest()
        try:
            raise AssertionError("one is not equal to two")
        except AssertionError:
            some_err = sys.exc_info()
        
        # add failure without startTest, due to custom TestResult munging?
        self.x.addFailure(test, some_err)
        
        result = self.get_xml_report()
        print result
        
        if self.ET:
            tree = self.ET.fromstring(result)
            tc = tree.find("testcase")
            eq_(tc.attrib['time'], "0")
        else:
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert ('<testcase classname="test_xunit.TC" '
                    'name="test_xunit.TC.runTest" time="0">') in result
    
    def test_addError(self):
        test = mktest()
#.........这里部分代码省略.........
开发者ID:LucianU,项目名称:kuma-lib,代码行数:101,代码来源:test_xunit.py


示例13: setUp

 def setUp(self):
     self.x = Xunit()
开发者ID:LucianU,项目名称:kuma-lib,代码行数:2,代码来源:test_xunit.py


示例14: TestXMLOutputWithXML

class TestXMLOutputWithXML(unittest.TestCase):

    def setUp(self):
        self.xmlfile = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 
                            'support', 'xunit.xml'))
        parser = optparse.OptionParser()
        self.x = Xunit()
        self.x.add_options(parser, env={})
        (options, args) = parser.parse_args([
            "--with-xunit",
            "--xunit-file=%s" % self.xmlfile
        ])
        self.x.configure(options, Config())

        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree

    def tearDown(self):
        os.unlink(self.xmlfile)

    def get_xml_report(self):
        class DummyStream:
            pass
        self.x.report(DummyStream())
        f = open(self.xmlfile, 'rb')
        return f.read()
        f.close()

    def test_addFailure(self):
        test = mktest()
        self.x.beforeTest(test)
        try:
            raise AssertionError("one is not 'equal' to two")
        except AssertionError:
            some_err = sys.exc_info()

        self.x.addFailure(test, some_err)

        result = self.get_xml_report()
        print result

        if self.ET:
            tree = self.ET.fromstring(result)
            eq_(tree.attrib['name'], "nosetests")
            eq_(tree.attrib['tests'], "1")
            eq_(tree.attrib['errors'], "0")
            eq_(tree.attrib['failures'], "1")
            eq_(tree.attrib['skip'], "0")

            tc = tree.find("testcase")
            eq_(tc.attrib['classname'], "test_xunit.TC")
            eq_(tc.attrib['name'], "runTest")
            assert time_taken.match(tc.attrib['time']), (
                        'Expected decimal time: %s' % tc.attrib['time'])

            err = tc.find("failure")
            eq_(err.attrib['type'], "%s.AssertionError" % (AssertionError.__module__,))
            err_lines = err.text.strip().split("\n")
            eq_(err_lines[0], 'Traceback (most recent call last):')
            eq_(err_lines[-1], 'AssertionError: one is not \'equal\' to two')
            eq_(err_lines[-2], '    raise AssertionError("one is not \'equal\' to two")')
        else:
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert '<testsuite name="nosetests" tests="1" errors="0" failures="1" skip="0">' in result
            assert '<testcase classname="test_xunit.TC" name="runTest"' in result
            assert '<failure type="exceptions.AssertionError"' in result
            assert "AssertionError: one is not 'equal' to two" in result
            assert "AssertionError(\"one is not 'equal' to two\")" in result
            assert '</failure></testcase></testsuite>' in result

    def test_addFailure_early(self):
        test = mktest()
        try:
            raise AssertionError("one is not equal to two")
        except AssertionError:
            some_err = sys.exc_info()

        # add failure without startTest, due to custom TestResult munging?
        self.x.addFailure(test, some_err)

        result = self.get_xml_report()
        print result

        if self.ET:
            tree = self.ET.fromstring(result)
            tc = tree.find("testcase")
            assert time_taken.match(tc.attrib['time']), (
                        'Expected decimal time: %s' % tc.attrib['time'])
        else:
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert ('<testcase classname="test_xunit.TC" '
                    'name="runTest" time="0') in result

#.........这里部分代码省略.........
开发者ID:ahmedelsb,项目名称:nose,代码行数:101,代码来源:test_xunit.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyversion.ismethod函数代码示例发布时间:2022-05-27
下一篇:
Python logcapture.LogCapture类代码示例发布时间: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