本文整理匯總了Python中unittest.html方法的典型用法代碼示例。如果您正苦於以下問題:Python unittest.html方法的具體用法?Python unittest.html怎麽用?Python unittest.html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類unittest
的用法示例。
在下文中一共展示了unittest.html方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testAssertMultiLineEqual
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def testAssertMultiLineEqual(self):
sample_text = """\
http://www.python.org/doc/2.3/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...]
"""
revised_sample_text = """\
http://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...] You may provide your
own implementation that does not subclass from TestCase, of course.
"""
sample_text_error = """\
- http://www.python.org/doc/2.3/lib/module-unittest.html
? ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
? ^^^
test case
- A test case is the smallest unit of testing. [...]
+ A test case is the smallest unit of testing. [...] You may provide your
? +++++++++++++++++++++
+ own implementation that does not subclass from TestCase, of course.
"""
self.maxDiff = None
try:
self.assertMultiLineEqual(sample_text, revised_sample_text)
except self.failureException as e:
# need to remove the first line of the error message
error = str(e).split('\n', 1)[1]
# no fair testing ourself with ourself, and assertEqual is used for strings
# so can't use assertEqual either. Just use assertTrue.
self.assertTrue(sample_text_error == error)
示例2: testAssertMultiLineEqual
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def testAssertMultiLineEqual(self):
sample_text = b"""\
http://www.python.org/doc/2.3/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...]
"""
revised_sample_text = b"""\
http://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...] You may provide your
own implementation that does not subclass from TestCase, of course.
"""
sample_text_error = b"""\
- http://www.python.org/doc/2.3/lib/module-unittest.html
? ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
? ^^^
test case
- A test case is the smallest unit of testing. [...]
+ A test case is the smallest unit of testing. [...] You may provide your
? +++++++++++++++++++++
+ own implementation that does not subclass from TestCase, of course.
"""
self.maxDiff = None
for type_changer in (lambda x: x, lambda x: x.decode('utf8')):
try:
self.assertMultiLineEqual(type_changer(sample_text),
type_changer(revised_sample_text))
except self.failureException, e:
# need to remove the first line of the error message
error = str(e).encode('utf8').split('\n', 1)[1]
# assertMultiLineEqual is hooked up as the default for
# unicode strings - so we can't use it for this check
self.assertTrue(sample_text_error == error)
示例3: tearDownClass
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def tearDownClass(cls):
# tearDownModule() is called after all the tests have run.
# http://docs.python.org/2/library/unittest.html#class-and-module-fixtures
# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated for the test cases.
shutil.rmtree(cls.temporary_directory)
示例4: testAssertMultiLineEqual
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def testAssertMultiLineEqual(self):
sample_text = """\
http://www.python.org/doc/2.3/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...]
"""
revised_sample_text = """\
http://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...] You may provide your
own implementation that does not subclass from TestCase, of course.
"""
sample_text_error = """\
- http://www.python.org/doc/2.3/lib/module-unittest.html
? ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
? ^^^
test case
- A test case is the smallest unit of testing. [...]
+ A test case is the smallest unit of testing. [...] You may provide your
? +++++++++++++++++++++
+ own implementation that does not subclass from TestCase, of course.
"""
self.maxDiff = None
try:
self.assertMultiLineEqual(sample_text, revised_sample_text)
except self.failureException as e:
# need to remove the first line of the error message
error = str(e).split('\n', 1)[1]
self.assertEqual(sample_text_error, error)
示例5: group
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def group(s, n):
# See
# http://www.python.org/doc/2.6/library/functions.html#zip
return zip(*[iter(s)]*n)
示例6: interleave_planes
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def interleave_planes(ipixels, apixels, ipsize, apsize):
"""
Interleave (colour) planes, e.g. RGB + A = RGBA.
Return an array of pixels consisting of the `ipsize` elements of data
from each pixel in `ipixels` followed by the `apsize` elements of data
from each pixel in `apixels`. Conventionally `ipixels` and
`apixels` are byte arrays so the sizes are bytes, but it actually
works with any arrays of the same type. The returned array is the
same type as the input arrays which should be the same type as each other.
"""
itotal = len(ipixels)
atotal = len(apixels)
newtotal = itotal + atotal
newpsize = ipsize + apsize
# Set up the output buffer
# See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356
out = array(ipixels.typecode)
# It's annoying that there is no cheap way to set the array size :-(
out.extend(ipixels)
out.extend(apixels)
# Interleave in the pixel data
for i in range(ipsize):
out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize]
for i in range(apsize):
out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize]
return out
示例7: mycallersname
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def mycallersname():
"""Returns the name of the caller of the caller of this function
(hence the name of the caller of the function in which
"mycallersname()" textually appears). Returns None if this cannot
be determined."""
# http://docs.python.org/library/inspect.html#the-interpreter-stack
import inspect
frame = inspect.currentframe()
if not frame:
return None
frame_,filename_,lineno_,funname,linelist_,listi_ = (
inspect.getouterframes(frame)[2])
return funname
示例8: _enhex
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def _enhex(s):
"""Convert from binary string (bytes) to hex string (str)."""
import binascii
return bytestostr(binascii.hexlify(s))
# Copies of PngSuite test files taken
# from http://www.schaik.com/pngsuite/pngsuite_bas_png.html
# on 2009-02-19 by drj and converted to hex.
# Some of these are not actually in PngSuite (but maybe they should
# be?), they use the same naming scheme, but start with a capital
# letter.
示例9: group
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def group(s, n):
# See
# http://www.python.org/doc/2.6/library/functions.html#zip
return list(zip(*[iter(s)]*n))
示例10: group
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def group(s, n):
# See
# http://www.python.org/doc/2.6/library/functions.html#zip
return zip(*[iter(s)] * n)
示例11: interleave_planes
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def interleave_planes(ipixels, apixels, ipsize, apsize):
"""
Interleave (colour) planes, e.g. RGB + A = RGBA.
Return an array of pixels consisting of the `ipsize` elements of data
from each pixel in `ipixels` followed by the `apsize` elements of data
from each pixel in `apixels`. Conventionally `ipixels` and
`apixels` are byte arrays so the sizes are bytes, but it actually
works with any arrays of the same type. The returned array is the
same type as the input arrays which should be the same type as each other.
"""
itotal = len(ipixels)
atotal = len(apixels)
newtotal = itotal + atotal
newpsize = ipsize + apsize
# Set up the output buffer
# See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356
out = array(ipixels.typecode)
# It's annoying that there is no cheap way to set the array size :-(
out.extend(ipixels)
out.extend(apixels)
# Interleave in the pixel data
for i in range(ipsize):
out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize]
for i in range(apsize):
out[i + ipsize:newtotal:newpsize] = apixels[i:atotal:apsize]
return out
示例12: _dehex
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def _dehex(s):
"""Liberally convert from hex string to binary string."""
import re
# Remove all non-hexadecimal digits
s = re.sub(r'[^a-fA-F\d]', '', s)
return s.decode('hex')
# Copies of PngSuite test files taken
# from http://www.schaik.com/pngsuite/pngsuite_bas_png.html
# on 2009-02-19 by drj and converted to hex.
# Some of these are not actually in PngSuite (but maybe they should
# be?), they use the same naming scheme, but start with a capital
# letter.
示例13: gen_header
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def gen_header(testcases):
header = f'''"""DO NOT MODIFY: Tests generated from `tests/` with {sys.argv[0]}"""
import unittest
from binascii import unhexlify
from manticore import ManticoreEVM, Plugin
from manticore.utils import config
'''
if any("logs" in testcase for testcase in testcases.values()):
body += """
import sha3
import rlp
from rlp.sedes import (
CountableList,
BigEndianInt,
Binary,
)
class Log(rlp.Serializable):
fields = [
('address', Binary.fixed_length(20, allow_empty=True)),
('topics', CountableList(BigEndianInt(32))),
('data', Binary())
]
"""
header += """consts = config.get_group('core')
consts.mprocessing = consts.mprocessing.single
consts = config.get_group('evm')
consts.oog = 'pedantic'
class EVMTest(unittest.TestCase):
# https://nose.readthedocs.io/en/latest/doc_tests/test_multiprocess/multiprocess.html#controlling-distribution
_multiprocess_can_split_ = True
# https://docs.python.org/3.7/library/unittest.html#unittest.TestCase.maxDiff
maxDiff = None
"""
return header
示例14: testAssertMultiLineEqual
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import html [as 別名]
def testAssertMultiLineEqual(self):
sample_text = """\
http://www.python.org/doc/2.3/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...]
"""
revised_sample_text = """\
http://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...] You may provide your
own implementation that does not subclass from TestCase, of course.
"""
sample_text_error = """
- http://www.python.org/doc/2.3/lib/module-unittest.html
? ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
? ^^^
test case
- A test case is the smallest unit of testing. [...]
+ A test case is the smallest unit of testing. [...] You may provide your
? +++++++++++++++++++++
+ own implementation that does not subclass from TestCase, of course.
"""
for type1 in (str, unicode):
for type2 in (str, unicode):
self.assertRaisesWithLiteralMatch(AssertionError, sample_text_error,
self.assertMultiLineEqual,
type1(sample_text),
type2(revised_sample_text))
self.assertRaises(AssertionError, self.assertMultiLineEqual, (1, 2), 'str')
self.assertRaises(AssertionError, self.assertMultiLineEqual, 'str', (1, 2))