11"""Test function in module."""
22
3+ from os .path import join
34from subprocess import CalledProcessError
45
56import pytest
67
7- from sphinxcontrib .versioning .git import clone , GitError
8+ from sphinxcontrib .versioning .git import clone , GitError , IS_WINDOWS
89
910
1011def test_no_exclude (tmpdir , local_docs , run ):
@@ -45,7 +46,7 @@ def test_exclude(tmpdir, local, run):
4546 # Run.
4647 exclude = [
4748 '.travis.yml' , 'appveyor.yml' , # Ignored (nonexistent), show warnings.
48- 'README' , 'two.txt' , 'sub/ four.txt' , # Only leave these.
49+ 'README' , 'two.txt' , join ( 'sub' , ' four.txt') , # Only leave these.
4950 ]
5051 new_root = tmpdir .ensure_dir ('new_root' )
5152 clone (str (local ), str (new_root ), 'origin' , 'feature' , '.' , exclude )
@@ -56,7 +57,7 @@ def test_exclude(tmpdir, local, run):
5657 assert new_root .join ('sub' , 'four.txt' ).read () == 'four'
5758 assert new_root .join ('two.txt' ).read () == 'two'
5859 paths = sorted (f .relto (new_root ) for f in new_root .visit () if new_root .join ('.git' ) not in f .parts ())
59- assert paths == ['README' , 'sub' , 'sub/ four.txt' , 'two.txt' ]
60+ assert paths == ['README' , 'sub' , join ( 'sub' , ' four.txt') , 'two.txt' ]
6061
6162 # Verify original repo state.
6263 run (local , ['git' , 'diff-index' , '--quiet' , 'HEAD' , '--' ]) # Verify unchanged.
@@ -88,7 +89,7 @@ def test_exclude_subdir(tmpdir, local, run):
8889 new_root = tmpdir .ensure_dir ('new_root' )
8990 clone (str (local ), str (new_root ), 'origin' , 'master' , 'sub' , ['three.txt' ])
9091 paths = sorted (f .relto (new_root ) for f in new_root .visit () if new_root .join ('.git' ) not in f .parts ())
91- assert paths == ['README' , 'sub' , 'sub/ three.txt' ]
92+ assert paths == ['README' , 'sub' , join ( 'sub' , ' three.txt') ]
9293
9394 status = run (new_root , ['git' , 'status' , '--porcelain' ])
9495 assert status == 'D sub/four.txt\n '
@@ -112,9 +113,9 @@ def test_exclude_patterns(tmpdir, local, run):
112113 run (local , ['git' , 'push' , 'origin' , 'master' ])
113114
114115 new_root = tmpdir .ensure_dir ('new_root' )
115- clone (str (local ), str (new_root ), 'origin' , 'master' , '.' , ['*.md' , '*/ *.md' ])
116+ clone (str (local ), str (new_root ), 'origin' , 'master' , '.' , ['*.md' , join ( '*' , ' *.md') ])
116117 paths = sorted (f .relto (new_root ) for f in new_root .visit () if new_root .join ('.git' ) not in f .parts ())
117- assert paths == ['one.md' , 'six.md' , 'sub' , 'sub/ five.md' , 'sub/ four.md' ]
118+ assert paths == ['one.md' , 'six.md' , 'sub' , join ( 'sub' , ' five.md'), join ( 'sub' , ' four.md') ]
118119
119120 status = run (new_root , ['git' , 'status' , '--porcelain' ])
120121 assert status == 'D README\n D sub/three.txt\n D two.txt\n '
@@ -165,8 +166,11 @@ def test_bad_branch_rel_dest_exclude(tmpdir, local, run):
165166 # Bad remote.
166167 run (local , ['git' , 'remote' , 'add' , 'origin' , local .join ('does_not_exist' )])
167168 with pytest .raises (GitError ) as exc :
168- clone (str (local ), str (tmpdir .ensure_dir ('new_root3' )), 'origin' , 'master' , '.' , None )
169- assert "repository '{}' does not exist" .format (local .join ('does_not_exist' )) in exc .value .output
169+ clone (str (local ), str (tmpdir .ensure_dir ('new_root4' )), 'origin' , 'master' , '.' , None )
170+ if IS_WINDOWS :
171+ assert "'{}' does not appear to be a git repository" .format (local .join ('does_not_exist' )) in exc .value .output
172+ else :
173+ assert "repository '{}' does not exist" .format (local .join ('does_not_exist' )) in exc .value .output
170174
171175
172176def test_multiple_remotes (tmpdir , local , remote , run ):
0 commit comments