[python-sqlamp] Added upstreams patch to fix issues with tests on python 2.7

Martin Bacovsky mbacovsk at fedoraproject.org
Mon Oct 3 22:01:43 UTC 2011


commit 6055b970189753070e15124dc2697333050e7684
Author: Martin Bačovský <mbacovsk at redhat.com>
Date:   Mon Oct 3 22:09:11 2011 +0200

    Added upstreams patch to fix issues with tests on python 2.7

 python-sqlamp.spec  |    3 +
 python_compat.patch |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 235 insertions(+), 0 deletions(-)
---
diff --git a/python-sqlamp.spec b/python-sqlamp.spec
index 29f9373..7a9add9 100644
--- a/python-sqlamp.spec
+++ b/python-sqlamp.spec
@@ -14,6 +14,7 @@ Source0:        http://sqlamp.angri.ru/sqlamp-%{version}.tar.gz
 Patch0:         sa0.6.6.patch
 Patch1:         sqlite-3.6.x-bug-workaround.patch
 Patch2:         sa72.patch
+Patch3:         python_compat.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch:      noarch
 
@@ -34,6 +35,7 @@ with hierarchical data structures. sqlamp uses (and depends on) SQLAlchemy.
 %patch0 -p1
 %patch1 -p1
 %patch2 -p1
+%patch3 -p1
 
 %build
 %{__python} setup.py build
@@ -72,6 +74,7 @@ rm -rf %{buildroot}
 * Thu Jun 30 2011 Martin Bacovsky <mbacovsk at redhat.com> - 0.5.2-3
 - Fixed #715906 FTBFS due to SA upgrade to 0.7.x
 - Backported upstreams patch adding support for SQLAlchemy 0.7.2
+- added upstreams patch to fix issues with tests on python 2.7
 
 * Mon Mar 28 2011 Martin Bacovsky <mbacovsk at redhat.com> - 0.5.2-2
 - Fixed support of SQLAlchemy 0.6.6 in MPOptions.order_by_clause(). Patch by Josip Delic.
diff --git a/python_compat.patch b/python_compat.patch
new file mode 100644
index 0000000..08d1d9c
--- /dev/null
+++ b/python_compat.patch
@@ -0,0 +1,232 @@
+diff -r 26f59cbfac52 -r 8c0646ffd245 CHANGES
+--- a/CHANGES	Wed Jun 22 23:15:27 2011 +0200
++++ b/CHANGES	Mon Jun 27 19:53:27 2011 +0200
+@@ -14,6 +14,7 @@
+ the argument provided, so if you construct your queries by hand (which is not
+ recommended) --- make sure that they're properly ordered.
+ 
++- Python branches 2.4 to 2.7 as well as python3 are supported now.
+ - :class:`MPClassManager` can not be used as an argument for `order_by()`.
+   Instead use method :meth:`MPClassManager.query` for constructing queries.
+ - Method :meth:`MPClassManager.query_all_trees` was renamed
+diff -r 26f59cbfac52 -r 8c0646ffd245 README
+--- a/README	Wed Jun 22 23:15:27 2011 +0200
++++ b/README	Mon Jun 27 19:53:27 2011 +0200
+@@ -6,8 +6,7 @@
+ 
+ Requirements
+ ------------
+-Requires SQLAlchemy >= 0.5. Known to work well with python 2.6 but should
+-also work with python 2.4+. Known-to-work supported DBMS include sqlite
++Requires SQLAlchemy >= 0.5. Known-to-work supported DBMS include sqlite
+ (tested with 3.6.14), MySQL (tested using both MyISAM and InnoDB with
+ server version 5.1.34) and PostgreSQL (tested with 8.3.7), but sqlamp
+ should work with any other DBMS supported by SQLAlchemy.
+diff -r 26f59cbfac52 -r 8c0646ffd245 sqlamp/__init__.py
+--- a/sqlamp/__init__.py	Wed Jun 22 23:15:27 2011 +0200
++++ b/sqlamp/__init__.py	Mon Jun 27 19:53:27 2011 +0200
+@@ -75,6 +75,27 @@
+ __version__ = (0, 5, 2)
+ __doc__ %= {'version': '.'.join(map(str, __version__))}
+ 
++try:
++    # Backward compatibility: `all` is new in python 2.5
++    all
++except NameError:
++    def all(iterable):
++        for element in iterable:
++            if not element:
++                return False
++        return True
++try:
++    # The same for `next`.`
++    next
++except NameError:
++    def next(iterable):
++        return iterable.next()
++try:
++    # Forward compatibility: there is no `basestring` in python3
++    basestring
++except NameError:
++    basestring = str
++
+ 
+ ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ PATH_FIELD_LENGTH = 255
+@@ -122,10 +143,9 @@
+     '3380'
+     >>> inc_path('GWZZZ', 5)
+     'GX000'
+-    >>> inc_path('ABZZ', 2)
+-    Traceback (most recent call last):
+-        ...
+-    PathOverflowError
++    >>> import unittest
++    >>> unittest.TestCase('id').assertRaises(PathOverflowError, \
++                                             inc_path, 'ABZZ', 2)
+     """
+     parent_path, path = path[:-steplen], path[-steplen:]
+     path = path.rstrip(ALPHABET[-1])
+@@ -157,7 +177,7 @@
+         self.steplen = steplen
+ 
+         self.max_children = len(ALPHABET) ** steplen
+-        self.max_depth = (PATH_FIELD_LENGTH / steplen) + 1
++        self.max_depth = (PATH_FIELD_LENGTH // steplen) + 1
+ 
+         assert len(table.primary_key.columns) == 1, \
+                "Composite primary keys not supported"
+@@ -207,7 +227,8 @@
+                 unique=True
+             ),
+         ]
+-        map(table.append_constraint, self.indices)
++        for index in self.indices:
++            table.append_constraint(index)
+ 
+     def query(self, entities, session):
+         """
+@@ -850,9 +871,9 @@
+     have `_nonexistent` object at the second place.
+ 
+     >>> x = _iter_current_next('1234')
+-    >>> x.next(), x.next(), x.next()
++    >>> next(x), next(x), next(x)
+     (('1', '2'), ('2', '3'), ('3', '4'))
+-    >>> x.next() == ('4', _nonexistent)
++    >>> next(x) == ('4', _nonexistent)
+     True
+     >>> list(_iter_current_next(''))
+     []
+@@ -860,10 +881,10 @@
+     True
+     """
+     iterator = iter(sequence)
+-    current_item = iterator.next()
++    current_item = next(iterator)
+     while current_item != _nonexistent:
+         try:
+-            next_item = iterator.next()
++            next_item = next(iterator)
+         except StopIteration:
+             next_item = _nonexistent
+         yield (current_item, next_item)
+@@ -887,9 +908,9 @@
+     [('A', [('B', [('C', [])])]), ('A', [('B', []), ('B', [])])]
+     >>> listify(_recursive_iterator('', is_child_func))
+     []
+-    >>> _recursive_iterator('A', is_child_func).next()
++    >>> next(_recursive_iterator('A', is_child_func))
+     ('A', ())
+-    >>> _recursive_iterator('AB', is_child_func).next() # doctest: +ELLIPSIS
++    >>> next(_recursive_iterator('AB', is_child_func)) # doctest: +ELLIPSIS
+     ('A', <generator object ...>)
+     """
+     current_next_iterator = _iter_current_next(sequence)
+@@ -899,7 +920,7 @@
+             and is_child_func(node, item['next'])
+ 
+     def step():
+-        item['current'], item['next'] = current_next_iterator.next()
++        item['current'], item['next'] = next(current_next_iterator)
+         if is_parent_of_next(item['current']):
+             return (item['current'], children_generator(item['current']))
+         else:
+diff -r 26f59cbfac52 -r 8c0646ffd245 tests/_testlib.py
+--- a/tests/_testlib.py	Wed Jun 22 23:15:27 2011 +0200
++++ b/tests/_testlib.py	Mon Jun 27 19:53:27 2011 +0200
+@@ -53,7 +53,7 @@
+         mp = sqlamp.MPManager(tbl, steplen=2)
+ 
+         def __init__(self, **kwargs):
+-            for key, val in kwargs.iteritems():
++            for key, val in kwargs.items():
+                 setattr(self, key, val)
+ 
+         def __repr__(self):
+diff -r 26f59cbfac52 -r 8c0646ffd245 tests/benchmark-tests.py
+--- a/tests/benchmark-tests.py	Wed Jun 22 23:15:27 2011 +0200
++++ b/tests/benchmark-tests.py	Mon Jun 27 19:53:27 2011 +0200
+@@ -18,7 +18,7 @@
+     def _base_insertion_benchmark(self, num_nodes, num_roots, commit_once):
+         import random
+         MAX_DEPTH = 20
+-        node_ids = [list() for x in xrange(MAX_DEPTH)]
++        node_ids = [list() for x in range(MAX_DEPTH)]
+         def random_parent_id():
+             depth = MAX_DEPTH * 1.5625 * (random.random() - 0.2) ** 2
+             depth = int(depth)
+@@ -27,13 +27,13 @@
+             return random.choice(node_ids[depth])
+ 
+         start = time()
+-        for x in xrange(num_roots):
++        for x in range(num_roots):
+             root = Cls()
+             self.sess.add(root)
+             self.sess.flush()
+             self.sess.commit()
+             node_ids[0].append(root.id)
+-        for x in xrange(num_nodes - num_roots):
++        for x in range(num_nodes - num_roots):
+             parent_id = random_parent_id()
+             node = Cls(parent_id=parent_id)
+             self.sess.add(node)
+@@ -50,29 +50,29 @@
+         elapsed = time() - start
+         transactions = commit_once and "all in one transaction" \
+                                    or "each in self transaction"
+-        print "%d insertions in %.2f seconds %s " \
++        print("%d insertions in %.2f seconds %s " \
+               "(%.2f insertions per second)" % \
+-              (num_nodes, elapsed, transactions, num_nodes / elapsed)
++              (num_nodes, elapsed, transactions, num_nodes / elapsed))
+ 
+     def _descendants_benchmark(self, num_passes):
+         total_children = 0
+         total_nodes = self.sess.query(Cls).count()
+         start = time()
+-        for x in xrange(num_passes):
++        for x in range(num_passes):
+             for node in self.sess.query(Cls):
+                 total_children += len(node.mp.query_descendants().all())
+         elapsed = time() - start
+         queries = num_passes * total_nodes
+         average_children = float(total_children) / queries
+-        print "%d queries in %.2f seconds (%.2f queries per second), " \
++        print("%d queries in %.2f seconds (%.2f queries per second), " \
+               "average of %.2f descendants in each node." % \
+-              (queries, elapsed, queries / elapsed, average_children)
++              (queries, elapsed, queries / elapsed, average_children))
+ 
+     def test_benchmark(self):
+         if not os.environ.get('BENCHMARK'):
+-            print "NB: benchmarks skipped."
++            print("NB: benchmarks skipped.")
+             return
+-        print "BENCHMARKING..."
++        print("BENCHMARKING...")
+         self._base_insertion_benchmark(
+             commit_once=False, num_nodes=1000, num_roots=10
+         )
+diff -r 26f59cbfac52 -r 8c0646ffd245 tests/functional-tests.py
+--- a/tests/functional-tests.py	Wed Jun 22 23:15:27 2011 +0200
++++ b/tests/functional-tests.py	Mon Jun 27 19:53:27 2011 +0200
+@@ -233,7 +233,7 @@
+         root = Cls()
+         self.sess.add(root)
+         self.sess.commit()
+-        for x in xrange(1296):
++        for x in range(1296):
+             self.sess.add(Cls(parent=root, name=str(x)))
+         self.sess.commit()
+         self.sess.add(Cls(parent=root))
+@@ -250,7 +250,7 @@
+     def test_path_too_deep(self):
+         self.assertEqual(Cls.mp.max_depth, 128) # int(255 / 2) + 1
+         node = None
+-        for x in xrange(128):
++        for x in range(128):
+             new_node = Cls(parent=node)
+             self.sess.add(new_node)
+             self.sess.flush()


More information about the scm-commits mailing list