comparison tests/test_fetch_command.py @ 22:95d0109e495e

Refactor tests so I can reuse code more.
author Augie Fackler <durin42@gmail.com>
date Wed, 08 Oct 2008 20:09:28 -0500
parents 8626f3d2e50b
children 99f8e4b535e9
comparison
equal deleted inserted replaced
21:8626f3d2e50b 22:95d0109e495e
19 self.wc_path = '%s/testrepo_wc' % self.tmpdir 19 self.wc_path = '%s/testrepo_wc' % self.tmpdir
20 20
21 def tearDown(self): 21 def tearDown(self):
22 shutil.rmtree(self.tmpdir) 22 shutil.rmtree(self.tmpdir)
23 os.chdir(self.oldwd) 23 os.chdir(self.oldwd)
24
25 def _load_fixture_and_fetch(self, fixture_name):
26 return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
27 self.wc_path)
24 28
25 def test_fresh_fetch_single_rev(self): 29 def test_fresh_fetch_single_rev(self):
26 test_util.load_svndump_fixture(self.repo_path, 'single_rev.svndump') 30 repo = self._load_fixture_and_fetch('single_rev.svndump')
27 fetch_command.fetch_revisions(ui.ui(),
28 svn_url='file://%s' % self.repo_path,
29 hg_repo_path=self.wc_path)
30 repo = hg.repository(ui.ui(), self.wc_path)
31 self.assertEqual(node.hex(repo['tip'].node()), 31 self.assertEqual(node.hex(repo['tip'].node()),
32 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') 32 'a47d0ce778660a91c31bf2c21c448e9ee296ac90')
33 self.assertEqual(repo['tip'], repo[0]) 33 self.assertEqual(repo['tip'], repo[0])
34 34
35 def test_fresh_fetch_two_revs(self): 35 def test_fresh_fetch_two_revs(self):
36 test_util.load_svndump_fixture(self.repo_path, 'two_revs.svndump') 36 repo = self._load_fixture_and_fetch('two_revs.svndump')
37 fetch_command.fetch_revisions(ui.ui(),
38 svn_url='file://%s' % self.repo_path,
39 hg_repo_path=self.wc_path)
40 repo = hg.repository(ui.ui(), self.wc_path)
41 # TODO there must be a better way than repo[0] for this check 37 # TODO there must be a better way than repo[0] for this check
42 self.assertEqual(node.hex(repo[0].node()), 38 self.assertEqual(node.hex(repo[0].node()),
43 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') 39 'a47d0ce778660a91c31bf2c21c448e9ee296ac90')
44 self.assertEqual(node.hex(repo['tip'].node()), 40 self.assertEqual(node.hex(repo['tip'].node()),
45 'bf3767835b3b32ecc775a298c2fa27134dd91c11') 41 'bf3767835b3b32ecc775a298c2fa27134dd91c11')
46 self.assertEqual(repo['tip'], repo[1]) 42 self.assertEqual(repo['tip'], repo[1])
47 43
48 def test_branches(self): 44 def test_branches(self):
49 test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') 45 repo = self._load_fixture_and_fetch('simple_branch.svndump')
50 fetch_command.fetch_revisions(ui.ui(),
51 svn_url='file://%s' % self.repo_path,
52 hg_repo_path=self.wc_path)
53 repo = hg.repository(ui.ui(), self.wc_path)
54 # TODO there must be a better way than repo[0] for this check 46 # TODO there must be a better way than repo[0] for this check
55 self.assertEqual(node.hex(repo[0].node()), 47 self.assertEqual(node.hex(repo[0].node()),
56 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') 48 'a47d0ce778660a91c31bf2c21c448e9ee296ac90')
57 self.assertEqual(node.hex(repo['tip'].node()), 49 self.assertEqual(node.hex(repo['tip'].node()),
58 '9dfb0a19494f45c36e22f3c6d1b21d80638a7f6e') 50 '9dfb0a19494f45c36e22f3c6d1b21d80638a7f6e')
59 self.assertEqual(len(repo['tip'].parents()), 1) 51 self.assertEqual(len(repo['tip'].parents()), 1)
60 self.assertEqual(repo['tip'].parents()[0], repo['default']) 52 self.assertEqual(repo['tip'].parents()[0], repo['default'])
61 self.assertEqual(len(repo.heads()), 1) 53 self.assertEqual(len(repo.heads()), 1)
62 54
63 def test_two_branches_with_heads(self): 55 def test_two_branches_with_heads(self):
64 test_util.load_svndump_fixture(self.repo_path, 'two_heads.svndump') 56 repo = self._load_fixture_and_fetch('two_heads.svndump')
65 fetch_command.fetch_revisions(ui.ui(),
66 svn_url='file://%s' % self.repo_path,
67 hg_repo_path=self.wc_path)
68 repo = hg.repository(ui.ui(), self.wc_path)
69 # TODO there must be a better way than repo[0] for this check 57 # TODO there must be a better way than repo[0] for this check
70 self.assertEqual(node.hex(repo[0].node()), 58 self.assertEqual(node.hex(repo[0].node()),
71 'a47d0ce778660a91c31bf2c21c448e9ee296ac90') 59 'a47d0ce778660a91c31bf2c21c448e9ee296ac90')
72 self.assertEqual(node.hex(repo['tip'].node()), 60 self.assertEqual(node.hex(repo['tip'].node()),
73 'a595c77cfcaa3d1ba9e04b2c55c68bc6bf2b0fbf') 61 'a595c77cfcaa3d1ba9e04b2c55c68bc6bf2b0fbf')
78 self.assertEqual(len(repo['tip'].parents()), 1) 66 self.assertEqual(len(repo['tip'].parents()), 1)
79 self.assertEqual(repo['tip'], repo['default']) 67 self.assertEqual(repo['tip'], repo['default'])
80 self.assertEqual(len(repo.heads()), 2) 68 self.assertEqual(len(repo.heads()), 2)
81 69
82 def test_many_special_cases_replay(self): 70 def test_many_special_cases_replay(self):
83 test_util.load_svndump_fixture(self.repo_path, 71 repo = self._load_fixture_and_fetch('many_special_cases.svndump')
84 'many_special_cases.svndump')
85 fetch_command.fetch_revisions(ui.ui(),
86 svn_url='file://%s' % self.repo_path,
87 hg_repo_path=self.wc_path)
88 repo = hg.repository(ui.ui(), self.wc_path)
89 # TODO there must be a better way than repo[0] for this check 72 # TODO there must be a better way than repo[0] for this check
90 self._many_special_cases_checks(repo) 73 self._many_special_cases_checks(repo)
91 74
92 75
93 def test_many_special_cases_diff(self): 76 def test_many_special_cases_diff(self):
94 test_util.load_svndump_fixture(self.repo_path, 77 repo = self._load_fixture_and_fetch('many_special_cases.svndump')
95 'many_special_cases.svndump')
96 fetch_command.fetch_revisions(ui.ui(),
97 svn_url='file://%s' % self.repo_path,
98 hg_repo_path=self.wc_path,
99 stupid = True)
100 repo = hg.repository(ui.ui(), self.wc_path)
101 # TODO there must be a better way than repo[0] for this check 78 # TODO there must be a better way than repo[0] for this check
102 self._many_special_cases_checks(repo) 79 self._many_special_cases_checks(repo)
103 80
104 def _many_special_cases_checks(self, repo): 81 def _many_special_cases_checks(self, repo):
105 self.assertEqual(node.hex(repo[0].node()), 82 self.assertEqual(node.hex(repo[0].node()),
111 self.assertEqual(node.hex(repo['the_branch'].parents()[0].node()), 88 self.assertEqual(node.hex(repo['the_branch'].parents()[0].node()),
112 '9dfb0a19494f45c36e22f3c6d1b21d80638a7f6e') 89 '9dfb0a19494f45c36e22f3c6d1b21d80638a7f6e')
113 self.assertEqual(len(repo['tip'].parents()), 1) 90 self.assertEqual(len(repo['tip'].parents()), 1)
114 self.assertEqual(repo['tip'], repo['default']) 91 self.assertEqual(repo['tip'], repo['default'])
115 self.assertEqual(len(repo.heads()), 2) 92 self.assertEqual(len(repo.heads()), 2)
116
117
118 93
119 94
120 class TestStupidPull(unittest.TestCase): 95 class TestStupidPull(unittest.TestCase):
121 def setUp(self): 96 def setUp(self):
122 self.oldwd = os.getcwd() 97 self.oldwd = os.getcwd()