10
10
11
11
from openlinter .rules import *
12
12
13
+
14
+ # Test fixtures
15
+
16
+ @pytest .fixture ()
17
+ def setup_empty_repo (tmpdir ):
18
+ # tmpdir is a LocalPath, git chokes unless you cast to str
19
+ git .Repo .init (str (tmpdir ))
20
+
21
+ @pytest .fixture ()
22
+ def setup_repo_one_br_one_commit (tmpdir ):
23
+ repo = git .Repo .init (str (tmpdir ))
24
+ # Make temporary file for the temporary repo
25
+ with open (str (tmpdir .join ('test_file.txt' )), 'w' ) as f :
26
+ f .write ('This is a file with text.\n ' )
27
+ repo .index .add ([str (tmpdir .join ('test_file.txt' ))])
28
+ repo .index .commit ('initial commit' )
29
+
30
+ @pytest .fixture ()
31
+ def setup_repo_two_br_two_commits (tmpdir ):
32
+ repo = git .Repo .init (str (tmpdir ))
33
+ # Make first temporary file and commit it
34
+ with open (str (tmpdir .join ('test_file.txt' )), 'w' ) as f :
35
+ f .write ('This is a file with text.\n ' )
36
+ repo .index .add ([str (tmpdir .join ('test_file.txt' ))])
37
+ repo .index .commit ('initial commit' )
38
+
39
+ # Make second temporary file and commit it
40
+ with open (str (tmpdir .join ('test_file2.txt' )), 'w' ) as f :
41
+ f .write ('This is a second file with text.\n ' )
42
+ repo .index .add ([str (tmpdir .join ('test_file2.txt' ))])
43
+ repo .index .commit ('second commit' )
44
+
45
+ # Make the dev branch
46
+ new_branch = repo .create_head ('develop' )
47
+
48
+
13
49
# Tests for openlinter.rules.check_file_presence()
14
50
15
51
def test_check_file_presence_nonexistent_file ():
@@ -67,8 +103,8 @@ def test_get_file_text_file_exists_has_text():
67
103
68
104
# Tests for openlinter.rules.detect_version_control()
69
105
70
- def test_detect_version_control_repository_exists ():
71
- result = detect_version_control ('tests/fixtures/test-git-repo' )
106
+ def test_detect_version_control_repository_exists (setup_empty_repo , tmpdir ):
107
+ result = detect_version_control (str ( tmpdir ) )
72
108
assert result == 'git'
73
109
74
110
def test_detect_version_control_folder_does_not_exist ():
@@ -81,64 +117,64 @@ def test_detect_version_control_folder_has_no_vc():
81
117
82
118
# Tests for openlinter.rules.check_multiple_branches()
83
119
84
- def test_check_multiple_branches_empty_repo ():
85
- assert check_multiple_branches ('tests/fixtures/test-git-repo' ) == False
120
+ def test_check_multiple_branches_empty_repo (setup_empty_repo , tmpdir ):
121
+ assert check_multiple_branches (str ( tmpdir ) ) == False
86
122
87
123
def test_check_multiple_branches_nonexistent_repo ():
88
124
with pytest .raises (git .InvalidGitRepositoryError ):
89
125
check_multiple_branches ('tests/fixtures/pic-folder' )
90
126
91
- def test_check_multiple_branches_nonexistent_repo ():
127
+ def test_check_multiple_branches_nonexistent_folder ():
92
128
with pytest .raises (git .NoSuchPathError ):
93
129
check_multiple_branches ('zzyzx' )
94
130
95
- def test_check_multiple_branches_repo_with_one_branch ( ):
96
- result = check_multiple_branches ('tests/fixtures/git-repo-one-branch' )
131
+ def test_check_multiple_branches_repo_one_branch ( setup_repo_one_br_one_commit , tmpdir ):
132
+ result = check_multiple_branches (str ( tmpdir ) )
97
133
assert result == False
98
134
99
- def test_check_multiple_branches_repo_with_two_branches ():
100
- result = check_multiple_branches ('tests/fixtures/git-repo-dev-branch' )
135
+ def test_check_multiple_branches_repo_with_two_branches (setup_repo_two_br_two_commits , tmpdir ):
136
+ result = check_multiple_branches (str ( tmpdir ) )
101
137
assert result == True
102
138
103
139
104
140
# Tests for openlinter.rules.check_for_develop_branch()
105
141
106
- def test_check_for_develop_branch_nonexistent_repo ():
142
+ def test_check_for_develop_branch_nonexistent_folder ():
107
143
with pytest .raises (git .NoSuchPathError ):
108
144
check_for_develop_branch ('zzyzx' , 'dev' )
109
145
110
146
def test_check_for_develop_branch_nonexistent_repo ():
111
147
with pytest .raises (git .InvalidGitRepositoryError ):
112
148
check_for_develop_branch ('tests/fixtures/pic-folder' , 'dev' )
113
149
114
- def test_check_for_develop_branch_repo_without_dev_branch ():
115
- result = check_for_develop_branch ('tests/fixtures/test-git-repo' , 'dev ' )
150
+ def test_check_for_develop_branch_repo_without_dev_branch (setup_empty_repo , tmpdir ):
151
+ result = check_for_develop_branch (str ( tmpdir ) , 'develop ' )
116
152
assert result == False
117
153
118
- def test_check_for_develop_branch_repo_has_dev_branch ():
119
- result = check_for_develop_branch ('tests/fixtures/git-repo-dev-branch' ,
154
+ def test_check_for_develop_branch_repo_has_dev_branch (setup_repo_two_br_two_commits , tmpdir ):
155
+ result = check_for_develop_branch (str ( tmpdir ) ,
120
156
'develop' )
121
157
assert result == True
122
158
123
159
124
160
# Tests for openlinter.rules.check_for_multiple_commits()
125
161
126
- def test_check_for_multiple_commits_nonexistent_repo ():
162
+ def test_check_for_multiple_commits_nonexistent_folder ():
127
163
with pytest .raises (git .NoSuchPathError ):
128
164
check_for_multiple_commits ('zzyzx' )
129
165
130
166
def test_check_for_multiple_commits_nonexistent_repo ():
131
167
with pytest .raises (git .InvalidGitRepositoryError ):
132
168
check_for_multiple_commits ('tests/fixtures/pic-folder' )
133
169
134
- def test_check_for_multiple_commits_no_commits ():
135
- result = check_for_multiple_commits ('tests/fixtures/test-git-repo' )
170
+ def test_check_for_multiple_commits_no_commits (setup_empty_repo , tmpdir ):
171
+ result = check_for_multiple_commits (str ( tmpdir ) )
136
172
assert result is False
137
173
138
- def test_check_for_multiple_commits_one_commit ():
139
- result = check_for_multiple_commits ('tests/fixtures/git-repo-one-branch' )
174
+ def test_check_for_multiple_commits_one_commit (setup_repo_one_br_one_commit , tmpdir ):
175
+ result = check_for_multiple_commits (str ( tmpdir ) )
140
176
assert result == False
141
177
142
- def test_check_for_multiple_commits_two_commits ():
143
- result = check_for_multiple_commits ('tests/fixtures/git-repo-dev-branch' )
178
+ def test_check_for_multiple_commits_two_commits (setup_repo_two_br_two_commits , tmpdir ):
179
+ result = check_for_multiple_commits (str ( tmpdir ) )
144
180
assert result == True
0 commit comments