Mercurial > hgsubversion
annotate tests/test_util.py @ 79:2e47623fa174
fetch_command: handle failing svn.diff3() on Windows, fetch full revision
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 09 Nov 2008 18:08:35 -0600 |
parents | 072010a271c6 |
children | 71de43e9f614 |
rev | line source |
---|---|
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
1 import errno |
14
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
2 import os |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
3 import subprocess |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
4 import shutil |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
5 import stat |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
6 import urllib |
14
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 |
22
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
8 from mercurial import ui |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
9 from mercurial import hg |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
10 |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
11 import fetch_command |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
12 |
14
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
13 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), |
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 'fixtures') |
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
15 |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
16 def fileurl(path): |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
17 path = os.path.abspath(path) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
18 drive, path = os.path.splitdrive(path) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
19 path = urllib.pathname2url(path) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
20 if drive: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
21 drive = '/' + drive |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
22 url = 'file://%s%s' % (drive, path) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
23 return url |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
24 |
14
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
25 def load_svndump_fixture(path, fixture_name): |
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
26 '''Loads an svnadmin dump into a fresh repo at path, which should not |
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
27 already exist. |
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
28 ''' |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
29 subprocess.call(['svnadmin', 'create', path,]) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
30 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=subprocess.PIPE, |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
31 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
14
d78dbf88c13d
Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
32 inp = open(os.path.join(FIXTURES, fixture_name)) |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
33 proc.stdin.write(inp.read()) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
34 proc.stdin.flush() |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
35 proc.communicate() |
22
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
36 |
23
1f8854804795
Add tests for tags and fix a bug in the tag-finding code that was found by the tests.
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
37 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False): |
22
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
38 load_svndump_fixture(repo_path, fixture_name) |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
39 fetch_command.fetch_revisions(ui.ui(), |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
40 svn_url=fileurl(repo_path), |
23
1f8854804795
Add tests for tags and fix a bug in the tag-finding code that was found by the tests.
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
41 hg_repo_path=wc_path, |
1f8854804795
Add tests for tags and fix a bug in the tag-finding code that was found by the tests.
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
42 stupid=stupid) |
22
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
43 repo = hg.repository(ui.ui(), wc_path) |
95d0109e495e
Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
44 return repo |
78
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
45 |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
46 def rmtree(path): |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
47 # Read-only files cannot be removed under Windows |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
48 for root, dirs, files in os.walk(path): |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
49 for f in files: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
50 f = os.path.join(root, f) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
51 try: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
52 s = os.stat(f) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
53 except OSError, e: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
54 if e.errno == errno.ENOENT: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
55 continue |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
56 raise |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
57 if (s.st_mode & stat.S_IWRITE) == 0: |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
58 os.chmod(f, s.st_mode | stat.S_IWRITE) |
072010a271c6
Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
23
diff
changeset
|
59 shutil.rmtree(path) |