-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_init.py
More file actions
78 lines (59 loc) · 2.55 KB
/
test_init.py
File metadata and controls
78 lines (59 loc) · 2.55 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from pathlib import Path
import subprocess
def test_init_in_directory(git2cpp_path, tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []
cmd = [git2cpp_path, 'init', '--bare', str(tmp_path)]
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 0
assert p.stdout == b''
assert p.stderr == b''
assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [
'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs'
]
# TODO: check this is a valid git repo
def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []
assert Path.cwd() == tmp_path
cmd = [git2cpp_path, 'init', '--bare']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 0
assert p.stdout == b''
assert p.stderr == b''
assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [
'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs'
]
# TODO: check this is a valid git repo
def test_init_not_bare(git2cpp_path, tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []
cmd = [git2cpp_path, 'init', '.']
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path)
assert p.returncode == 0
assert p.stdout == b''
assert p.stderr == b''
# Directory contains just .git directory.
assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == ['.git']
# .git directory is a valid repo.
assert sorted(map(lambda path: path.name, (tmp_path / '.git').iterdir())) == [
'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs'
]
# Would like to use `git2cpp status` but it complains that 'refs/heads/master' not found
cmd = [git2cpp_path, 'log']
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path)
assert p.returncode == 0
assert p.stdout == b''
assert p.stderr == b''
def test_error_on_unknown_option(git2cpp_path):
cmd = [git2cpp_path, 'init', '--unknown']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 109
assert p.stdout == b''
assert p.stderr.startswith(b"The following argument was not expected: --unknown")
def test_error_on_repeated_directory(git2cpp_path):
cmd = [git2cpp_path, 'init', 'abc', 'def']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 109
assert p.stdout == b''
assert p.stderr.startswith(b"The following argument was not expected: def")