本文整理汇总了Python中tests.patcher.OsPatcher类的典型用法代码示例。如果您正苦于以下问题:Python OsPatcher类的具体用法?Python OsPatcher怎么用?Python OsPatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OsPatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CMakeTest
class CMakeTest(TestCase):
def setUp(self):
self._config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'bdemeta.json': '{"roots": ["r"]}',
'r': {
'standalones': {
'p': {
'package': {
'p.dep': '',
'p.mem': '',
},
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_generate_cmake(self):
output1 = StringIO()
run(output1, None, output1, None, ['cmake', 'bdemeta.json', 'p'])
r = TargetResolver(self._config)
p = resolve(r, 'p')
output2 = StringIO()
generate(p, output2)
assert(output1.getvalue() == output2.getvalue())
示例2: NoConfigMainTest
class NoConfigMainTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({
})
def tearDown(self):
self._patcher.reset()
def test_help_text(self):
stdout = StringIO()
stderr = StringIO()
main(stdout, stderr, None, None, [__name__])
assert(not stdout.getvalue())
assert(stderr.getvalue())
def test_no_config_error(self):
stdout = StringIO()
stderr = StringIO()
main(stdout,
stderr,
None,
None,
[__name__, 'walk', 'bdemeta.json', 'p1'])
assert(not stdout.getvalue())
assert(stderr.getvalue())
示例3: RunTest
class RunTest(TestCase):
def setUp(self):
self._config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'.bdemeta.conf': '{"roots": ["r"]}',
'r': {
'groups': {
'gr1': {
'group': {
'gr1.dep': '',
'gr1.mem': 'gr1p1 gr1p2',
},
'gr1p1': {
'package': {
'gr1p1.dep': '',
'gr1p1.mem': '',
},
},
'gr1p2': {
'package': {
'gr1p2.dep': '',
'gr1p2.mem': '',
},
},
},
'gr2': {
'group': {
'gr2.dep': 'gr1',
'gr2.mem': '',
},
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_no_mode_error(self):
with self.assertRaises(InvalidArgumentsError) as e:
run(None, None, None, None, None, [])
assert('No mode specified' == e.exception.args[0])
def test_unknown_mode_error(self):
with self.assertRaises(InvalidArgumentsError) as e:
run(None, None, None, None, None, ['foo'])
assert('Unknown mode \'{}\''.format('foo') == e.exception.args[0])
def test_target_with_dependencies(self):
f = StringIO()
run(f, None, None, None, None, ['walk', 'gr2'])
r = TargetResolver(self._config)
us = resolve(r, ['gr2'])
assert(' '.join(u.name for u in us) + '\n' == f.getvalue())
示例4: CMakeResolverTest
class CMakeResolverTest(TestCase):
def setUp(self):
self.config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'r': {
'thirdparty': {
't1': {
'CMakeLists.txt': '',
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_cmake_identification(self):
r = TargetResolver(self.config)
assert({
'type': 'cmake',
'path': P('r')/'thirdparty'/'t1'
} == r.identify('t1'))
def test_cmake_path(self):
r = TargetResolver(self.config)
t = r.resolve('t1', {})
assert(P('r')/'thirdparty'/'t1' == t.path())
示例5: GraphTest
class GraphTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({
'.bdemeta.conf': '{"roots": ["r"]}',
'r': {
'adapters': {
'p1': {
'package': {
'p1.dep': '',
'p1.mem': '',
},
},
'p2': {
'package': {
'p2.dep': 'p1',
'p2.mem': '',
},
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_graph(self):
f = StringIO()
run(f, None, None, None, None, ['dot', 'p2'])
lines = f.getvalue().split('\n')
assert('digraph G {' == lines[0])
assert(' "p2" -> "p1"' == lines[1])
assert('}' == lines[2])
示例6: NoRootTest
class NoRootTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({
'bdemeta.json': '{"roots": ["r"]}',
})
def tearDown(self):
self._patcher.reset()
def test_no_root_error(self):
with self.assertRaises(InvalidPathError) as e:
run(None, None, None, None, ['walk', 'bdemeta.json'])
assert(P('r') == e.exception.args[0])
def test_no_root_main_error(self):
stdout = StringIO()
stderr = StringIO()
main(stdout,
stderr,
None,
None,
[__name__, 'walk', 'bdemeta.json', 'p1'])
assert(not stdout.getvalue())
assert(stderr.getvalue())
assert('r' in stderr.getvalue())
示例7: BdeItemsTest
class BdeItemsTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({
'one': {
'char': 'a',
'commented': {
'item': '# a',
},
'real': {
'one': {
'comment': 'a\n#b',
},
},
},
'longer': {
'char': 'ab',
},
'two': {
'same': {
'line': 'a b',
},
'diff': {
'lines': 'a\nb',
},
'commented': {
'same': {
'line': '# a b',
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_one_char_item(self):
assert({'a'} == bde_items(P('one')/'char'))
def test_longer_char_item(self):
assert({'ab'} == bde_items(P('longer')/'char'))
def test_two_items_on_same_line(self):
assert({'a', 'b'} == bde_items(P('two')/'same'/'line'))
def test_item_on_each_line(self):
assert({'a', 'b'} == bde_items(P('two')/'diff'/'lines'))
def test_one_commented_item(self):
assert(set() == bde_items(P('one')/'commented'/'item'))
def test_two_commented_items_same_line(self):
assert(set() == bde_items(P('two')/'commented'/'same'/'line'))
def test_one_real_one_comment(self):
assert({'a'} == bde_items(P('one')/'real'/'one'/'comment'))
示例8: NoConfigErrorTest
class NoConfigErrorTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({})
def tearDown(self):
self._patcher.reset()
def test_no_config_error(self):
caught = False
try:
run(StringIO(), ['walk', 'foo'])
except NoConfigError as e:
caught = True
assert(caught)
示例9: setUp
def setUp(self):
self._patcher = OsPatcher({
'bdemeta.json': '{"roots": ["r"]}',
'r': {
'standalones': {
'p1': {
'package': {
'p1.dep': '',
'p1.mem': '',
},
},
'p2': {
'package': {
'p2.dep': 'p1',
'p2.mem': '',
},
},
'p3': {
'package': {
'p3.dep': 'p4',
'p3.mem': '',
},
},
'p4': {
'package': {
'p4.dep': 'p3',
'p4.mem': '',
},
},
},
},
})
示例10: InvalidPathErrorTest
class InvalidPathErrorTest(TestCase):
def setUp(self):
self._patcher = OsPatcher({
'.bdemeta.conf': '{ "roots": ["unlikely_path_that_exists"] }',
})
def tearDown(self):
self._patcher.reset()
def test_invalid_path_error(self):
with self.assertRaises(InvalidPathError):
run(None, None, None, None, None, ['walk', 'foo'])
stderr = StringIO()
main(None, stderr, None, None, None, [__name__, 'walk', 'foo'])
assert(stderr.getvalue())
示例11: setUp
def setUp(self):
self.config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'r': {
'adapters': {
'p1': {
'package': {
'p1.dep': '',
'p1.mem': 'p1c1 p1c2',
},
},
'p2': {
'package': {
'p2.dep': 'p1',
'p2.mem': '',
},
},
'p3': {
'package': {
'p3.dep': '',
'p3.mem': '',
},
'p3.cmake': '',
},
},
},
})
示例12: setUp
def setUp(self):
self._patcher = OsPatcher({
'one': {
'char': 'a',
'commented': {
'item': '# a',
},
'real': {
'one': {
'comment': 'a\n#b',
},
},
},
'longer': {
'char': 'ab',
},
'two': {
'same': {
'line': 'a b',
},
'diff': {
'lines': 'a\nb',
},
'commented': {
'same': {
'line': '# a b',
},
},
},
})
示例13: NotFoundErrorsTest
class NotFoundErrorsTest(TestCase):
def setUp(self):
self.config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'r': { },
})
def tearDown(self):
self._patcher.reset()
def test_non_identification(self):
r = TargetResolver(self.config)
with self.assertRaises(TargetNotFoundError):
r.identify('foo')
示例14: CMakeTest
class CMakeTest(TestCase):
def setUp(self):
self._config = {
'roots': [
P('r'),
]
}
self._patcher = OsPatcher({
'.bdemeta.conf': '{"roots": ["r"]}',
'r': {
'adapters': {
'p': {
'package': {
'p.dep': '',
'p.mem': '',
},
},
},
},
})
def tearDown(self):
self._patcher.reset()
def test_generate_cmake(self):
output = StringIO()
f1 = {}
w1 = get_filestore_writer(f1)
run(output, None, w1, None, None, ['cmake', 'p'])
r = TargetResolver(self._config)
p = resolve(r, 'p')
f2 = {}
w2 = get_filestore_writer(f2)
generate(p, w2)
assert(f1.keys() == f2.keys())
for k in f1:
assert(f1[k].getvalue() == f2[k].getvalue())
示例15: LazilyBoundTest
class LazilyBoundTest(TestCase):
def setUp(self):
self.config = {
'roots': [
P('r'),
],
'providers': {
'p1': ['bar']
},
'runtime_libraries': [
'bar'
]
}
self._patcher = OsPatcher({
'r': {
'adapters': {
'p1': {
'package': {
'p1.dep': '',
'p1.mem': '',
},
},
'p2': {
'package': {
'p2.dep': 'bar',
'p2.mem': '',
},
}
},
}
})
def tearDown(self):
self._patcher.reset()
def test_lazily_bound_bar(self):
r = TargetResolver(self.config)
p1 = r.resolve('p1', {})
bar = r.resolve('bar', { 'p1': p1 })
p2 = r.resolve('p2', { 'bar': bar, 'p1': p1 })
assert(p2.lazily_bound)