本文整理匯總了Python中gears.environment.Environment.list方法的典型用法代碼示例。如果您正苦於以下問題:Python Environment.list方法的具體用法?Python Environment.list怎麽用?Python Environment.list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gears.environment.Environment
的用法示例。
在下文中一共展示了Environment.list方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: EnvironmentListTests
# 需要導入模塊: from gears.environment import Environment [as 別名]
# 或者: from gears.environment.Environment import list [as 別名]
class EnvironmentListTests(TestCase):
def setUp(self):
self.environment = Environment(STATIC_DIR)
self.environment.register_defaults()
self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))
def test_list(self):
items = list(self.environment.list("js/templates", "application/javascript"))
self.assertEqual(len(items), 3)
for i, item in enumerate(sorted(items, key=lambda x: x[1])):
path = "js/templates/%s.js.handlebars" % "abc"[i]
asset_attributes, absolute_path = item
self.assertIsInstance(asset_attributes, AssetAttributes)
self.assertEqual(asset_attributes.path, path)
self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))
def test_list_recursively(self):
items = list(self.environment.list("js/templates", "application/javascript", recursive=True))
self.assertEqual(len(items), 4)
for i, item in enumerate(sorted(items, key=lambda x: x[1])):
path = "js/templates/%s.js.handlebars" % ("a", "b", "c", "d/e")[i]
asset_attributes, absolute_path = item
self.assertIsInstance(asset_attributes, AssetAttributes)
self.assertEqual(asset_attributes.path, path)
self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))
示例2: EnvironmentListTests
# 需要導入模塊: from gears.environment import Environment [as 別名]
# 或者: from gears.environment.Environment import list [as 別名]
class EnvironmentListTests(TestCase):
def setUp(self):
self.environment = Environment(STATIC_DIR)
self.environment.register_defaults()
self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))
def test_list(self):
items = list(self.environment.list('js/templates', ['.js', '.handlebars']))
self.assertEqual(len(items), 3)
for i, item in enumerate(sorted(items, key=lambda x: x[1])):
path = 'js/templates/%s.js.handlebars' % 'abc'[i]
asset_attributes, absolute_path = item
self.assertIsInstance(asset_attributes, AssetAttributes)
self.assertEqual(asset_attributes.path, path)
self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))