本文整理汇总了Python中carbon.rewrite.RewriteRuleManager.read_rules方法的典型用法代码示例。如果您正苦于以下问题:Python RewriteRuleManager.read_rules方法的具体用法?Python RewriteRuleManager.read_rules怎么用?Python RewriteRuleManager.read_rules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类carbon.rewrite.RewriteRuleManager
的用法示例。
在下文中一共展示了RewriteRuleManager.read_rules方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_clears_if_no_file
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_read_clears_if_no_file(self):
import carbon.rewrite
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'exists', Mock(return_value=False)):
with patch.object(RewriteRuleManager, 'clear') as clear_mock:
RewriteRuleManager.read_rules()
clear_mock.assert_called_once_with()
示例2: test_read_records_mtime
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_read_records_mtime(self):
import carbon.rewrite
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertEqual(1234, RewriteRuleManager.rules_last_read)
示例3: test_read_opens_file_if_mtime_newer
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_read_opens_file_if_mtime_newer(self):
import carbon.rewrite
RewriteRuleManager.rules_last_read = 1234
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=5678)):
RewriteRuleManager.read_rules()
self.assertTrue(open_mock.called)
示例4: test_comments_ignored
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_comments_ignored(self):
import carbon.rewrite
open_mock = Mock(return_value=iter(self.commented_config.splitlines()))
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', open_mock, create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertEqual(1, len(RewriteRuleManager.rules('pre')))
示例5: test_section_parsed_into_ruleset
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_section_parsed_into_ruleset(self):
import carbon.rewrite
open_mock = Mock(return_value=iter(self.sample_config.splitlines()))
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', open_mock, create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertTrue('pre' in RewriteRuleManager.rulesets)
示例6: test_read_doesnt_open_file_if_mtime_unchanged
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_read_doesnt_open_file_if_mtime_unchanged(self):
import carbon.rewrite
mtime = 1234
RewriteRuleManager.rules_last_read = mtime
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertFalse(open_mock.called)
示例7: test_rules_unchanged_if_mtime_unchanged
# 需要导入模块: from carbon.rewrite import RewriteRuleManager [as 别名]
# 或者: from carbon.rewrite.RewriteRuleManager import read_rules [as 别名]
def test_rules_unchanged_if_mtime_unchanged(self):
import carbon.rewrite
mtime = 1234
rulesets = {'pre': [Mock(RewriteRule)]}
RewriteRuleManager.rules_last_read = mtime
RewriteRuleManager.rulesets.update(rulesets)
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=mtime)):
RewriteRuleManager.read_rules()
self.assertEqual(rulesets, RewriteRuleManager.rulesets)