Merge lp:~thumper/launchpad/fix-TestSharingMigrationPerformance into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Merged at revision: 11363
Proposed branch: lp:~thumper/launchpad/fix-TestSharingMigrationPerformance
Merge into: lp:launchpad
Diff against target: 114 lines (+29/-61)
1 file modified
lib/lp/translations/scripts/tests/test_message_sharing_migration.py (+29/-61)
To merge this branch: bzr merge lp:~thumper/launchpad/fix-TestSharingMigrationPerformance
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+32828@code.launchpad.net

Commit message

Fix TestSharingMigrationPerformance to not call gc.get_objects().

Description of the change

Fix the lp.translations.scripts.tests.test_message_sharing_migration.TestSharingMigrationPerformance test to not use gc.get_objects() as this interacts badly with bzrlib lazy imports.

The test is also a little more explicit.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Its also a very expensive function to call. This is much more appropriate.

Small nit:
+from lp.testing import (
+ record_statements,
+ TestCaseWithFactory)

should be
+from lp.testing import (
+ record_statements,
+ TestCaseWithFactory,
+ )

as per the list policy in the wiki.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/scripts/tests/test_message_sharing_migration.py'
2--- lib/lp/translations/scripts/tests/test_message_sharing_migration.py 2009-11-27 12:50:16 +0000
3+++ lib/lp/translations/scripts/tests/test_message_sharing_migration.py 2010-08-17 02:31:46 +0000
4@@ -13,7 +13,10 @@
5 from zope.security.proxy import removeSecurityProxy
6
7 from lp.services.worlddata.interfaces.language import ILanguageSet
8-from lp.testing import TestCaseWithFactory
9+from lp.testing import (
10+ record_statements,
11+ TestCaseWithFactory,
12+ )
13 from lp.translations.interfaces.pofiletranslator import (
14 IPOFileTranslatorSet)
15 from lp.translations.model.pomsgid import POMsgID
16@@ -742,22 +745,6 @@
17 transaction.commit()
18 gc.collect()
19
20- def _listLoadedObjects(self, of_class, ignore_list=None):
21- """Return the set of objects of a given type that are in memory.
22-
23- :param of_class: A class to filter for.
24- :param ignore_list: A previous return value. Any POMsgIDs that
25- were already in that list are ignored here.
26- """
27- pomsgids = set([
28- whatever
29- for whatever in gc.get_objects()
30- if isinstance(whatever, of_class)
31- ])
32- if ignore_list is not None:
33- pomsgids -= ignore_list
34- return pomsgids
35-
36 def _resetReferences(self):
37 """Reset translation-related references in the test object.
38
39@@ -782,50 +769,31 @@
40
41 self.templates = [POTemplate.get(id) for id in template_ids]
42
43- def test_merging_loads_no_msgids(self):
44- # Migration does not load actual msgids into memory.
45- self._flushDbObjects()
46- msgids_before = self._listLoadedObjects(POMsgID)
47-
48- self._makeTranslationMessages('x', 'y', trunk_diverged=True)
49- self._makeTranslationMessages('1', '2', stable_diverged=True)
50-
51- self._resetReferences()
52- self.assertNotEqual([], self.templates)
53- self.assertEqual(
54- set(), self._listLoadedObjects(POMsgID, msgids_before))
55-
56- self.script._mergePOTMsgSets(self.templates)
57- self.script._mergeTranslationMessages(self.templates)
58-
59- self.assertEqual(
60- set(), self._listLoadedObjects(POMsgID, msgids_before))
61-
62- def test_merging_loads_no_potranslations(self):
63- # Migration does not load actual POTranslations into memory.
64- self._flushDbObjects()
65- potranslations_before = self._listLoadedObjects(POTranslation)
66-
67- self._makeTranslationMessages('x', 'y', trunk_diverged=True)
68- self._makeTranslationMessages('1', '2', stable_diverged=True)
69-
70- self._resetReferences()
71- self.assertNotEqual([], self.templates)
72- self.assertEqual(
73- set(),
74- self._listLoadedObjects(POTranslation, potranslations_before))
75-
76- self.script._mergePOTMsgSets(self.templates)
77-
78- self.assertEqual(
79- set(),
80- self._listLoadedObjects(POTranslation, potranslations_before))
81-
82- self.script._mergeTranslationMessages(self.templates)
83-
84- self.assertEqual(
85- set(),
86- self._listLoadedObjects(POTranslation, potranslations_before))
87+ def assertNoStatementsInvolvingTable(self, table_name, statements):
88+ """The specified table name is not in any of the statements."""
89+ table_name = table_name.upper()
90+ self.assertFalse(
91+ any([table_name in statement.upper()
92+ for statement in statements]))
93+
94+ def test_merging_loads_no_msgids_or_potranslations(self):
95+ # Migration does not touch the POMsgID or POTranslation tables.
96+ self._makeTranslationMessages('x', 'y', trunk_diverged=True)
97+ self._makeTranslationMessages('1', '2', stable_diverged=True)
98+ self._resetReferences()
99+ self.assertNotEqual([], self.templates)
100+
101+ _ignored, statements = record_statements(
102+ self.script._mergePOTMsgSets, self.templates)
103+ self.assertNoStatementsInvolvingTable(POMsgID._table, statements)
104+ self.assertNoStatementsInvolvingTable(
105+ POTranslation._table, statements)
106+
107+ _ignored, statements = record_statements(
108+ self.script._mergeTranslationMessages, self.templates)
109+ self.assertNoStatementsInvolvingTable(POMsgID._table, statements)
110+ self.assertNoStatementsInvolvingTable(
111+ POTranslation._table, statements)
112
113
114 def test_suite():