本文整理汇总了Python中testfixtures.compare函数的典型用法代码示例。如果您正苦于以下问题:Python compare函数的具体用法?Python compare怎么用?Python compare使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no___dict___not_strict_different
def test_no___dict___not_strict_different(self):
if py_34_plus:
expected = (
"\n <C(failed):testfixtures.tests.test_com[42 chars] </C>"
" != <X>",
)
else:
expected = (
"\n"
" <C(failed):testfixtures.tests.test_comparison.X>\n"
" x:1 != 2\n"
" y:2 not in other\n"
" </C> != <X>",
)
x = X()
x.x = 2
try:
self.assertEqual(
C(X, x=1, y=2, strict=False),
x
)
except AssertionError as e:
compare(e.args, expected)
else:
self.fail('No exception raised!')
示例2: test_sprocess_communicate_with_process
def test_sprocess_communicate_with_process(self):
foo = ' foo'
bar = ' bar'
cmd = ["echo", "this is a command" + foo + bar]
p = procopen(cmd, stdoutpipe=True)
stdout, _ = p.communicate()
compare(stdout, b"this is a command foo bar\n")
示例3: test_cleanup_properly
def test_cleanup_properly(self):
r = Replacer()
try:
m = Mock()
d = mkdtemp()
m.return_value = d
r.replace('testfixtures.tempdirectory.mkdtemp',m)
self.failUnless(os.path.exists(d))
self.assertFalse(m.called)
@tempdir()
def test_method(d):
d.write('something', b'stuff')
d.check('something', )
self.assertFalse(m.called)
compare(os.listdir(d),[])
test_method()
self.assertTrue(m.called)
self.failIf(os.path.exists(d))
finally:
r.restore()
if os.path.exists(d):
# only runs if the test fails!
rmtree(d) # pragma: no cover
示例4: test_gotcha_import
def test_gotcha_import(self):
# standard `replace` caveat, make sure you
# patch all revelent places where date
# has been imported:
@replace('datetime.date', test_date())
def test_something():
from datetime import date
compare(date.today(), d(2001, 1, 1))
compare(sample1.str_today_1(), '2001-01-02')
with ShouldRaise(AssertionError) as s:
test_something()
# This convoluted check is because we can't stub
# out the date, since we're testing stubbing out
# the date ;-)
j, dt1, j, dt2, j = s.raised.args[0].split("'")
# check we can parse the date
dt1 = strptime(dt1, '%Y-%m-%d')
# check the dt2 bit was as it should be
compare(dt2, '2001-01-02')
# What you need to do is replace the imported type:
@replace('testfixtures.tests.sample1.date', test_date())
def test_something():
compare(sample1.str_today_1(), '2001-01-01')
test_something()
示例5: test_language_tool_checker
def test_language_tool_checker(self):
target_file = os.path.join(
here, 'languagetool_grammar.pdf')
rez = language_tool_checker.main(target_file=target_file)
compare(rez,
[{'help': 'It would be a honour.',
'id': 'C2000',
'msg': 'misspelling - Use \'an\' instead of \'a\' if '
'the following word starts with a vowel sound,'
' e.g. \'an article\', \'an hour\'',
'msg_name': 'EN_A_VS_AN',
'page': 'Slide 1'},
{'help': 'It would be a honour.',
'id': 'C2005',
'msg': 'misspelling - Possible spelling mistake found',
'msg_name': 'MORFOLOGIK_RULE_EN_US',
'page': 'Slide 1'},
{'help': 'It was only shown on ITV and '
'not B.B.C.',
'id': 'C2005',
'msg': 'misspelling - Possible spelling mistake found',
'msg_name': 'MORFOLOGIK_RULE_EN_US',
'page': 'Slide 1'},
{'help': '... they\'re coats in the cloakroom. '
'I know alot about precious stones. Have '
'you seen th...',
'id': 'C2005',
'msg': 'misspelling - Possible spelling mistake found',
'msg_name': 'MORFOLOGIK_RULE_EN_US',
'page': 'Slide 3'}])
示例6: test_get_admin_resources
def test_get_admin_resources(self):
"""Retrieve admin resources."""
url = reverse("api:resources-detail", args=[self.user.pk])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
expected = {
"quota": 2,
"mailboxes": 2,
"domain_admins": 2,
"domain_aliases": 2,
"domains": 2,
"mailbox_aliases": 2
}
compare(expected, response.data)
# As reseller => fails
self.client.credentials(
HTTP_AUTHORIZATION="Token {}".format(self.r_token.key))
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
# As domain admin => fails
self.client.credentials(
HTTP_AUTHORIZATION="Token {}".format(self.da_token.key))
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
示例7: test_plugin_versions
def test_plugin_versions(self):
self._write_jpi('test1', """
Url: http://wiki.jenkins-ci.org/display/JENKINS/Ant+Plugin
Junk: 1.0
Extension-Name: test1
Implementation-Title: test1
Implementation-Version: 2
Plugin-Version: 2
""")
self._write_jpi('test2', """
Junk: 1.0
Extension-Name: test2
Implementation-Title: test2
Implementation-Version: 1
Plugin-Version: 1
""")
plugin = self.make_plugin()
plugin.write_plugin_versions(self.dir.path, self.dir.path)
compare(
self.dir.read(self.dir.getpath('plugin-versions.txt')),
expected=os.linesep.join((
'test1: 2',
'test2: 1',
'',
)))
示例8: test_nested_working
def test_nested_working(self):
config1 = Config(dict(x=1, y=[2, 3], z=dict(a=4, b=5)))
config2 = Config(dict(w=6, y=[7], z=dict(b=8, c=9)))
config1.merge(config2)
compare(config1.data,
expected=dict(x=1, w=6, y=[2, 3, 7], z=dict(a=4, b=8, c=9)))
示例9: test_override_type_mapping
def test_override_type_mapping(self):
config1 = Config([1, 2])
config2 = Config([3, 4])
def zipper(context, source, target):
return zip(target, source)
config1.merge(config2, mergers={list: zipper})
compare(config1.data, expected=[(1, 3), (2, 4)])
示例10: test_set_rdsheet_trim
def test_set_rdsheet_trim(self):
r = TestReader(
('Sheet1',[['X',' ']]),
('Sheet2',[['X','X']]),
)
book = tuple(r.get_workbooks())[0][0]
# fire methods on filter
f = ColumnTrimmer()
f.next = c = Mock()
f.start()
f.workbook(book,'new.xls')
f.sheet(book.sheet_by_index(0),'new')
f.row(0,0)
f.cell(0,0,0,0)
f.cell(0,1,0,1)
f.set_rdsheet(book.sheet_by_index(1))
f.cell(0,0,1,0)
f.cell(0,1,1,1)
f.finish()
compare(c.method_calls,[
('start', (), {}),
('workbook', (C('xlutils.tests.fixtures.DummyBook'), 'new.xls'),{}),
('sheet', (C('xlrd.sheet.Sheet',name='Sheet1',strict=False), u'new'),{}),
('row', (0, 0),{}),
('cell', (0, 0, 0, 0),{}),
('cell', (0, 1, 0, 1),{}),
('set_rdsheet', (C('xlrd.sheet.Sheet',name='Sheet2',strict=False),),{}),
('cell', (0, 0, 1, 0),{}),
('cell', (0, 1, 1, 1),{}),
('finish', (), {})
])
示例11: test_use_write_sheet_name_in_logging
def test_use_write_sheet_name_in_logging(self,h):
r = TestReader(
('Sheet1',[['X',' ']]),
)
book = tuple(r.get_workbooks())[0][0]
# fire methods on filter
f = ColumnTrimmer()
f.next = c = Mock()
f.start()
f.workbook(book,'new.xls')
f.sheet(book.sheet_by_index(0),'new')
f.row(0,0)
f.cell(0,0,0,0)
f.cell(0,1,0,1)
f.finish()
compare(c.method_calls,[
('start', (), {}),
('workbook', (C('xlutils.tests.fixtures.DummyBook'), 'new.xls'),{}),
('sheet', (C('xlrd.sheet.Sheet',name='Sheet1',strict=False), u'new'),{}),
('row', (0, 0),{}),
('cell', (0, 0, 0, 0),{}),
('finish', (),{})
])
h.check((
'xlutils.filter',
'DEBUG',
"Number of columns trimmed from 2 to 1 for sheet 'new'"
))
示例12: test_start
def test_start(self,d):
f = ErrorFilter()
f.next = m = Mock()
f.wtbook = 'junk'
f.handler.fired = 'junk'
f.temp_path = d.path
f.prefix = 'junk'
j = open(os.path.join(d.path,'junk.xls'),'wb')
j.write('junk')
j.close()
f.start()
compare(f.wtbook,None)
compare(f.handler.fired,False)
self.failIf(os.path.exists(d.path))
compare(os.listdir(f.temp_path),[])
compare(f.prefix,0)
f.finish()
compare(m.method_calls,[
('start', (), {}),
('finish', (), {})
])
示例13: test_custom_filepaths
def test_custom_filepaths(self):
# also tests the __call__ method
class TestReader(BaseReader):
def get_filepaths(self):
return (test_xls_path,)
t = TestReader()
f = Mock()
t(f)
compare(f.method_calls,[
('start',(),{}),
('workbook',(C('xlrd.Book',
pickleable=0,
formatting_info=1,
on_demand=True,
strict=False),'test.xls'),{}),
('sheet',(C('xlrd.sheet.Sheet'),u'Sheet1'),{}),
('row',(0,0),{}),
('cell',(0,0,0,0),{}),
('cell',(0,1,0,1),{}),
('row',(1,1),{}),
('cell',(1,0,1,0),{}),
('cell',(1,1,1,1),{}),
('sheet',(C('xlrd.sheet.Sheet'),u'Sheet2'),{}),
('row',(0,0),{}),
('cell',(0,0,0,0),{}),
('cell',(0,1,0,1),{}),
('row',(1,1),{}),
('cell',(1,0,1,0),{}),
('cell',(1,1,1,1),{}),
('finish',(),{}),
])
示例14: test_multiple_workbooks_with_same_name
def test_multiple_workbooks_with_same_name(self,h):
r = TestReader(
('Sheet1',[['S1R0C0']]),
)
book = tuple(r.get_workbooks())[0][0]
# fire methods on filter
f = ErrorFilter()
f.next = c = Mock()
f.start()
f.workbook(book,'new.xls')
f.sheet(book.sheet_by_index(0),'new1')
f.cell(0,0,0,0)
f.workbook(book,'new.xls')
f.sheet(book.sheet_by_index(0),'new2')
f.cell(0,0,0,0)
f.finish()
compare(c.method_calls,[
('start', (), {}),
('workbook', (C('xlrd.Book'), 'new.xls'),{}),
('sheet', (C('xlrd.sheet.Sheet',name='new1',strict=False), u'new1'),{}),
('row', (0, 0),{}),
('cell', (0, 0, 0, 0),{}),
('workbook', (C('xlrd.Book'), 'new.xls'),{}),
('sheet', (C('xlrd.sheet.Sheet',name='new2',strict=False), u'new2'),{}),
('row', (0, 0),{}),
('cell', (0, 0, 0, 0),{}),
('finish', (), {})
])
self.assertEqual(len(h.records),0)
示例15: test_stream_with_name_guess_parser
def test_stream_with_name_guess_parser(self):
with NamedTemporaryFile(suffix='.json') as source:
source.write(b'{"x": 1}')
source.flush()
source.seek(0)
config = Config.from_stream(source)
compare(config.x, expected=1)