annotate tests/test_util.py @ 82:71de43e9f614

Extract PushTest common code into test_util.TestBase
author Patrick Mezard <pmezard@gmail.com>
date Fri, 14 Nov 2008 16:18:24 -0600
parents 072010a271c6
children 6c9b7cf1c5aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
6 import tempfile
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
7 import unittest
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
8 import urllib
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
10 from mercurial import ui
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
11 from mercurial import hg
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
12
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
13 import fetch_command
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
14 import push_cmd
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
15
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 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
17 'fixtures')
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
19 def fileurl(path):
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
20 path = os.path.abspath(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
21 drive, path = os.path.splitdrive(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
22 path = urllib.pathname2url(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
23 if drive:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
24 drive = '/' + drive
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
25 url = 'file://%s%s' % (drive, path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
26 return url
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
27
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 def load_svndump_fixture(path, fixture_name):
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 '''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
30 already exist.
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 '''
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
32 subprocess.call(['svnadmin', 'create', path,])
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
33 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
34 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 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
36 proc.stdin.write(inp.read())
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
37 proc.stdin.flush()
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
38 proc.communicate()
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
39
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
40 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
41 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
42 fetch_command.fetch_revisions(ui.ui(),
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
43 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
44 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
45 stupid=stupid)
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
46 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
47 return repo
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
48
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
49 def rmtree(path):
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
50 # 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
51 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
52 for f in files:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
53 f = os.path.join(root, f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
54 try:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
55 s = os.stat(f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
56 except OSError, e:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
57 if e.errno == errno.ENOENT:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
58 continue
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
59 raise
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
60 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
61 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
62 shutil.rmtree(path)
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
63
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
64 class TestBase(unittest.TestCase):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
65 def setUp(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
66 self.oldwd = os.getcwd()
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
67 self.tmpdir = tempfile.mkdtemp('svnwrap_test')
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
68 self.repo_path = '%s/testrepo' % self.tmpdir
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
69 self.wc_path = '%s/testrepo_wc' % self.tmpdir
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
70
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
71 def tearDown(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
72 rmtree(self.tmpdir)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
73 os.chdir(self.oldwd)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
74
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
75 # define this as a property so that it reloads anytime we need it
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
76 @property
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
77 def repo(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
78 return hg.repository(ui.ui(), self.wc_path)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
79
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
80 def pushrevisions(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
81 push_cmd.push_revisions_to_subversion(
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
82 ui.ui(), repo=self.repo, hg_repo_path=self.wc_path,
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
83 svn_url=fileurl(self.repo_path))