aboutsummaryrefslogtreecommitdiff
path: root/gitosis/test/util.py
blob: b37178e9aa8db7b46830dbb4a78b9df3f874a97c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from nose.tools import eq_ as eq
 
import errno
import os
import stat
 
def mkdir(*a, **kw):
    try:
        os.mkdir(*a**kw)
    except OSErrore:
        if e.errno == errno.EEXIST:
            pass
        else:
            raise
 
def maketemp():
    tmp = os.path.join(os.path.dirname(__file__)'tmp')
    mkdir(tmp)
    me = os.path.splitext(os.path.basename(__file__))[0]
    tmp = os.path.join(tmpme)
    mkdir(tmp)
    return tmp
 
def writeFile(path, content):
    tmp = '%s.tmp' % path
    f = file(tmp'w')
    try:
        f.write(content)
    finally:
        f.close()
    os.rename(tmppath)
 
def readFile(path):
    f = file(path)
    try:
        data = f.read()
    finally:
        f.close()
    return data
 
def check_mode(path, mode, is_file=None, is_dir=None):
    st = os.stat(path)
    if is_dir:
        assert stat.S_ISDIR(st.st_mode)
    if is_file:
        assert stat.S_ISREG(st.st_mode)
 
    got = stat.S_IMODE(st.st_mode)
    eq(gotmode'File mode %04o!=%04o for %s' % (gotmodepath))