diff options
Diffstat (limited to 'hgsshsign/tests/_support.py')
-rw-r--r-- | hgsshsign/tests/_support.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/hgsshsign/tests/_support.py b/hgsshsign/tests/_support.py new file mode 100644 index 0000000..ef08932 --- /dev/null +++ b/hgsshsign/tests/_support.py | |||
@@ -0,0 +1,39 @@ | |||
1 | # vim:filetype=python:fileencoding=utf-8 | ||
2 | import os | ||
3 | import tempfile | ||
4 | import subprocess | ||
5 | |||
6 | |||
7 | def make_test_repo(): | ||
8 | tmpdir = tempfile.mkdtemp('.tmp', __name__.replace('.', '_')) | ||
9 | |||
10 | os.chdir(tmpdir) | ||
11 | subprocess.call('hg init test-repo.hg', shell=True) | ||
12 | os.chdir('test-repo.hg') | ||
13 | |||
14 | for filename, text, is_new, message in SKEL_FILES: | ||
15 | write_commit_file(filename, is_new=is_new, text=text, message=message) | ||
16 | |||
17 | return tmpdir, os.path.join(tmpdir, 'test-repo.hg') | ||
18 | |||
19 | |||
20 | def write_commit_file(filename, is_new=True, text='', message=''): | ||
21 | handle = open(filename, 'w') | ||
22 | handle.write(text) | ||
23 | handle.close() | ||
24 | |||
25 | if is_new: | ||
26 | subprocess.call('hg add %s' % filename, shell=True) | ||
27 | |||
28 | subprocess.call('hg ci -m %r %s' % (message, filename), | ||
29 | shell=True) | ||
30 | |||
31 | |||
32 | SKEL_FILES = ( | ||
33 | ('foo', 'bar', True, 'this is my foo'), | ||
34 | ('ham', 'bones', True, 'this is my ham'), | ||
35 | ('qwx', 'schnizzle', True, 'this is for testing'), | ||
36 | ('foo', 'bar\npatoot', False, 'my foo. it grows.'), | ||
37 | ('ham', 'booones', False, 'this ham is better'), | ||
38 | ('qwx', '', False, 'I grew tired of this qwx'), | ||
39 | ) | ||