Mercurial > hgsubversion
comparison tests/test_util.py @ 78:072010a271c6
Fix basic issues with tests on Windows
- shutil.rmtree() fails if there are any read-only files (svn store)
- Fix files:// URLs
- os.spawnvp()/Popen4() do not exist under Windows, use subprocess
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 09 Nov 2008 18:08:35 -0600 |
parents | 1f8854804795 |
children | 71de43e9f614 |
comparison
equal
deleted
inserted
replaced
77:ed3dd5bf45da | 78:072010a271c6 |
---|---|
1 import errno | |
1 import os | 2 import os |
2 import popen2 | 3 import subprocess |
4 import shutil | |
5 import stat | |
6 import urllib | |
3 | 7 |
4 from mercurial import ui | 8 from mercurial import ui |
5 from mercurial import hg | 9 from mercurial import hg |
6 | 10 |
7 import fetch_command | 11 import fetch_command |
8 | 12 |
9 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), | 13 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), |
10 'fixtures') | 14 'fixtures') |
11 | 15 |
16 def fileurl(path): | |
17 path = os.path.abspath(path) | |
18 drive, path = os.path.splitdrive(path) | |
19 path = urllib.pathname2url(path) | |
20 if drive: | |
21 drive = '/' + drive | |
22 url = 'file://%s%s' % (drive, path) | |
23 return url | |
24 | |
12 def load_svndump_fixture(path, fixture_name): | 25 def load_svndump_fixture(path, fixture_name): |
13 '''Loads an svnadmin dump into a fresh repo at path, which should not | 26 '''Loads an svnadmin dump into a fresh repo at path, which should not |
14 already exist. | 27 already exist. |
15 ''' | 28 ''' |
16 os.spawnvp(os.P_WAIT, 'svnadmin', ['svnadmin', 'create', path,]) | 29 subprocess.call(['svnadmin', 'create', path,]) |
17 proc = popen2.Popen4(['svnadmin', 'load', path,]) | 30 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=subprocess.PIPE, |
31 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
18 inp = open(os.path.join(FIXTURES, fixture_name)) | 32 inp = open(os.path.join(FIXTURES, fixture_name)) |
19 proc.tochild.write(inp.read()) | 33 proc.stdin.write(inp.read()) |
20 proc.tochild.close() | 34 proc.stdin.flush() |
21 proc.wait() | 35 proc.communicate() |
22 | 36 |
23 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False): | 37 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False): |
24 load_svndump_fixture(repo_path, fixture_name) | 38 load_svndump_fixture(repo_path, fixture_name) |
25 fetch_command.fetch_revisions(ui.ui(), | 39 fetch_command.fetch_revisions(ui.ui(), |
26 svn_url='file://%s' % repo_path, | 40 svn_url=fileurl(repo_path), |
27 hg_repo_path=wc_path, | 41 hg_repo_path=wc_path, |
28 stupid=stupid) | 42 stupid=stupid) |
29 repo = hg.repository(ui.ui(), wc_path) | 43 repo = hg.repository(ui.ui(), wc_path) |
30 return repo | 44 return repo |
45 | |
46 def rmtree(path): | |
47 # Read-only files cannot be removed under Windows | |
48 for root, dirs, files in os.walk(path): | |
49 for f in files: | |
50 f = os.path.join(root, f) | |
51 try: | |
52 s = os.stat(f) | |
53 except OSError, e: | |
54 if e.errno == errno.ENOENT: | |
55 continue | |
56 raise | |
57 if (s.st_mode & stat.S_IWRITE) == 0: | |
58 os.chmod(f, s.st_mode | stat.S_IWRITE) | |
59 shutil.rmtree(path) |