aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-09-01 16:28:51 -0700
committerTommi Virtanen <tv@eagain.net>2007-09-01 16:28:51 -0700
commitc5ee8f08d5fbccf4dc6868ae5c2882e71a2cb5e2 (patch)
treebabe4f876686156e2c30a356fdfee07875584a43
parentMake gitosis.util.mkdir pass through any os.mkdir args. (diff)
downloadgitosis-dakkar-c5ee8f08d5fbccf4dc6868ae5c2882e71a2cb5e2.tar.gz
gitosis-dakkar-c5ee8f08d5fbccf4dc6868ae5c2882e71a2cb5e2.tar.bz2
gitosis-dakkar-c5ee8f08d5fbccf4dc6868ae5c2882e71a2cb5e2.zip
Refactor to share file mode checking.
-rw-r--r--gitosis/test/test_repository.py23
-rw-r--r--gitosis/test/util.py16
2 files changed, 24 insertions, 15 deletions
diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py
index 7e5885d..f5b312a 100644
--- a/gitosis/test/test_repository.py
+++ b/gitosis/test/test_repository.py
@@ -1,12 +1,11 @@
from nose.tools import eq_ as eq
import os
-import stat
import shutil
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):
# we want it to be a bare repository
@@ -16,9 +15,7 @@ def test_init_simple():
tmp = maketemp()
path = os.path.join(tmp, 'repo.git')
repository.init(path)
- st = os.stat(path)
- assert stat.S_ISDIR(st.st_mode)
- eq(stat.S_IMODE(st.st_mode), 0750)
+ check_mode(path, 0750, is_dir=True)
check_bare(path)
def test_init_exist_dir():
@@ -26,9 +23,7 @@ def test_init_exist_dir():
path = os.path.join(tmp, 'repo.git')
mkdir(path)
repository.init(path)
- st = os.stat(path)
- assert stat.S_ISDIR(st.st_mode)
- eq(stat.S_IMODE(st.st_mode), 0750)
+ check_mode(path, 0750, is_dir=True)
check_bare(path)
def test_init_exist_git():
@@ -36,9 +31,7 @@ def test_init_exist_git():
path = os.path.join(tmp, 'repo.git')
repository.init(path)
repository.init(path)
- st = os.stat(path)
- assert stat.S_ISDIR(st.st_mode)
- eq(stat.S_IMODE(st.st_mode), 0750)
+ check_mode(path, 0750, is_dir=True)
check_bare(path)
def test_init_templates():
@@ -54,9 +47,11 @@ def test_init_templates():
repository.init(path)
got = readFile(os.path.join(path, 'no-confusion'))
eq(got, 'i should show up\n')
- st = os.stat(os.path.join(path, 'hooks', 'post-update'))
- assert stat.S_ISREG(st.st_mode)
- eq('%04o'%stat.S_IMODE(st.st_mode), '%04o'%0755)
+ check_mode(
+ os.path.join(path, 'hooks', 'post-update'),
+ 0755,
+ is_file=True,
+ )
got = readFile(os.path.join(path, 'hooks', 'post-update'))
eq(got, '#!/bin/sh\n# i can override standard templates\n')
# standard templates are there, too
diff --git a/gitosis/test/util.py b/gitosis/test/util.py
index b5c19ca..b37178e 100644
--- a/gitosis/test/util.py
+++ b/gitosis/test/util.py
@@ -1,4 +1,8 @@
-import os, errno
+from nose.tools import eq_ as eq
+
+import errno
+import os
+import stat
def mkdir(*a, **kw):
try:
@@ -33,3 +37,13 @@ def readFile(path):
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(got, mode, 'File mode %04o!=%04o for %s' % (got, mode, path))