Refactor to share file mode checking.
This commit is contained in:
parent
c264d696e2
commit
c5ee8f08d5
|
@ -1,12 +1,11 @@
|
||||||
from nose.tools import eq_ as eq
|
from nose.tools import eq_ as eq
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import stat
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from gitosis import repository
|
from gitosis import repository
|
||||||
|
|
||||||
from gitosis.test.util import mkdir, maketemp, readFile
|
from gitosis.test.util import mkdir, maketemp, readFile, check_mode
|
||||||
|
|
||||||
def check_bare(path):
|
def check_bare(path):
|
||||||
# we want it to be a bare repository
|
# we want it to be a bare repository
|
||||||
|
@ -16,9 +15,7 @@ def test_init_simple():
|
||||||
tmp = maketemp()
|
tmp = maketemp()
|
||||||
path = os.path.join(tmp, 'repo.git')
|
path = os.path.join(tmp, 'repo.git')
|
||||||
repository.init(path)
|
repository.init(path)
|
||||||
st = os.stat(path)
|
check_mode(path, 0750, is_dir=True)
|
||||||
assert stat.S_ISDIR(st.st_mode)
|
|
||||||
eq(stat.S_IMODE(st.st_mode), 0750)
|
|
||||||
check_bare(path)
|
check_bare(path)
|
||||||
|
|
||||||
def test_init_exist_dir():
|
def test_init_exist_dir():
|
||||||
|
@ -26,9 +23,7 @@ def test_init_exist_dir():
|
||||||
path = os.path.join(tmp, 'repo.git')
|
path = os.path.join(tmp, 'repo.git')
|
||||||
mkdir(path)
|
mkdir(path)
|
||||||
repository.init(path)
|
repository.init(path)
|
||||||
st = os.stat(path)
|
check_mode(path, 0750, is_dir=True)
|
||||||
assert stat.S_ISDIR(st.st_mode)
|
|
||||||
eq(stat.S_IMODE(st.st_mode), 0750)
|
|
||||||
check_bare(path)
|
check_bare(path)
|
||||||
|
|
||||||
def test_init_exist_git():
|
def test_init_exist_git():
|
||||||
|
@ -36,9 +31,7 @@ def test_init_exist_git():
|
||||||
path = os.path.join(tmp, 'repo.git')
|
path = os.path.join(tmp, 'repo.git')
|
||||||
repository.init(path)
|
repository.init(path)
|
||||||
repository.init(path)
|
repository.init(path)
|
||||||
st = os.stat(path)
|
check_mode(path, 0750, is_dir=True)
|
||||||
assert stat.S_ISDIR(st.st_mode)
|
|
||||||
eq(stat.S_IMODE(st.st_mode), 0750)
|
|
||||||
check_bare(path)
|
check_bare(path)
|
||||||
|
|
||||||
def test_init_templates():
|
def test_init_templates():
|
||||||
|
@ -54,9 +47,11 @@ def test_init_templates():
|
||||||
repository.init(path)
|
repository.init(path)
|
||||||
got = readFile(os.path.join(path, 'no-confusion'))
|
got = readFile(os.path.join(path, 'no-confusion'))
|
||||||
eq(got, 'i should show up\n')
|
eq(got, 'i should show up\n')
|
||||||
st = os.stat(os.path.join(path, 'hooks', 'post-update'))
|
check_mode(
|
||||||
assert stat.S_ISREG(st.st_mode)
|
os.path.join(path, 'hooks', 'post-update'),
|
||||||
eq('%04o'%stat.S_IMODE(st.st_mode), '%04o'%0755)
|
0755,
|
||||||
|
is_file=True,
|
||||||
|
)
|
||||||
got = readFile(os.path.join(path, 'hooks', 'post-update'))
|
got = readFile(os.path.join(path, 'hooks', 'post-update'))
|
||||||
eq(got, '#!/bin/sh\n# i can override standard templates\n')
|
eq(got, '#!/bin/sh\n# i can override standard templates\n')
|
||||||
# standard templates are there, too
|
# standard templates are there, too
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import os, errno
|
from nose.tools import eq_ as eq
|
||||||
|
|
||||||
|
import errno
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
def mkdir(*a, **kw):
|
def mkdir(*a, **kw):
|
||||||
try:
|
try:
|
||||||
|
@ -33,3 +37,13 @@ def readFile(path):
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
return data
|
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(got, mode, 'File mode %04o!=%04o for %s' % (got, mode, path))
|
||||||
|
|
Loading…
Reference in a new issue