From f670ca5e70962cf7fbc5b1c5758fb70d9c2e0e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Thu, 16 Feb 2012 19:49:48 +0100 Subject: Issue #13878: Fix random test_sched failures. --- Lib/test/test_sched.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py index 29fd277..91b8f0c 100644 --- a/Lib/test/test_sched.py +++ b/Lib/test/test_sched.py @@ -12,10 +12,10 @@ class TestCase(unittest.TestCase): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) - for x in [0.05, 0.04, 0.03, 0.02, 0.01]: + for x in [0.5, 0.4, 0.3, 0.2, 0.1]: z = scheduler.enter(x, 1, fun, (x,)) scheduler.run() - self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + self.assertEqual(l, [0.1, 0.2, 0.3, 0.4, 0.5]) def test_enterabs(self): l = [] @@ -31,7 +31,7 @@ class TestCase(unittest.TestCase): fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for priority in [1, 2, 3, 4, 5]: - z = scheduler.enter(0.01, priority, fun, (priority,)) + z = scheduler.enterabs(0.01, priority, fun, (priority,)) scheduler.run() self.assertEqual(l, [1, 2, 3, 4, 5]) @@ -39,11 +39,12 @@ class TestCase(unittest.TestCase): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) - event1 = scheduler.enter(0.01, 1, fun, (0.01,)) - event2 = scheduler.enter(0.02, 1, fun, (0.02,)) - event3 = scheduler.enter(0.03, 1, fun, (0.03,)) - event4 = scheduler.enter(0.04, 1, fun, (0.04,)) - event5 = scheduler.enter(0.05, 1, fun, (0.05,)) + now = time.time() + event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,)) + event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,)) + event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,)) + event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,)) + event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,)) scheduler.cancel(event1) scheduler.cancel(event5) scheduler.run() -- cgit v0.12 From b3890226b33f86d485dccac309d442b15e766270 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 16 Feb 2012 21:39:03 +0200 Subject: sqlite3: Fix documentation errors concerning Cursor.rowcount Closes #13995. --- Doc/includes/sqlite3/shortcut_methods.py | 3 +-- Doc/library/sqlite3.rst | 11 +++++------ Misc/NEWS | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Doc/includes/sqlite3/shortcut_methods.py b/Doc/includes/sqlite3/shortcut_methods.py index 596d87c..71600d4 100644 --- a/Doc/includes/sqlite3/shortcut_methods.py +++ b/Doc/includes/sqlite3/shortcut_methods.py @@ -17,5 +17,4 @@ con.executemany("insert into person(firstname, lastname) values (?, ?)", persons for row in con.execute("select firstname, lastname from person"): print(row) -# Using a dummy WHERE clause to not let SQLite take the shortcut table deletes. -print("I just deleted", con.execute("delete from person where 1=1").rowcount, "rows") +print("I just deleted", con.execute("delete from person").rowcount, "rows") diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 350950c..f0fd86c 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -543,18 +543,17 @@ Cursor Objects attribute, the database engine's own support for the determination of "rows affected"/"rows selected" is quirky. - For ``DELETE`` statements, SQLite reports :attr:`rowcount` as 0 if you make a - ``DELETE FROM table`` without any condition. - For :meth:`executemany` statements, the number of modifications are summed up into :attr:`rowcount`. As required by the Python DB API Spec, the :attr:`rowcount` attribute "is -1 in case no ``executeXX()`` has been performed on the cursor or the rowcount of the - last operation is not determinable by the interface". + last operation is not determinable by the interface". This includes ``SELECT`` + statements because we cannot determine the number of rows a query produced + until all rows were fetched. - This includes ``SELECT`` statements because we cannot determine the number of - rows a query produced until all rows were fetched. + With SQLite versions before 3.6.5, :attr:`rowcount` is set to 0 if + you make a ``DELETE FROM table`` without any condition. .. attribute:: Cursor.lastrowid diff --git a/Misc/NEWS b/Misc/NEWS index 8b0e12a..9c64855 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -528,8 +528,8 @@ Extension Modules Documentation ------------- -- Issue #13491: Fix many errors in sqlite3 documentation. Initial - patch by Johannes Vogel. +- Issues #13491 and #13995: Fix many errors in sqlite3 documentation. + Initial patch for #13491 by Johannes Vogel. - Issue #13402: Document absoluteness of sys.executable. -- cgit v0.12 From e59a306081d8f34814b91dc9e911beac7271c452 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 16 Feb 2012 23:17:31 +0100 Subject: The C accelerator was not always imported for cElementTree's tests. (there's still an issue with --huntrleaks switch) --- Lib/test/test_xml_etree.py | 1 - Lib/test/test_xml_etree_c.py | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 6060e06..8713de5 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1352,7 +1352,6 @@ def xinclude(): r""" Basic inclusion example (XInclude C.1) - >>> from xml.etree import ElementTree as ET >>> from xml.etree import ElementInclude >>> document = xinclude_loader("C1.xml") diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index dbe1c3a..a73d0c4 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -5,7 +5,7 @@ from test.support import import_fresh_module import unittest cET = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree']) -cET_alias = import_fresh_module('xml.etree.cElementTree', fresh=['_elementtree']) +cET_alias = import_fresh_module('xml.etree.cElementTree', fresh=['_elementtree', 'xml.etree']) # cElementTree specific tests @@ -52,6 +52,9 @@ class TestAcceleratorImported(unittest.TestCase): def test_correct_import_cET(self): self.assertEqual(cET.Element.__module__, '_elementtree') + def test_correct_import_cET_alias(self): + self.assertEqual(cET_alias.Element.__module__, '_elementtree') + def test_main(): from test import test_xml_etree, test_xml_etree_c -- cgit v0.12 From 1639505c383a1c8b46ff6f2a5b9071f26ad43ece Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 16 Feb 2012 23:28:35 +0100 Subject: fix the _namespace_map cleanup for cElementTree tests. --- Lib/test/test_xml_etree.py | 7 +------ Lib/xml/etree/ElementTree.py | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 8713de5..58fdcd4 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1881,12 +1881,7 @@ class CleanContext(object): def __enter__(self): from xml.etree import ElementPath - if hasattr(ET, '_namespace_map'): - self._nsmap = ET._namespace_map - else: - # when testing the cElementTree alias - from xml.etree.ElementTree import _namespace_map - self._nsmap = _namespace_map + self._nsmap = ET.register_namespace._namespace_map # Copy the default namespace mapping self._nsmap_copy = self._nsmap.copy() # Copy the path cache (should be empty) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 93147eb..defef0d 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1086,6 +1086,8 @@ _namespace_map = { # dublin core "http://purl.org/dc/elements/1.1/": "dc", } +# For tests and troubleshooting +register_namespace._namespace_map = _namespace_map def _raise_serialization_error(text): raise TypeError( -- cgit v0.12