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 *
9 from wlrepo import MercurialLibrary
11 import os, os.path, tempfile
14 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data')
18 from functools import wraps
21 def decorated(*args, **kwargs):
24 temp = tempfile.mkdtemp("", "testdir_" )
25 path = os.path.join(temp, 'repo')
26 shutil.copytree(os.path.join(REPO_TEMPLATES, name), path, False)
27 kwargs['library'] = MercurialLibrary(path)
31 #if not clean and self.response:
32 # print "RESULT", func.__name__, ">>>"
35 shutil.rmtree(temp, True)
37 decorated = make_decorator(func)(decorated)
43 def test_opening(library):
47 def test_read_document(library):
48 doc = library.document('sample')
49 assert_equal(doc.data('xml'), 'Ala ma kota\n')
52 def test_read_UTF8_document(library):
53 doc = library.document('sample_pl')
54 assert_equal(doc.data('xml'), u'Gżegżółka\n'.encode('utf-8'))
57 def test_change_document(library):
58 doc = library.document('sample')
59 STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
61 def write_action(library, resolve):
62 f = library._fileopen(resolve('xml'), 'r+')
63 assert_equal(f.read(), 'Ala ma kota\n')
68 assert_equal(f.read(), STRING)
70 def commit_info(document):
71 return ("Document rewrite", "library")
73 ndoc = doc.invoke_and_commit(write_action, commit_info)
74 assert_equal(ndoc.data('xml'), STRING)
78 def test_create_document(library):
79 assert_equal(sorted(library.documents()), sorted(['sample', 'sample_pl']))
81 doc = library.document_create("creation")
82 doc.quickwrite("xml", "<ala />", "Quick write", user="library")
84 assert_equal(sorted(library.documents()), sorted(['sample', 'sample_pl', 'creation']))
87 #@temprepo('branched')
88 #def test_switch_branch(library):
89 # tester_cab = library.cabinet("valid_file", "tester", create=False)
90 # assert_equal( list(tester_cab.parts()), ['valid_file'])
92 #@raises(wlrepo.CabinetNotFound)
93 #@temprepo('branched')
94 #def test_branch_not_found(library):
95 # tester_cab = library.cabinet("ugh", "tester", create=False)
97 #@temprepo('branched')
98 #def test_no_branches(library):
99 # n4 = library.shelf(4)
100 # n3 = library.shelf(3)
101 # n2 = library.shelf(2)
102 # n1 = library.shelf(1)
103 # n0 = library.shelf(0)
105 # assert_true( n3.parentof(n4) )
106 # assert_false( n4.parentof(n3) )
107 # assert_true( n0.parentof(n1) )
108 # assert_false( n1.parentof(n0) )
109 # assert_false( n0.parentof(n4) )
111 ## def test_ancestor_of_simple(self):
112 # assert_true( n3.ancestorof(n4) )
113 # assert_true( n2.ancestorof(n4) )
114 # assert_true( n1.ancestorof(n4) )
115 # assert_true( n0.ancestorof(n4) )
117 # assert_true( n2.ancestorof(n3) )
118 # assert_true( n1.ancestorof(n3) )
119 # assert_true( n0.ancestorof(n3) )
121 # assert_false( n4.ancestorof(n4) )
122 # assert_false( n4.ancestorof(n3) )
123 # assert_false( n3.ancestorof(n2) )
124 # assert_false( n3.ancestorof(n1) )
125 # assert_false( n3.ancestorof(n0) )
127 ## def test_common_ancestor_simple(self):
128 # assert_true( n3.has_common_ancestor(n4) )
129 # assert_true( n3.has_common_ancestor(n3) )
130 # assert_true( n3.has_common_ancestor(n3) )
133 #@temprepo('branched2')
134 #def test_once_branched(library):
135 # n7 = library.shelf(7)
136 # n6 = library.shelf(6)
137 # n5 = library.shelf(5)
138 # n4 = library.shelf(4)
139 # n3 = library.shelf(3)
140 # n2 = library.shelf(2)
142 # assert_true( n2.parentof(n3) )
143 # assert_false( n3.parentof(n2) )
145 # assert_true( n2.parentof(n5) )
146 # assert_false( n5.parentof(n2) )
148 # assert_false( n2.parentof(n4) )
149 # assert_false( n2.parentof(n6) )
150 # assert_false( n3.parentof(n5) )
151 # assert_false( n5.parentof(n3) )
153 ## def test_ancestorof_branched(self):
154 # assert_true( n2.ancestorof(n7) )
155 # assert_false( n7.ancestorof(n2) )
156 # assert_true( n2.ancestorof(n6) )
157 # assert_false( n6.ancestorof(n2) )
158 # assert_true( n2.ancestorof(n5) )
159 # assert_false( n5.ancestorof(n2) )
161 # assert_false( n3.ancestorof(n5) )
162 # assert_false( n5.ancestorof(n3) )
163 # assert_false( n4.ancestorof(n5) )
164 # assert_false( n5.ancestorof(n4) )
165 # assert_false( n3.ancestorof(n7) )
166 # assert_false( n7.ancestorof(n3) )
167 # assert_false( n4.ancestorof(n6) )
168 # assert_false( n6.ancestorof(n4) )
170 ## def test_common_ancestor_branched(self):
171 # assert_true( n2.has_common_ancestor(n4) )
172 # assert_true( n2.has_common_ancestor(n7) )
173 # assert_true( n2.has_common_ancestor(n6) )
175 # # cause it's not in the right branch
176 # assert_false( n5.has_common_ancestor(n3) )
177 # assert_false( n7.has_common_ancestor(n4) )
180 #def test_after_merge(library):
181 # n8 = library.shelf(8)
182 # n7 = library.shelf(7)
183 # n6 = library.shelf(6)
185 # assert_true( n7.parentof(n8) )
186 # assert_false( n8.parentof(n7) )
188 # assert_true( n7.ancestorof(n8) )
189 # assert_true( n6.ancestorof(n8) )
192 # assert_true( n7.has_common_ancestor(n8) )
193 # # cause it's not in the right branch
194 # assert_false( n8.has_common_ancestor(n7) )
196 #@temprepo('merged_with_local_commit')
197 #def test_after_merge_and_local_commit(library):
198 # n9 = library.shelf(9)
199 # n8 = library.shelf(8)
200 # n7 = library.shelf(7)
201 # n6 = library.shelf(6)
203 # assert_true( n7.parentof(n8) )
204 # assert_false( n8.parentof(n7) )
206 # assert_true( n9.has_common_ancestor(n8) )
207 # # cause it's not in the right branch
208 # assert_false( n8.has_common_ancestor(n9) )
211 #@temprepo('branched2')
212 #def test_merge_personal_to_default(library):
213 # main = library.shelf(2)
216 # local = library.shelf(7)
219 # document = library.document("ala", "admin")
220 # shared = document.shared()
221 # assert_true( shared is None )
222 # document.share("Here is my copy!")
224 # assert_equal( document.shelf(), local) # local didn't change
226 # shared = document.shared()
227 # assert_true( shared is not None )
229 # print library.shelf()
231 # new_main = shared.shelf()
232 # assert_not_equal( new_main, main) # main has new revision
234 # # check for parents
235 # assert_true( main.parentof(new_main) )
236 # assert_true( local.parentof(new_main) )
239 #def test_create_branch(library):
240 # tester_cab = library.cabinet("anotherone", "tester", create=True)
241 # assert_equal( list(tester_cab.parts()), ['anotherone'])