|
1 | 1 | import os
|
| 2 | +import shutil |
| 3 | +import subprocess |
2 | 4 | import sys
|
3 | 5 | from datetime import date
|
4 | 6 | from datetime import datetime
|
@@ -92,6 +94,42 @@ def test_parse_call_order(wd):
|
92 | 94 | git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE)
|
93 | 95 |
|
94 | 96 |
|
| 97 | +@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/707") |
| 98 | +def test_not_owner(wd): |
| 99 | + git_dir = opj(wd.cwd) |
| 100 | + original_stat = os.stat(git_dir) |
| 101 | + if not shutil.which("sudo"): |
| 102 | + pytest.skip("sudo executable not found") |
| 103 | + |
| 104 | + proc = subprocess.run( |
| 105 | + ["sudo", "chown", "-R", "12345", git_dir], stdin=subprocess.DEVNULL |
| 106 | + ) |
| 107 | + if proc.returncode != 0: |
| 108 | + pytest.skip("Failed to change ownership, is passwordless sudo available?") |
| 109 | + try: |
| 110 | + subprocess.run( |
| 111 | + ["sudo", "chmod", "a+r", git_dir], stdin=subprocess.DEVNULL, check=True |
| 112 | + ) |
| 113 | + subprocess.run( |
| 114 | + ["sudo", "chgrp", "-R", "12345", git_dir], |
| 115 | + stdin=subprocess.DEVNULL, |
| 116 | + check=True, |
| 117 | + ) |
| 118 | + assert git.parse(str(wd.cwd)) |
| 119 | + finally: |
| 120 | + # Restore the ownership |
| 121 | + subprocess.run( |
| 122 | + ["sudo", "chown", "-R", str(original_stat.st_uid), git_dir], |
| 123 | + stdin=subprocess.DEVNULL, |
| 124 | + check=True, |
| 125 | + ) |
| 126 | + subprocess.run( |
| 127 | + ["sudo", "chgrp", "-R", str(original_stat.st_gid), git_dir], |
| 128 | + stdin=subprocess.DEVNULL, |
| 129 | + check=True, |
| 130 | + ) |
| 131 | + |
| 132 | + |
95 | 133 | def test_version_from_git(wd):
|
96 | 134 | assert wd.version == "0.1.dev0"
|
97 | 135 |
|
|
0 commit comments