test/unittest_rset.py
changeset 6366 1806148d6ce8
parent 6225 a176e68b7d0d
parent 6340 470d8e828fda
child 6367 d4c485ec1ca1
--- a/test/unittest_rset.py	Thu Sep 23 23:28:58 2010 +0200
+++ b/test/unittest_rset.py	Wed Sep 29 16:16:32 2010 +0200
@@ -16,9 +16,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""unit tests for module cubicweb.utils
-
-"""
+"""unit tests for module cubicweb.utils"""
 
 from urlparse import urlsplit
 import pickle
@@ -52,7 +50,7 @@
             }
         for rql, relations in queries.items():
             result = list(attr_desc_iterator(parse(rql).children[0]))
-            self.assertEquals((rql, result), (rql, relations))
+            self.assertEqual((rql, result), (rql, relations))
 
     def test_relations_description_indexed(self):
         """tests relations_description() function"""
@@ -63,7 +61,7 @@
         for rql, results in queries.items():
             for var_index, relations in results.items():
                 result = list(attr_desc_iterator(parse(rql).children[0], var_index))
-                self.assertEquals(result, relations)
+                self.assertEqual(result, relations)
 
 
 
@@ -79,15 +77,15 @@
     def compare_urls(self, url1, url2):
         info1 = urlsplit(url1)
         info2 = urlsplit(url2)
-        self.assertEquals(info1[:3], info2[:3])
+        self.assertEqual(info1[:3], info2[:3])
         if info1[3] != info2[3]:
             params1 = dict(pair.split('=') for pair in info1[3].split('&'))
             params2 = dict(pair.split('=') for pair in info1[3].split('&'))
-            self.assertDictEquals(params1, params2)
+            self.assertDictEqual(params1, params2)
 
     def test_pickle(self):
         del self.rset.req
-        self.assertEquals(len(pickle.dumps(self.rset)), 392)
+        self.assertEqual(len(pickle.dumps(self.rset)), 392)
 
     def test_build_url(self):
         req = self.request()
@@ -105,9 +103,9 @@
     def test_resultset_build(self):
         """test basic build of a ResultSet"""
         rs = ResultSet([1,2,3], 'CWGroup X', description=['CWGroup', 'CWGroup', 'CWGroup'])
-        self.assertEquals(rs.rowcount, 3)
-        self.assertEquals(rs.rows, [1,2,3])
-        self.assertEquals(rs.description, ['CWGroup', 'CWGroup', 'CWGroup'])
+        self.assertEqual(rs.rowcount, 3)
+        self.assertEqual(rs.rows, [1,2,3])
+        self.assertEqual(rs.description, ['CWGroup', 'CWGroup', 'CWGroup'])
 
 
     def test_resultset_limit(self):
@@ -117,12 +115,12 @@
         rs.req = self.request()
         rs.vreg = self.vreg
 
-        self.assertEquals(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']])
+        self.assertEqual(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']])
         rs2 = rs.limit(2, offset=1)
-        self.assertEquals(rs2.rows, [[13000, 'syt'], [14000, 'nico']])
-        self.assertEquals(rs2.get_entity(0, 0).cw_row, 0)
-        self.assertEquals(rs.limit(2, offset=2).rows, [[14000, 'nico']])
-        self.assertEquals(rs.limit(2, offset=3).rows, [])
+        self.assertEqual(rs2.rows, [[13000, 'syt'], [14000, 'nico']])
+        self.assertEqual(rs2.get_entity(0, 0).cw_row, 0)
+        self.assertEqual(rs.limit(2, offset=2).rows, [[14000, 'nico']])
+        self.assertEqual(rs.limit(2, offset=3).rows, [])
 
 
     def test_resultset_filter(self):
@@ -135,8 +133,8 @@
             return entity.login != 'nico'
 
         rs2 = rs.filtered_rset(test_filter)
-        self.assertEquals(len(rs2), 2)
-        self.assertEquals([login for _, login in rs2], ['adim', 'syt'])
+        self.assertEqual(len(rs2), 2)
+        self.assertEqual([login for _, login in rs2], ['adim', 'syt'])
 
     def test_resultset_transform(self):
         rs = ResultSet([[12, 'adim'], [13, 'syt'], [14, 'nico']],
@@ -147,8 +145,8 @@
             return row[1:], desc[1:]
         rs2 = rs.transformed_rset(test_transform)
 
-        self.assertEquals(len(rs2), 3)
-        self.assertEquals(list(rs2), [['adim'],['syt'],['nico']])
+        self.assertEqual(len(rs2), 3)
+        self.assertEqual(list(rs2), [['adim'],['syt'],['nico']])
 
     def test_resultset_sort(self):
         rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']],
@@ -157,23 +155,35 @@
         rs.req = self.request()
         rs.vreg = self.vreg
 
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login'])
         self.assertEquals(len(rs2), 3)
         self.assertEquals([login for _, login in rs2], ['adim', 'nico', 'syt'])
+=======
+        rs2 = rs.sorted_rset(lambda e:e['login'])
+        self.assertEqual(len(rs2), 3)
+        self.assertEqual([login for _, login in rs2], ['adim', 'nico', 'syt'])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         # make sure rs is unchanged
-        self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico'])
+        self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico'])
 
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         rs2 = rs.sorted_rset(lambda e:e.cw_attr_cache['login'], reverse=True)
         self.assertEquals(len(rs2), 3)
         self.assertEquals([login for _, login in rs2], ['syt', 'nico', 'adim'])
+=======
+        rs2 = rs.sorted_rset(lambda e:e['login'], reverse=True)
+        self.assertEqual(len(rs2), 3)
+        self.assertEqual([login for _, login in rs2], ['syt', 'nico', 'adim'])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         # make sure rs is unchanged
-        self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico'])
+        self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico'])
 
         rs3 = rs.sorted_rset(lambda row: row[1], col=-1)
-        self.assertEquals(len(rs3), 3)
-        self.assertEquals([login for _, login in rs3], ['adim', 'nico', 'syt'])
+        self.assertEqual(len(rs3), 3)
+        self.assertEqual([login for _, login in rs3], ['adim', 'nico', 'syt'])
         # make sure rs is unchanged
-        self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico'])
+        self.assertEqual([login for _, login in rs], ['adim', 'syt', 'nico'])
 
     def test_resultset_split(self):
         rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'],
@@ -187,33 +197,49 @@
         rs.req = self.request()
         rs.vreg = self.vreg
 
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         rsets = rs.split_rset(lambda e:e.cw_attr_cache['login'])
         self.assertEquals(len(rsets), 3)
         self.assertEquals([login for _, login,_ in rsets[0]], ['adim', 'adim'])
         self.assertEquals([login for _, login,_ in rsets[1]], ['syt'])
         self.assertEquals([login for _, login,_ in rsets[2]], ['nico', 'nico'])
+=======
+        rsets = rs.split_rset(lambda e:e['login'])
+        self.assertEqual(len(rsets), 3)
+        self.assertEqual([login for _, login,_ in rsets[0]], ['adim', 'adim'])
+        self.assertEqual([login for _, login,_ in rsets[1]], ['syt'])
+        self.assertEqual([login for _, login,_ in rsets[2]], ['nico', 'nico'])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         # make sure rs is unchanged
-        self.assertEquals([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico'])
+        self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico'])
 
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         rsets = rs.split_rset(lambda e:e.cw_attr_cache['login'], return_dict=True)
         self.assertEquals(len(rsets), 3)
         self.assertEquals([login for _, login,_ in rsets['nico']], ['nico', 'nico'])
         self.assertEquals([login for _, login,_ in rsets['adim']], ['adim', 'adim'])
         self.assertEquals([login for _, login,_ in rsets['syt']], ['syt'])
+=======
+        rsets = rs.split_rset(lambda e:e['login'], return_dict=True)
+        self.assertEqual(len(rsets), 3)
+        self.assertEqual([login for _, login,_ in rsets['nico']], ['nico', 'nico'])
+        self.assertEqual([login for _, login,_ in rsets['adim']], ['adim', 'adim'])
+        self.assertEqual([login for _, login,_ in rsets['syt']], ['syt'])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         # make sure rs is unchanged
-        self.assertEquals([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico'])
+        self.assertEqual([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico'])
 
         rsets = rs.split_rset(lambda s: s.count('d'), col=2)
-        self.assertEquals(len(rsets), 2)
-        self.assertEquals([title for _, _, title in rsets[0]],
+        self.assertEqual(len(rsets), 2)
+        self.assertEqual([title for _, _, title in rsets[0]],
                           [u"Adim chez les pinguins",
                            u"Jardiner facile",
                            u"L'épluchage du castor commun",])
-        self.assertEquals([title for _, _, title in rsets[1]],
+        self.assertEqual([title for _, _, title in rsets[1]],
                           [u"Le carrelage en 42 leçons",
                            u"La tarte tatin en 15 minutes",])
         # make sure rs is unchanged
-        self.assertEquals([title for _, _, title in rs],
+        self.assertEqual([title for _, _, title in rs],
                           [u'Adim chez les pinguins',
                            u'Jardiner facile',
                            u'Le carrelage en 42 leçons',
@@ -228,15 +254,27 @@
 
     def test_get_entity_simple(self):
         self.request().create_entity('CWUser', login=u'adim', upassword='adim',
-                        surname=u'di mascio', firstname=u'adrien')
+                                     surname=u'di mascio', firstname=u'adrien')
         e = self.execute('Any X,T WHERE X login "adim", X surname T').get_entity(0, 0)
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_attr_cache['surname'], 'di mascio')
         self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname')
         self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'creation_date')
         self.assertEquals(pprelcachedict(e._cw_related_cache), [])
+=======
+        self.assertEqual(e['surname'], 'di mascio')
+        self.assertRaises(KeyError, e.__getitem__, 'firstname')
+        self.assertRaises(KeyError, e.__getitem__, 'creation_date')
+        self.assertEqual(pprelcachedict(e._cw_related_cache), [])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         e.complete()
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_attr_cache['firstname'], 'adrien')
         self.assertEquals(pprelcachedict(e._cw_related_cache), [])
+=======
+        self.assertEqual(e['firstname'], 'adrien')
+        self.assertEqual(pprelcachedict(e._cw_related_cache), [])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
 
     def test_get_entity_advanced(self):
         self.request().create_entity('Bookmark', title=u'zou', path=u'/view')
@@ -244,24 +282,47 @@
         rset = self.execute('Any X,Y,XT,YN WHERE X bookmarked_by Y, X title XT, Y login YN')
 
         e = rset.get_entity(0, 0)
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_row, 0)
         self.assertEquals(e.cw_col, 0)
         self.assertEquals(e.cw_attr_cache['title'], 'zou')
         self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'path')
         self.assertEquals(e.view('text'), 'zou')
         self.assertEquals(pprelcachedict(e._cw_related_cache), [])
+=======
+        self.assertEqual(e.cw_row, 0)
+        self.assertEqual(e.cw_col, 0)
+        self.assertEqual(e['title'], 'zou')
+        self.assertRaises(KeyError, e.__getitem__, 'path')
+        self.assertEqual(e.view('text'), 'zou')
+        self.assertEqual(pprelcachedict(e._cw_related_cache), [])
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
 
         e = rset.get_entity(0, 1)
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_row, 0)
         self.assertEquals(e.cw_col, 1)
         self.assertEquals(e.cw_attr_cache['login'], 'anon')
         self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname')
         self.assertEquals(pprelcachedict(e._cw_related_cache),
+=======
+        self.assertEqual(e.cw_row, 0)
+        self.assertEqual(e.cw_col, 1)
+        self.assertEqual(e['login'], 'anon')
+        self.assertRaises(KeyError, e.__getitem__, 'firstname')
+        self.assertEqual(pprelcachedict(e._cw_related_cache),
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
                           [])
         e.complete()
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_attr_cache['firstname'], None)
         self.assertEquals(e.view('text'), 'anon')
         self.assertEquals(pprelcachedict(e._cw_related_cache),
+=======
+        self.assertEqual(e['firstname'], None)
+        self.assertEqual(e.view('text'), 'anon')
+        self.assertEqual(pprelcachedict(e._cw_related_cache),
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
                           [])
 
         self.assertRaises(NotAnEntity, rset.get_entity, 0, 2)
@@ -273,7 +334,7 @@
         seid = self.execute('State X WHERE X name "activated"')[0][0]
         # for_user / in_group are prefetched in CWUser __init__, in_state should
         # be filed from our query rset
-        self.assertEquals(pprelcachedict(e._cw_related_cache),
+        self.assertEqual(pprelcachedict(e._cw_related_cache),
                           [('in_state_subject', [seid])])
 
     def test_get_entity_advanced_prefilled_cache(self):
@@ -282,17 +343,32 @@
         rset = self.execute('Any X,U,S,XT,UL,SN WHERE X created_by U, U in_state S, '
                             'X title XT, S name SN, U login UL, X eid %s' % e.eid)
         e = rset.get_entity(0, 0)
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(e.cw_attr_cache['title'], 'zou')
         self.assertEquals(pprelcachedict(e._cw_related_cache),
+=======
+        self.assertEqual(e['title'], 'zou')
+        self.assertEqual(pprelcachedict(e._cw_related_cache),
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
                           [('created_by_subject', [5])])
         # first level of recursion
         u = e.created_by[0]
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(u.cw_attr_cache['login'], 'admin')
         self.assertRaises(KeyError, u.cw_attr_cache.__getitem__, 'firstname')
+=======
+        self.assertEqual(u['login'], 'admin')
+        self.assertRaises(KeyError, u.__getitem__, 'firstname')
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
         # second level of recursion
         s = u.in_state[0]
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
         self.assertEquals(s.cw_attr_cache['name'], 'activated')
         self.assertRaises(KeyError, s.cw_attr_cache.__getitem__, 'description')
+=======
+        self.assertEqual(s['name'], 'activated')
+        self.assertRaises(KeyError, s.__getitem__, 'description')
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
 
 
     def test_get_entity_cache_with_left_outer_join(self):
@@ -302,11 +378,11 @@
         e = rset.get_entity(0, 0)
         # if any of the assertion below fails with a KeyError, the relation is not cached
         # related entities should be an empty list
-        self.assertEquals(e._cw_relation_cache('primary_email', 'subject', True), ())
+        self.assertEqual(e._cw_relation_cache('primary_email', 'subject', True), ())
         # related rset should be an empty rset
         cached = e._cw_relation_cache('primary_email', 'subject', False)
         self.assertIsInstance(cached, ResultSet)
-        self.assertEquals(cached.rowcount, 0)
+        self.assertEqual(cached.rowcount, 0)
 
 
     def test_get_entity_union(self):
@@ -320,16 +396,20 @@
                     ('CWGroup', 'users'))
         for entity in rset.entities(): # test get_entity for each row actually
             etype, n = expected[entity.cw_row]
-            self.assertEquals(entity.__regid__, etype)
+            self.assertEqual(entity.__regid__, etype)
             attr = etype == 'Bookmark' and 'title' or 'name'
+<<<<<<< /home/syt/src/fcubicweb/cubicweb/test/unittest_rset.py
             self.assertEquals(entity.cw_attr_cache[attr], n)
+=======
+            self.assertEqual(entity[attr], n)
+>>>>>>> /tmp/unittest_rset.py~other.4ZXPmp
 
     def test_related_entity_optional(self):
         e = self.request().create_entity('Bookmark', title=u'aaaa', path=u'path')
         rset = self.execute('Any B,U,L WHERE B bookmarked_by U?, U login L')
         entity, rtype = rset.related_entity(0, 2)
-        self.assertEquals(entity, None)
-        self.assertEquals(rtype, None)
+        self.assertEqual(entity, None)
+        self.assertEqual(rtype, None)
 
     def test_related_entity_union_subquery(self):
         e = self.request().create_entity('Bookmark', title=u'aaaa', path=u'path')
@@ -338,27 +418,27 @@
                             ' UNION '
                             ' (Any X,N WHERE X is Bookmark, X title N))')
         entity, rtype = rset.related_entity(0, 1)
-        self.assertEquals(entity.eid, e.eid)
-        self.assertEquals(rtype, 'title')
+        self.assertEqual(entity.eid, e.eid)
+        self.assertEqual(rtype, 'title')
         entity, rtype = rset.related_entity(1, 1)
-        self.assertEquals(entity.__regid__, 'CWGroup')
-        self.assertEquals(rtype, 'name')
+        self.assertEqual(entity.__regid__, 'CWGroup')
+        self.assertEqual(rtype, 'name')
         #
         rset = self.execute('Any X,N ORDERBY N WHERE X is Bookmark WITH X,N BEING '
                             '((Any X,N WHERE X is CWGroup, X name N)'
                             ' UNION '
                             ' (Any X,N WHERE X is Bookmark, X title N))')
         entity, rtype = rset.related_entity(0, 1)
-        self.assertEquals(entity.eid, e.eid)
-        self.assertEquals(rtype, 'title')
+        self.assertEqual(entity.eid, e.eid)
+        self.assertEqual(rtype, 'title')
         #
         rset = self.execute('Any X,N ORDERBY N WITH N,X BEING '
                             '((Any N,X WHERE X is CWGroup, X name N)'
                             ' UNION '
                             ' (Any N,X WHERE X is Bookmark, X title N))')
         entity, rtype = rset.related_entity(0, 1)
-        self.assertEquals(entity.eid, e.eid)
-        self.assertEquals(rtype, 'title')
+        self.assertEqual(entity.eid, e.eid)
+        self.assertEqual(rtype, 'title')
 
     def test_related_entity_trap_subquery(self):
         req = self.request()
@@ -372,7 +452,7 @@
         rset = self.execute('Any X,S,L WHERE X in_state S '
                             'WITH X, L BEING (Any X,MAX(L) GROUPBY X '
                             'WHERE X is CWUser, T? wf_info_for X, T creation_date L)')
-        self.assertEquals(len(rset), 2)
+        self.assertEqual(len(rset), 2)
         rset.related_entity(0, 1)
         rset.related_entity(0, 2)
 
@@ -380,28 +460,28 @@
         rset = self.execute('Any U,G WHERE U in_group G')
         # make sure we have at least one element
         self.failUnless(rset)
-        self.assertEquals(set(e.e_schema.type for e in rset.entities(0)),
+        self.assertEqual(set(e.e_schema.type for e in rset.entities(0)),
                           set(['CWUser',]))
-        self.assertEquals(set(e.e_schema.type for e in rset.entities(1)),
+        self.assertEqual(set(e.e_schema.type for e in rset.entities(1)),
                           set(['CWGroup',]))
 
     def test_printable_rql(self):
         rset = self.execute(u'CWEType X WHERE X final FALSE')
-        self.assertEquals(rset.printable_rql(),
+        self.assertEqual(rset.printable_rql(),
                           'Any X WHERE X final FALSE, X is CWEType')
 
     def test_searched_text(self):
         rset = self.execute(u'Any X WHERE X has_text "foobar"')
-        self.assertEquals(rset.searched_text(), 'foobar')
+        self.assertEqual(rset.searched_text(), 'foobar')
         rset = self.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'})
-        self.assertEquals(rset.searched_text(), 'foo')
+        self.assertEqual(rset.searched_text(), 'foo')
 
     def test_union_limited_rql(self):
         rset = self.execute('(Any X,N WHERE X is Bookmark, X title N)'
                             ' UNION '
                             '(Any X,N WHERE X is CWGroup, X name N)')
         rset.limit(2, 10, inplace=True)
-        self.assertEquals(rset.limited_rql(),
+        self.assertEqual(rset.limited_rql(),
                           'Any A,B LIMIT 2 OFFSET 10 '
                           'WITH A,B BEING ('
                           '(Any X,N WHERE X is Bookmark, X title N) '
@@ -411,12 +491,12 @@
 
     def test_count_users_by_date(self):
         rset = self.execute('Any D, COUNT(U) GROUPBY D WHERE U is CWUser, U creation_date D')
-        self.assertEquals(rset.related_entity(0,0), (None, None))
+        self.assertEqual(rset.related_entity(0,0), (None, None))
 
     def test_str(self):
         rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)')
         self.assertIsInstance(str(rset), basestring)
-        self.assertEquals(len(str(rset).splitlines()), 1)
+        self.assertEqual(len(str(rset).splitlines()), 1)
 
     def test_repr(self):
         rset = self.execute('(Any X,N WHERE X is CWGroup, X name N)')
@@ -425,7 +505,7 @@
 
         rset = self.execute('(Any X WHERE X is CWGroup, X name "managers")')
         self.assertIsInstance(str(rset), basestring)
-        self.assertEquals(len(str(rset).splitlines()), 1)
+        self.assertEqual(len(str(rset).splitlines()), 1)
 
 if __name__ == '__main__':
     unittest_main()