本文整理匯總了Python中mozbuild.frontend.context.Context.add_source方法的典型用法代碼示例。如果您正苦於以下問題:Python Context.add_source方法的具體用法?Python Context.add_source怎麽用?Python Context.add_source使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mozbuild.frontend.context.Context
的用法示例。
在下文中一共展示了Context.add_source方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_context_paths
# 需要導入模塊: from mozbuild.frontend.context import Context [as 別名]
# 或者: from mozbuild.frontend.context.Context import add_source [as 別名]
def test_context_paths(self):
test = Context()
# Newly created context has no paths.
self.assertIsNone(test.main_path)
self.assertIsNone(test.current_path)
self.assertEqual(test.all_paths, set())
self.assertEqual(test.source_stack, [])
foo = os.path.abspath("foo")
test.add_source(foo)
# Adding the first source makes it the main and current path.
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, foo)
self.assertEqual(test.all_paths, set([foo]))
self.assertEqual(test.source_stack, [foo])
bar = os.path.abspath("bar")
test.add_source(bar)
# Adding the second source makes leaves main and current paths alone.
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, foo)
self.assertEqual(test.all_paths, set([bar, foo]))
self.assertEqual(test.source_stack, [foo])
qux = os.path.abspath("qux")
test.push_source(qux)
# Pushing a source makes it the current path
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, qux)
self.assertEqual(test.all_paths, set([bar, foo, qux]))
self.assertEqual(test.source_stack, [foo, qux])
hoge = os.path.abspath("hoge")
test.push_source(hoge)
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, hoge)
self.assertEqual(test.all_paths, set([bar, foo, hoge, qux]))
self.assertEqual(test.source_stack, [foo, qux, hoge])
fuga = os.path.abspath("fuga")
# Adding a source after pushing doesn't change the source stack
test.add_source(fuga)
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, hoge)
self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
self.assertEqual(test.source_stack, [foo, qux, hoge])
# Adding a source twice doesn't change anything
test.add_source(qux)
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, hoge)
self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
self.assertEqual(test.source_stack, [foo, qux, hoge])
last = test.pop_source()
# Popping a source returns the last pushed one, not the last added one.
self.assertEqual(last, hoge)
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, qux)
self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
self.assertEqual(test.source_stack, [foo, qux])
last = test.pop_source()
self.assertEqual(last, qux)
self.assertEqual(test.main_path, foo)
self.assertEqual(test.current_path, foo)
self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
self.assertEqual(test.source_stack, [foo])
# Popping the main path is allowed.
last = test.pop_source()
self.assertEqual(last, foo)
self.assertEqual(test.main_path, foo)
self.assertIsNone(test.current_path)
self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
self.assertEqual(test.source_stack, [])
# Popping past the main path asserts.
with self.assertRaises(AssertionError):
test.pop_source()
# Pushing after the main path was popped asserts.
with self.assertRaises(AssertionError):
test.push_source(foo)
test = Context()
test.push_source(foo)
test.push_source(bar)
# Pushing the same file twice is allowed.
test.push_source(bar)
test.push_source(foo)
self.assertEqual(last, foo)
self.assertEqual(test.main_path, foo)
#.........這裏部分代碼省略.........