本文整理汇总了Python中trac.util.create_file函数的典型用法代码示例。如果您正苦于以下问题:Python create_file函数的具体用法?Python create_file怎么用?Python create_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
tmpdir = os.path.realpath(tempfile.gettempdir())
self.env = EnvironmentStub(enable=['trac.*', AuthzPolicy], path=tmpdir)
self.env.config.set('trac', 'permission_policies',
'AuthzPolicy, DefaultPermissionPolicy')
self.env.config.set('ticket', 'restrict_owner', True)
self.perm_sys = PermissionSystem(self.env)
self.env.insert_known_users([
('user1', '', ''), ('user2', '', ''),
('user3', '', ''), ('user4', '', '')
])
self.perm_sys.grant_permission('user1', 'TICKET_MODIFY')
self.perm_sys.grant_permission('user2', 'TICKET_VIEW')
self.perm_sys.grant_permission('user3', 'TICKET_MODIFY')
self.perm_sys.grant_permission('user4', 'TICKET_MODIFY')
self.authz_file = os.path.join(tmpdir, 'trac-authz-policy')
create_file(self.authz_file)
self.env.config.set('authz_policy', 'authz_file', self.authz_file)
self.ctlr = TicketSystem(self.env).action_controllers[0]
self.req1 = Mock(authname='user1', args={},
perm=PermissionCache(self.env, 'user1'))
self.ticket = Ticket(self.env)
self.ticket['status'] = 'new'
self.ticket.insert()
示例2: test_inherit_multiple
def test_inherit_multiple(self):
class Foo(object):
option_b = Option("b", "option2", "default")
base = os.path.dirname(self.filename)
relsite1 = os.path.join("sub1", "trac-site1.ini")
site1 = os.path.join(base, relsite1)
relsite2 = os.path.join("sub2", "trac-site2.ini")
site2 = os.path.join(base, relsite2)
os.mkdir(os.path.dirname(site1))
create_file(site1, "[a]\noption1 = x\n" "[c]\noption = 1\npath1 = site1\n")
try:
os.mkdir(os.path.dirname(site2))
create_file(site2, "[b]\noption2 = y\n" "[c]\noption = 2\npath2 = site2\n")
try:
self._write(["[inherit]", "file = %s, %s" % (relsite1, relsite2)])
config = self._read()
self.assertEqual("x", config.get("a", "option1"))
self.assertEqual("y", config.get("b", "option2"))
self.assertEqual("1", config.get("c", "option"))
self.assertEqual(os.path.join(base, "site1"), config.getpath("c", "path1"))
self.assertEqual(os.path.join(base, "site2"), config.getpath("c", "path2"))
self.assertEqual("", config.getpath("c", "path3"))
self.assertEqual(os.path.join(base, "site4"), config.getpath("c", "path4", "site4"))
finally:
os.remove(site2)
os.rmdir(os.path.dirname(site2))
finally:
os.remove(site1)
os.rmdir(os.path.dirname(site1))
示例3: test_get_historian
def test_get_historian(self):
paths = [u'normal-path.txt',
u'tickét.tx\\t',
u'\a\b\t\n\v\f\r\x1b"\\.tx\\t']
for path in paths:
path_utf8 = path.encode('utf-8')
create_file(os.path.join(self.repos_path, path_utf8))
self._git('add', path_utf8)
self._git_commit('-m', 'ticket:11180 and ticket:11198',
date=datetime(2013, 4, 30, 17, 48, 57))
def validate(path, quotepath):
self._git('config', 'core.quotepath', quotepath)
storage = self._storage()
rev = storage.head()
with storage.get_historian('HEAD', path) as historian:
hrev = storage.last_change('HEAD', path, historian)
self.assertEquals(rev, hrev)
validate(paths[0], 'true')
validate(paths[0], 'false')
validate(paths[1], 'true')
validate(paths[1], 'false')
validate(paths[2], 'true')
validate(paths[2], 'false')
示例4: test_existing
def test_existing(self):
util.create_file(self.path, 'Some content')
self.assertEqual('Some content', util.read_file(self.path))
with util.AtomicFile(self.path) as f:
f.write('Some new content')
self.assertEqual(True, f.closed)
self.assertEqual('Some new content', util.read_file(self.path))
示例5: runTest
def runTest(self):
env = self._testenv.get_trac_environment()
env.config.set('components', 'RaiseExceptionPlugin.*', 'enabled')
env.config.save()
create_file(os.path.join(env.path, 'plugins', 'RaiseExceptionPlugin.py'),
"""\
from trac.core import Component, implements
from trac.web.api import IRequestHandler
url = 'http://trac-hacks.org/wiki/HelloWorldMacro'
class RaiseExceptionPlugin(Component):
implements(IRequestHandler)
def match_request(self, req):
if req.path_info == '/raise-exception':
return True
def process_request(self, req):
raise Exception
""")
try:
tc.go(self._tester.url + '/raise-exception')
tc.find(internal_error)
tc.find('<form class="newticket" method="get" '
'action="http://trac-hacks.org/newticket">')
tc.find('<input type="hidden" name="component" '
'value="HelloWorldMacro" />')
finally:
env.config.set('components', 'RaiseExceptionPlugin.*', 'disabled')
示例6: test_sync
def test_sync(self):
self._git_init()
for idx in xrange(3):
filename = 'file%d.txt' % idx
create_file(os.path.join(self.repos_path, filename))
self._git('add', filename)
self._git_commit('-a', '-m', filename,
date=datetime(2014, 2, 2, 17, 12, idx))
self._add_repository('gitrepos')
repos = self._repomgr.get_repository('gitrepos')
revs = [entry[1] for entry in repos.repos.get_node('').get_history()]
revs.reverse()
revs2 = []
def feedback(rev):
revs2.append(rev)
repos.sync(feedback=feedback)
self.assertEqual(revs, revs2)
self.assertEqual(4, len(revs2))
revs2 = []
def feedback_1(rev):
revs2.append(rev)
if len(revs2) == 2:
raise StopSync
def feedback_2(rev):
revs2.append(rev)
try:
repos.sync(feedback=feedback_1, clean=True)
except StopSync:
self.assertEqual(revs[:2], revs2)
repos.sync(feedback=feedback_2) # restart sync
self.assertEqual(revs, revs2)
示例7: test_coarse_permissions
def test_coarse_permissions(self):
# Granted to all due to wildcard
self.assertPathPerm(True, 'unknown')
self.assertPathPerm(True, 'joe')
self.assertRevPerm(True, 'unknown')
self.assertRevPerm(True, 'joe')
# Granted if at least one fine permission is granted
self.policy._mtime = 0
create_file(self.authz, """\
[/somepath]
joe = r
denied =
[module:/otherpath]
jane = r
$anonymous = r
[inactive:/not-in-this-instance]
unknown = r
""")
self.assertPathPerm(None, 'unknown')
self.assertRevPerm(None, 'unknown')
self.assertPathPerm(None, 'denied')
self.assertRevPerm(None, 'denied')
self.assertPathPerm(True, 'joe')
self.assertRevPerm(True, 'joe')
self.assertPathPerm(True, 'jane')
self.assertRevPerm(True, 'jane')
self.assertPathPerm(True, 'anonymous')
self.assertRevPerm(True, 'anonymous')
示例8: _test_timerange
def _test_timerange(self, cached_repository):
self.env.config.set('git', 'cached_repository', cached_repository)
self._git_init()
filename = os.path.join(self.repos_path, '.gitignore')
start = datetime(2000, 1, 1, 0, 0, 0, 0, utc)
ts = datetime(2014, 2, 5, 15, 24, 6, 0, utc)
for idx in xrange(3):
create_file(filename, 'commit-%d.txt' % idx)
self._git_commit('-a', '-m', 'commit %d' % idx, date=ts)
self._add_repository()
repos = self._repomgr.get_repository('gitrepos')
repos.sync()
revs = [repos.youngest_rev]
while True:
parents = repos.parent_revs(revs[-1])
if not parents:
break
revs.extend(parents)
self.assertEqual(4, len(revs))
csets = list(repos.get_changesets(start, ts))
self.assertEqual(1, len(csets))
self.assertEqual(revs[-1], csets[0].rev) # is oldest rev
csets = list(repos.get_changesets(start, ts + timedelta(seconds=1)))
self.assertEqual(revs, [cset.rev for cset in csets])
示例9: setUp
def setUp(self):
self.parent_dir = tempfile.mkdtemp(prefix="trac-")
self.tracignore = os.path.join(self.parent_dir, ".tracignore")
for dname in self.dirs:
os.mkdir(os.path.join(self.parent_dir, dname))
for fname in self.files:
create_file(os.path.join(self.parent_dir, fname))
self.environ = {"trac.env_paths": [], "trac.env_parent_dir": self.parent_dir}
示例10: test_parse_authz_malformed_raises
def test_parse_authz_malformed_raises(self):
"""ConfigurationError should be raised if the file is malformed."""
create_file(self.authz_file, """\
wiki:WikiStart]
änon = WIKI_VIEW
* =
""")
authz_policy = AuthzPolicy(self.env)
self.assertRaises(ConfigurationError, authz_policy.parse_authz)
示例11: setUp
def setUp(self):
self.status = None
self.headers = None
self.response = StringIO()
self.dir = tempfile.mkdtemp(prefix='trac-')
self.filename = os.path.join(self.dir, 'test.txt')
self.data = 'contents\n'
create_file(self.filename, self.data, 'wb')
self.req = None
示例12: test_migrate_with_plugin_py_to_sqlite_env
def test_migrate_with_plugin_py_to_sqlite_env(self):
dburi = get_dburi()
if dburi == 'sqlite::memory:':
dburi = 'sqlite:db/trac.db'
self._create_env(self.src_path, dburi)
plugin_name = self._generate_module_name() + '.py'
create_file(os.path.join(self.src_path, 'plugins', plugin_name),
_plugin_py)
self._test_migrate_with_plugin_to_sqlite_env()
示例13: test_existing
def test_existing(self):
util.create_file(self.path, 'Some content')
self.assertEqual('Some content', util.read_file(self.path))
f = util.AtomicFile(self.path)
try:
f.write('Some new content')
finally:
f.close()
self.assertEqual('Some new content', util.read_file(self.path))
示例14: test_existing_open_for_reading
def test_existing_open_for_reading(self):
util.create_file(self.path, 'Initial file content')
self.assertEqual('Initial file content', util.read_file(self.path))
with open(self.path) as rf:
with util.AtomicFile(self.path) as f:
f.write('Replaced content')
self.assertEqual(True, rf.closed)
self.assertEqual(True, f.closed)
self.assertEqual('Replaced content', util.read_file(self.path))
示例15: setUp
def setUp(self):
self.env = EnvironmentStub()
self.repos_path = tempfile.mkdtemp(prefix='trac-gitrepos')
self.git_bin = locate('git')
# create git repository and master branch
self._git('init', self.repos_path)
create_file(os.path.join(self.repos_path, '.gitignore'))
self._git('add', '.gitignore')
self._git('commit', '-a', '-m', 'test')