本文整理汇总了Python中testfixtures.compare函数的典型用法代码示例。如果您正苦于以下问题:Python compare函数的具体用法?Python compare怎么用?Python compare使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compare函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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!')
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:25,代码来源:test_comparison.py
示例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")
开发者ID:dpmatthews,项目名称:cylc,代码行数:7,代码来源:test_cylc_subproc.py
示例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
开发者ID:jonflusspferd,项目名称:testfixtures,代码行数:30,代码来源:test_tempdir.py
示例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()
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:28,代码来源:test_date.py
示例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'}])
开发者ID:alunix,项目名称:slidelint,代码行数:30,代码来源:TestCheckerLanguageTool.py
示例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)
开发者ID:brucewu16899,项目名称:modoboa,代码行数:26,代码来源:test_api.py
示例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',
'',
)))
开发者ID:Simplistix,项目名称:archivist,代码行数:27,代码来源:test_source_jenkins.py
示例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)))
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
示例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)])
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
示例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', (), {})
])
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:31,代码来源:test_filter.py
示例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'"
))
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:28,代码来源:test_filter.py
示例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', (), {})
])
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:25,代码来源:test_filter.py
示例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',(),{}),
])
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:31,代码来源:test_filter.py
示例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)
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:29,代码来源:test_filter.py
示例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)
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
示例16: test_type_returns_new_object
def test_type_returns_new_object(self):
config1 = Config((1, 2))
config2 = Config((3, 4))
def concat(context, source, target):
return target + source
config1.merge(config2, mergers={tuple: concat})
compare(config1.data, expected=(1, 2, 3, 4))
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
示例17: test_gotcha_import
def test_gotcha_import(self):
# standard `replace` caveat, make sure you
# patch all revelent places where time
# has been imported:
@replace('time.time',test_time())
def test_something():
from time import time
compare(time(),978307200.0)
compare(sample1.str_time(),'978307201.0')
s = should_raise(test_something,AssertionError)
s()
# This convoluted check is because we can't stub
# out time, since we're testing stubbing out time ;-)
j,t1,j,t2,j = s.raised.args[0].split("'")
# check we can parse the time
t1 = float(t1)
# check the t2 bit was as it should be
compare(t2,'978307201.0')
# What you need to do is replace the imported type:
@replace('testfixtures.tests.sample1.time',test_time())
def test_something():
compare(sample1.str_time(),'978307200.0')
test_something()
开发者ID:Lothiraldan,项目名称:testfixtures,代码行数:28,代码来源:test_time.py
示例18: test_supplement_type_mapping
def test_supplement_type_mapping(self):
config1 = Config({'x': (1, 2)})
config2 = Config({'x': (3, 4)})
def concat(context, source, target):
return target + source
config1.merge(config2, mergers=default_mergers+{tuple: concat})
compare(config1.data, expected={'x': (1, 2, 3, 4)})
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
示例19: test_load_local_requirements__with_blanks
def test_load_local_requirements__with_blanks(self,
mock_path_exists
):
"""
TestShakerMetadata::test_load_local_requirements: Test loading from local dependency file with blanks and comments
"""
# Setup
mock_path_exists.return_value = True
text_file_data = '\n'.join(["[email protected]:test_organisation/test1-formula.git==v1.0.1",
"",
"[email protected]:test_organisation/test2-formula.git==v2.0.1",
" ",
"#DONT_READ_ME",
"[email protected]:test_organisation/test3-formula.git==v3.0.1"])
with patch('__builtin__.open',
mock_open(read_data=()),
create=True) as mopen:
mopen.return_value.__iter__.return_value = text_file_data.splitlines()
shaker.libs.logger.Logger().setLevel(logging.DEBUG)
tempobj = ShakerMetadata(autoload=False)
input_directory = '.'
input_filename = 'test'
tempobj.load_local_requirements(input_directory, input_filename)
mock_path_exists.assert_called_once_with('./test')
mopen.assert_called_once_with('./test', 'r')
testfixtures.compare(tempobj.local_requirements, self._sample_dependencies)
开发者ID:eedgar,项目名称:salt-shaker,代码行数:27,代码来源:test_shaker_metadata.py
示例20: test_mapping_paths
def test_mapping_paths(self):
config = Config({'x': 'old'})
data = {'foo': 'bar'}
config.merge(data, mapping={
source['foo']: target['x']
})
compare(config.data, expected={'x': 'bar'})
开发者ID:Simplistix,项目名称:configurator,代码行数:7,代码来源:test_config.py
注:本文中的testfixtures.compare函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论