1 # -*- encoding: utf-8 -*-
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-18 14:43:27$"
5 __doc__ = "Tests for RAL mercurial backend."
7 from nose.tools import *
10 from wlrepo import MercurialLibrary
11 from wlrepo.backend_mercurial import *
13 import os, os.path, tempfile
17 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data/repos')
21 def decorated(self, *args, **kwargs):
24 temp = tempfile.mkdtemp("", "testdir_" )
25 path = join(temp, 'repo')
26 shutil.copytree(join(REPO_TEMPLATES, name), path, False)
27 repo = MercurialLibrary(path)
28 func(self, *args, library=repo, **kwargs)
31 #if not clean and self.response:
32 # print "RESULT", func.__name__, ">>>"
35 shutil.rmtree(temp, True)
42 def test_opening(library):
46 def test_main_cabinet(library):
47 mcab = library.main_cabinet
48 assert_equal(mcab.maindoc_name, '')
50 doclist = mcab.documents()
51 assert_equal( list(doclist), ['valid_file'])
54 def test_read_document(library):
55 doc = library.main_cabinet.retrieve('valid_file')
56 assert_equal(doc.read().strip(), 'Ala ma kota')
59 def test_read_UTF8_document(library):
60 doc = library.main_cabinet.retrieve('polish_file')
61 assert_equal(doc.read().strip(), u'Gąska!'.encode('utf-8'))
64 def test_write_document(library):
65 doc = library.main_cabinet.retrieve('valid_file')
66 assert_equal(doc.read().strip(), 'Ala ma kota')
67 STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
69 assert_equal(doc.read(), STRING)
72 def test_create_document(library):
73 doc = library.main_cabinet.create("another_file", "Some text")
74 assert_equal( doc.read(), "Some text")
75 assert_true( os.path.isfile( os.path.join(repopath, "pub_another_file.xml")) )
78 def test_switch_branch(library):
79 tester_cab = library.cabinet("valid_file", "tester", create=False)
80 assert_equal( list(tester_cab.documents()), ['valid_file'])
82 @raises(wlrepo.CabinetNotFound)
84 def test_branch_not_found(library):
85 tester_cab = library.cabinet("ugh", "tester", create=False)
88 def test_no_branches(library):
95 assert_true( n3.parentof(n4) )
96 assert_false( n4.parentof(n3) )
97 assert_true( n0.parentof(n1) )
98 assert_false( n1.parentof(n0) )
99 assert_false( n0.parentof(n4) )
101 # def test_ancestor_of_simple(self):
102 assert_true( n3.ancestorof(n4) )
103 assert_true( n2.ancestorof(n4) )
104 assert_true( n1.ancestorof(n4) )
105 assert_true( n0.ancestorof(n4) )
107 assert_true( n2.ancestorof(n3) )
108 assert_true( n1.ancestorof(n3) )
109 assert_true( n0.ancestorof(n3) )
111 assert_false( n4.ancestorof(n4) )
112 assert_false( n4.ancestorof(n3) )
113 assert_false( n3.ancestorof(n2) )
114 assert_false( n3.ancestorof(n1) )
115 assert_false( n3.ancestorof(n0) )
117 # def test_common_ancestor_simple(self):
118 assert_true( n3.has_common_ancestor(n4) )
119 assert_true( n3.has_common_ancestor(n3) )
120 assert_true( n3.has_common_ancestor(n3) )
123 @temprepo('branched_two')
124 def test_once_branched(library):
125 n7 = library.shelf(7)
126 n6 = library.shelf(6)
127 n5 = library.shelf(5)
128 n4 = library.shelf(4)
129 n3 = library.shelf(3)
130 n2 = library.shelf(2)
132 assert_true( n2.parentof(n3) )
133 assert_false( n3.parentof(n2) )
135 assert_true( n2.parentof(n5) )
136 assert_false( n5.parentof(n2) )
138 assert_false( n2.parentof(n4) )
139 assert_false( n2.parentof(n6) )
140 assert_false( n3.parentof(n5) )
141 assert_false( n5.parentof(n3) )
143 # def test_ancestorof_branched(self):
144 assert_true( n2.ancestorof(n7) )
145 assert_false( n7.ancestorof(n2) )
146 assert_true( n2.ancestorof(n6) )
147 assert_false( n6.ancestorof(n2) )
148 assert_true( n2.ancestorof(n5) )
149 assert_false( n5.ancestorof(n2) )
151 assert_false( n3.ancestorof(n5) )
152 assert_false( n5.ancestorof(n3) )
153 assert_false( n4.ancestorof(n5) )
154 assert_false( n5.ancestorof(n4) )
155 assert_false( n3.ancestorof(n7) )
156 assert_false( n7.ancestorof(n3) )
157 assert_false( n4.ancestorof(n6) )
158 assert_false( n6.ancestorof(n4) )
160 # def test_common_ancestor_branched(self):
161 assert_true( n2.has_common_ancestor(n4) )
162 assert_true( n2.has_common_ancestor(n7) )
163 assert_true( n2.has_common_ancestor(n6) )
165 # cause it's not in the right branch
166 assert_false( n5.has_common_ancestor(n3) )
167 assert_false( n7.has_common_ancestor(n4) )
170 def test_after_merge(library):
171 n8 = library.shelf(8)
172 n7 = library.shelf(7)
173 n6 = library.shelf(6)
175 assert_true( n7.parentof(n8) )
176 assert_false( n8.parentof(n7) )
178 assert_true( n7.ancestorof(n8) )
179 assert_true( n6.ancestorof(n8) )
182 assert_true( n7.has_common_ancestor(n8) )
183 # cause it's not in the right branch
184 assert_false( n8.has_common_ancestor(n7) )
186 @temprepo('merged_with_local_commit')
187 def test_after_merge_and_local_commit(library):
188 n9 = library.shelf(9)
189 n8 = library.shelf(8)
190 n7 = library.shelf(7)
191 n6 = library.shelf(6)
193 assert_true( n7.parentof(n8) )
194 assert_false( n8.parentof(n7) )
196 assert_true( n9.has_common_ancestor(n8) )
197 # cause it's not in the right branch
198 assert_false( n8.has_common_ancestor(n9) )
201 @temprepo('branched2')
202 def test_merge_personal_to_default(library):
203 main = library.shelf(2)
204 local = library.shelf(7)
206 document = library.document("ala", "admin")
207 shared = document.shared()
208 print document, shared
210 document.share("Here is my copy!")
212 assert_equal( document.shelf(), local) # local didn't change
215 new_main = shared.shelf()
216 assert_not_equal( new_main, main) # main has new revision
219 assert_true( main.parentof(new_main) )
220 assert_true( local.parentof(new_main) )
223 def testCreateBranch(library):
224 library = MercurialLibrary(repopath)
226 tester_cab = library.cabinet("anotherone", "tester", create=True)
227 assert_equal( list(tester_cab.documents()), ['anotherone'])