Merge lp:~mvo/software-center/unity-lens-plus-wildcard-fix into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3124
Proposed branch: lp:~mvo/software-center/unity-lens-plus-wildcard-fix
Merge into: lp:software-center
Diff against target: 454 lines (+155/-45)
13 files modified
apt_xapian_index_plugin/software_center.py (+6/-1)
data/software-center.menu.in (+20/-6)
setup.py (+4/-4)
softwarecenter/db/categories.py (+4/-2)
softwarecenter/db/database.py (+2/-0)
softwarecenter/db/update.py (+5/-5)
softwarecenter/enums.py (+4/-4)
softwarecenter/ui/gtk3/panes/availablepane.py (+9/-0)
softwarecenter/utils.py (+2/-3)
softwarecenter/version.py (+2/-2)
tests/test_database.py (+57/-17)
tests/test_xapian.py (+28/-1)
tests/utils.py (+12/-0)
To merge this branch: bzr merge lp:~mvo/software-center/unity-lens-plus-wildcard-fix
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+120152@code.launchpad.net

Description of the change

This branch adds a "Dash Search Plugins" subcategory to Tweaks&Themes.
It also adds a workaround for a bug that the xapian query parser will
not work if there is a "-" in the query term

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Hi Michael, and thanks for doing this work. So, I can see the "Dash Search Plugins" subcategory in the Tweaks&Themes section, and it shows two lenses - the AskUbuntu lens and a Wikipedia lens. However, if I search all categories for the string "unity-lens-" I can actually see quite a few more lenses that are hidden in the technical items. I'm not quite sure how we want to fix this, or even if it is a problem. It seems, however, that we'll want all of the lenses to appear in the subcategory. Please let me know what you think.

Also, could you please describe just a little more detail about the Xapian workaround you added? Is there a bug for this issue by chance? Maybe you could provide a test case to demonstrate how the error is manifested?

Finally, I am getting an error in the new unit test that you added to test_xapian.py. It seems I'm not getting any results back for the query. Possibly it's something simple on my end. Please let me know. Here's the error:

PYTHONPATH=. python tests/test_xapian.py
F......No handlers could be found for logger "softwarecenter.distro.ubuntu"
.
======================================================================
FAIL: test_wildcard_bug1025579_workaround (__main__.AptXapianIndexTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_xapian.py", line 126, in test_wildcard_bug1025579_workaround
    self.assertNotEqual(len(mset), 0)
AssertionError: 0 == 0

----------------------------------------------------------------------
Ran 8 tests in 0.097s

FAILED (failures=1)

Many thanks!

Revision history for this message
Gary Lasker (gary-lasker) wrote :

This code looks good and I'll set it as approved so as not to block it. We can tweak if needed/as needed in future branches, and this gets us the feature which is excellent. Michael, please just take a look at the unit test issue. I'm sure it's passing on your machine so I'm probably just missing something on my end.

Thanks again for this! It's great to have this for FF.

review: Approve
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks for the review Gary. Its probably failing for you because you are not using the current quantal version of apt-xapian-index that I uploaded to fix the same problem in there too (that "-" is special). I will add a test skip decorator probably that tests for the version of a-x-i.

3109. By Michael Vogt

tests/test_xapian.py: skip test for wildcard bug1026679 as the fix was added in quantals apt-xapian-index only

3110. By Michael Vogt

update db schema because we have the new APM key and add test for ensuring that the APM values are setup correclty

3111. By Michael Vogt

use xapian.inmemory_open() for DB tests that do not need to be persistent

3112. By Michael Vogt

add explicit testcase for the xapian query parser "-" workaround/bug

3113. By Michael Vogt

tests/test_database.py: reference the upstream xapian ticket

3114. By Michael Vogt

apt_xapian_index_plugin/software_center.py: include package name terms in a-x-i plugin too

3115. By Michael Vogt

make sure category flags are applied for subcategories as well

3116. By Michael Vogt

data/software-center.menu.in: add nonapps-visible flag to unity-lens

Revision history for this message
Michael Vogt (mvo) wrote :

On Sat, Aug 18, 2012 at 06:39:17AM -0000, Gary Lasker wrote:
> Hi Michael, and thanks for doing this work. So, I can see the "Dash Search Plugins" subcategory in the Tweaks&Themes section, and it shows two lenses - the AskUbuntu lens and a Wikipedia lens. However, if I search all categories for the string "unity-lens-" I can actually see quite a few more lenses that are hidden in the technical items. I'm not quite sure how we want to fix this, or even if it is a problem. It seems, however, that we'll want all of the lenses to appear in the subcategory. Please let me know what you think.

Thanks for the review. There was a flag missing to always make the
nonapps visible. There was also a bug in the subcategory part of the
available pane that prevented the flag from getting used. This should
all be fixed now.

> Also, could you please describe just a little more detail about the Xapian workaround you added? Is there a bug for this issue by chance? Maybe you could provide a test case to demonstrate how the error is manifested?

I added a TestCase for tihs now, it includes a link to the quoting
problem of the xapian query parser (http://trac.xapian.org/ticket/128)

> Finally, I am getting an error in the new unit test that you added to test_xapian.py. It seems I'm not getting any results back for the query. Possibly it's something simple on my end. Please let me know. Here's the error:
[..]

This seems to be caused by running on precise, I exclude this test
now if precise is used, there is no "XPM" term in the xapian db on
precise.

Cheers and enjoy your vacation.

Cheers,
 Michael

3117. By Michael Vogt

pep8 fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'apt_xapian_index_plugin/software_center.py'
--- apt_xapian_index_plugin/software_center.py 2012-07-02 09:51:31 +0000
+++ apt_xapian_index_plugin/software_center.py 2012-08-21 13:19:20 +0000
@@ -10,7 +10,10 @@
10 CustomKeys,10 CustomKeys,
11 XapianValues,11 XapianValues,
12 )12 )
13from softwarecenter.db.update import WEIGHT_DESKTOP_NAME13from softwarecenter.db.update import (
14 WEIGHT_DESKTOP_NAME,
15 get_pkgname_terms,
16 )
14from softwarecenter.distro import get_distro17from softwarecenter.distro import get_distro
1518
1619
@@ -104,6 +107,8 @@
104 # add s-c values/terms for the name107 # add s-c values/terms for the name
105 document.add_term("AA"+name)108 document.add_term("AA"+name)
106 document.add_value(XapianValues.APPNAME, name)109 document.add_value(XapianValues.APPNAME, name)
110 for t in get_pkgname_terms(pkg.name):
111 document.add_term(t)
107 self.indexer.index_text_without_positions(112 self.indexer.index_text_without_positions(
108 name, WEIGHT_DESKTOP_NAME)113 name, WEIGHT_DESKTOP_NAME)
109 # we pretend to be an application114 # we pretend to be an application
110115
=== modified file 'data/software-center.menu.in'
--- data/software-center.menu.in 2012-05-15 02:39:12 +0000
+++ data/software-center.menu.in 2012-08-21 13:19:20 +0000
@@ -332,16 +332,13 @@
332 <Include>332 <Include>
333 <And>333 <And>
334 <Or>334 <Or>
335 <SCPkgnameWildcard>ttf*</SCPkgnameWildcard>335 <SCPkgnameWildcard>ttf-*</SCPkgnameWildcard>
336 <SCPkgnameWildcard>otf*</SCPkgnameWildcard>336 <SCPkgnameWildcard>otf-*</SCPkgnameWildcard>
337 <SCSection>fonts</SCSection>337 <SCSection>fonts</SCSection>
338 <SCSection>restricted/fonts</SCSection>338 <SCSection>restricted/fonts</SCSection>
339 <SCSection>universe/fonts</SCSection>339 <SCSection>universe/fonts</SCSection>
340 <SCSection>multiverse/fonts</SCSection>340 <SCSection>multiverse/fonts</SCSection>
341 </Or>341 </Or>
342 <Not>
343 <SCPkgname>ttfm</SCPkgname>
344 </Not>
345 </And>342 </And>
346 </Include>343 </Include>
347 </Menu>344 </Menu>
@@ -528,7 +525,24 @@
528 <Menu>525 <Menu>
529 <_Name>Themes &amp; Tweaks</_Name>526 <_Name>Themes &amp; Tweaks</_Name>
530 <SCIcon>preferences-other</SCIcon>527 <SCIcon>preferences-other</SCIcon>
531 <Include><Category>Settings</Category></Include>528 <Include>
529 <Category>Settings</Category>
530 </Include>
531
532 <!-- Sub-categories for the Themes -->
533 <Menu>
534 <_Name>Dash Search Plugins</_Name>
535 <Flags>
536 <Flag>nonapps-visible</Flag>
537 </Flags>
538 <SCIcon>preferences-other</SCIcon>
539 <Include>
540 <And>
541 <SCPkgnameWildcard>unity-lens-*</SCPkgnameWildcard>
542 </And>
543 </Include>
544 </Menu>
545
532 </Menu>546 </Menu>
533547
534 <!-- System -->548 <!-- System -->
535549
=== modified file 'setup.py'
--- setup.py 2012-07-23 11:48:24 +0000
+++ setup.py 2012-08-21 13:19:20 +0000
@@ -69,10 +69,10 @@
69DISTRO = platform.dist()[0]69DISTRO = platform.dist()[0]
70RELEASE = platform.dist()[1]70RELEASE = platform.dist()[1]
71open("softwarecenter/version.py", "w").write("""71open("softwarecenter/version.py", "w").write("""
72VERSION='%s'72VERSION = '%s'
73CODENAME='%s'73CODENAME = '%s'
74DISTRO='%s'74DISTRO = '%s'
75RELEASE='%s'75RELEASE = '%s'
76""" % (VERSION, CODENAME, DISTRO, RELEASE))76""" % (VERSION, CODENAME, DISTRO, RELEASE))
7777
7878
7979
=== modified file 'softwarecenter/db/categories.py'
--- softwarecenter/db/categories.py 2012-08-17 07:46:59 +0000
+++ softwarecenter/db/categories.py 2012-08-21 13:19:20 +0000
@@ -399,8 +399,10 @@
399 query = xapian.Query(xapian_op, query, q)399 query = xapian.Query(xapian_op, query, q)
400 elif operator_elem.tag == "SCPkgnameWildcard":400 elif operator_elem.tag == "SCPkgnameWildcard":
401 LOG.debug("adding tag: %s" % operator_elem.text)401 LOG.debug("adding tag: %s" % operator_elem.text)
402 # query both axi and s-c402 # query both axi and s-c and ensure that the pkgname is
403 s = "pkg_wildcard:%s" % qtext403 # mangled to workaround xapians query parser lack of
404 # quoting :/
405 s = "pkg_wildcard:%s" % qtext.replace("-", "_")
404 q = self.db.xapian_parser.parse_query(s,406 q = self.db.xapian_parser.parse_query(s,
405 xapian.QueryParser.FLAG_WILDCARD)407 xapian.QueryParser.FLAG_WILDCARD)
406 query = xapian.Query(xapian_op, query, q)408 query = xapian.Query(xapian_op, query, q)
407409
=== modified file 'softwarecenter/db/database.py'
--- softwarecenter/db/database.py 2012-08-14 14:45:47 +0000
+++ softwarecenter/db/database.py 2012-08-21 13:19:20 +0000
@@ -204,7 +204,9 @@
204 xapian_parser.add_boolean_prefix("section", "XS")204 xapian_parser.add_boolean_prefix("section", "XS")
205 xapian_parser.add_boolean_prefix("origin", "XOC")205 xapian_parser.add_boolean_prefix("origin", "XOC")
206 xapian_parser.add_prefix("pkg_wildcard", "XP")206 xapian_parser.add_prefix("pkg_wildcard", "XP")
207 xapian_parser.add_prefix("pkg_wildcard", "XPM")
207 xapian_parser.add_prefix("pkg_wildcard", "AP")208 xapian_parser.add_prefix("pkg_wildcard", "AP")
209 xapian_parser.add_prefix("pkg_wildcard", "APM")
208 xapian_parser.set_default_op(xapian.Query.OP_AND)210 xapian_parser.set_default_op(xapian.Query.OP_AND)
209 return xapian_parser211 return xapian_parser
210212
211213
=== modified file 'softwarecenter/db/update.py'
--- softwarecenter/db/update.py 2012-08-01 04:37:06 +0000
+++ softwarecenter/db/update.py 2012-08-21 13:19:20 +0000
@@ -118,10 +118,10 @@
118118
119119
120def get_pkgname_terms(pkgname):120def get_pkgname_terms(pkgname):
121 result = ["AP" + pkgname]121 result = ["AP" + pkgname,
122 if '-' in pkgname:122 # workaround xapian oddness by providing a "mangled" version
123 # we need this to work around xapian oddness123 # with a different prefix
124 result.append(pkgname.replace('-', '_'))124 "APM" + pkgname.replace('-', '_')]
125 return result125 return result
126126
127127
@@ -239,7 +239,7 @@
239 doc_key = self.FIELD_TO_XAPIAN[key]239 doc_key = self.FIELD_TO_XAPIAN[key]
240 doc.add_value(doc_key, value)240 doc.add_value(doc_key, value)
241 # add terms to the xapian database241 # add terms to the xapian database
242 get_terms = self.FIELD_TO_TERMS.get(key, lambda i: i)242 get_terms = self.FIELD_TO_TERMS.get(key, lambda i: [])
243 for t in get_terms(value):243 for t in get_terms(value):
244 doc.add_term(t)244 doc.add_term(t)
245245
246246
=== modified file 'softwarecenter/enums.py'
--- softwarecenter/enums.py 2012-08-01 04:26:27 +0000
+++ softwarecenter/enums.py 2012-08-21 13:19:20 +0000
@@ -61,7 +61,7 @@
6161
62# version of the database, every time something gets added (like62# version of the database, every time something gets added (like
63# terms for mime-type) increase this (but keep as a string!)63# terms for mime-type) increase this (but keep as a string!)
64DB_SCHEMA_VERSION = "6"64DB_SCHEMA_VERSION = "7"
6565
66# the default limit for a search66# the default limit for a search
67DEFAULT_SEARCH_LIMIT = 1000067DEFAULT_SEARCH_LIMIT = 10000
@@ -253,9 +253,9 @@
253253
254# visibility of non applications in the search results254# visibility of non applications in the search results
255class NonAppVisibility:255class NonAppVisibility:
256 (ALWAYS_VISIBLE,256 ALWAYS_VISIBLE = "non-apps-always-visible"
257 MAYBE_VISIBLE,257 MAYBE_VISIBLE = "non-apps-maybe-visible"
258 NEVER_VISIBLE) = range(3)258 NEVER_VISIBLE = "non-apps-never-visible"
259259
260260
261# application actions261# application actions
262262
=== modified file 'softwarecenter/ui/gtk3/panes/availablepane.py'
--- softwarecenter/ui/gtk3/panes/availablepane.py 2012-07-19 09:37:04 +0000
+++ softwarecenter/ui/gtk3/panes/availablepane.py 2012-08-21 13:19:20 +0000
@@ -696,7 +696,9 @@
696696
697 def display_app_view_page(self, view_state):697 def display_app_view_page(self, view_state):
698 category = view_state.category698 category = view_state.category
699 subcategory = view_state.subcategory
699 self.set_category(category)700 self.set_category(category)
701 self.set_subcategory(subcategory)
700702
701 result = self.display_list_page(view_state)703 result = self.display_list_page(view_state)
702704
@@ -790,10 +792,17 @@
790 current_page = self.notebook.get_current_page()792 current_page = self.notebook.get_current_page()
791 return current_page == self.Pages.PURCHASE793 return current_page == self.Pages.PURCHASE
792794
795 def set_subcategory(self, subcategory):
796 LOG.debug('set_subcategory: %s' % subcategory)
797 self.state.subcategory = subcategory
798 self._apply_filters_for_category_or_subcategory(subcategory)
799
793 def set_category(self, category):800 def set_category(self, category):
794 LOG.debug('set_category: %s' % category)801 LOG.debug('set_category: %s' % category)
795 self.state.category = category802 self.state.category = category
803 self._apply_filters_for_category_or_subcategory(category)
796804
805 def _apply_filters_for_category_or_subcategory(self, category):
797 # apply flags806 # apply flags
798 if category:807 if category:
799 if 'nonapps-visible' in category.flags:808 if 'nonapps-visible' in category.flags:
800809
=== modified file 'softwarecenter/utils.py'
--- softwarecenter/utils.py 2012-08-16 14:44:29 +0000
+++ softwarecenter/utils.py 2012-08-21 13:19:20 +0000
@@ -663,9 +663,8 @@
663 # set new global datadir663 # set new global datadir
664 softwarecenter.paths.datadir = datadir664 softwarecenter.paths.datadir = datadir
665 # also alter the app-install path665 # also alter the app-install path
666 path = "%s/desktop/software-center.menu" % \666 path = "./build/share/app-install/desktop/software-center.menu"
667 softwarecenter.paths.APP_INSTALL_PATH667 if os.path.exists(path):
668 if not os.path.exists(path):
669 softwarecenter.paths.APP_INSTALL_PATH = './build/share/app-install'668 softwarecenter.paths.APP_INSTALL_PATH = './build/share/app-install'
670 logging.warn("using local APP_INSTALL_PATH: %s" %669 logging.warn("using local APP_INSTALL_PATH: %s" %
671 softwarecenter.paths.APP_INSTALL_PATH)670 softwarecenter.paths.APP_INSTALL_PATH)
672671
=== modified file 'softwarecenter/version.py'
--- softwarecenter/version.py 2012-08-01 04:37:06 +0000
+++ softwarecenter/version.py 2012-08-21 13:19:20 +0000
@@ -1,5 +1,5 @@
11
2VERSION = '5.3.3.1'2VERSION = '5.3.7'
3CODENAME = 'quantal'3CODENAME = 'UNRELEASED'
4DISTRO = 'Ubuntu'4DISTRO = 'Ubuntu'
5RELEASE = '12.10'5RELEASE = '12.10'
66
=== modified file 'tests/test_database.py'
--- tests/test_database.py 2012-08-15 12:11:14 +0000
+++ tests/test_database.py 2012-08-21 13:19:20 +0000
@@ -13,6 +13,7 @@
13from tests.utils import (13from tests.utils import (
14 DATA_DIR,14 DATA_DIR,
15 get_test_db,15 get_test_db,
16 get_test_db_from_app_install_data,
16 get_test_pkg_info,17 get_test_pkg_info,
17 do_events,18 do_events,
18 make_software_center_agent_subscription_dict,19 make_software_center_agent_subscription_dict,
@@ -77,24 +78,26 @@
77 self.assertEqual(res, [ v2, v1, v0 ])78 self.assertEqual(res, [ v2, v1, v0 ])
7879
7980
81 def _get_db_from_test_app_install_data(self):
82 db = xapian.inmemory_open()
83 res = update_from_app_install_data(db, self.cache,
84 datadir=os.path.join(DATA_DIR, "desktop"))
85 self.assertTrue(res)
86 self.assertEqual(db.get_doccount(), 5)
87 return db
88
80 def test_update_from_desktop_file(self):89 def test_update_from_desktop_file(self):
81 # ensure we index with german locales to test i18n90 # ensure we index with german locales to test i18n
82 os.environ["LANGUAGE"] = "de"91 os.environ["LANGUAGE"] = "de"
83 db = xapian.WritableDatabase(TEST_DB,92 datadir = os.path.join(DATA_DIR, "desktop")
84 xapian.DB_CREATE_OR_OVERWRITE)93 db = get_test_db_from_app_install_data(datadir)
85 res = update_from_app_install_data(db, self.cache,
86 datadir=os.path.join(DATA_DIR, "desktop"))
87 self.assertTrue(res)
88 self.assertEqual(db.get_doccount(), 5)
89 # test if Name[de] was picked up94 # test if Name[de] was picked up
90 i=095 i=0
91 for it in db.postlist("AAUbuntu Software Zentrum"):96 for it in db.postlist("AAUbuntu Software Zentrum"):
92 i+=197 i+=1
93 self.assertEqual(i, 1)
9498
95 def test_update_from_appstream_xml(self):99 def test_update_from_appstream_xml(self):
96 db = xapian.WritableDatabase(TEST_DB,100 db = xapian.inmemory_open()
97 xapian.DB_CREATE_OR_OVERWRITE)
98 res = update_from_appstream_xml(db, self.cache,101 res = update_from_appstream_xml(db, self.cache,
99 os.path.join(DATA_DIR, "app-info"))102 os.path.join(DATA_DIR, "app-info"))
100 self.assertTrue(res)103 self.assertTrue(res)
@@ -113,8 +116,7 @@
113 def test_update_from_var_lib_apt_lists(self):116 def test_update_from_var_lib_apt_lists(self):
114 # ensure we index with german locales to test i18n117 # ensure we index with german locales to test i18n
115 os.environ["LANGUAGE"] = "de"118 os.environ["LANGUAGE"] = "de"
116 db = xapian.WritableDatabase(TEST_DB,119 db = xapian.inmemory_open()
117 xapian.DB_CREATE_OR_OVERWRITE)
118 res = update_from_var_lib_apt_lists(db, self.cache,120 res = update_from_var_lib_apt_lists(db, self.cache,
119 listsdir=os.path.join(DATA_DIR, "app-info"))121 listsdir=os.path.join(DATA_DIR, "app-info"))
120 self.assertTrue(res)122 self.assertTrue(res)
@@ -137,8 +139,7 @@
137 self.assertTrue(found_gettext_translation)139 self.assertTrue(found_gettext_translation)
138140
139 def test_update_from_json_string(self):141 def test_update_from_json_string(self):
140 db = xapian.WritableDatabase(TEST_DB,142 db = xapian.inmemory_open()
141 xapian.DB_CREATE_OR_OVERWRITE)
142 cache = apt.Cache()143 cache = apt.Cache()
143 p = os.path.join(DATA_DIR, "app-info-json", "apps.json")144 p = os.path.join(DATA_DIR, "app-info-json", "apps.json")
144 res = update_from_json_string(db, cache, open(p).read(), origin=p)145 res = update_from_json_string(db, cache, open(p).read(), origin=p)
@@ -146,8 +147,7 @@
146 self.assertEqual(db.get_doccount(), 1)147 self.assertEqual(db.get_doccount(), 1)
147148
148 def test_build_from_software_center_agent(self):149 def test_build_from_software_center_agent(self):
149 db = xapian.WritableDatabase(TEST_DB,150 db = xapian.inmemory_open()
150 xapian.DB_CREATE_OR_OVERWRITE)
151 cache = apt.Cache()151 cache = apt.Cache()
152 # monkey patch distro to ensure we get data152 # monkey patch distro to ensure we get data
153 distro = softwarecenter.distro.get_distro()153 distro = softwarecenter.distro.get_distro()
@@ -343,8 +343,7 @@
343 # staging does not have a valid cert343 # staging does not have a valid cert
344 os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"344 os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
345 cache = get_test_pkg_info()345 cache = get_test_pkg_info()
346 db = xapian.WritableDatabase(TEST_DB,346 db = xapian.inmemory_open()
347 xapian.DB_CREATE_OR_OVERWRITE)
348 res = update_from_software_center_agent(db, cache, ignore_cache=True)347 res = update_from_software_center_agent(db, cache, ignore_cache=True)
349 self.assertTrue(res)348 self.assertTrue(res)
350349
@@ -702,6 +701,47 @@
702 self.assertEqual(app.archive_suite, "")701 self.assertEqual(app.archive_suite, "")
703702
704703
704class XapianQueryParserWorkarounds(unittest.TestCase):
705 """This TestCase demonstrates the issues around the query
706 parser wildcard support if the "-" char is part of the
707 pkgname and tests the workaround for this
708
709 (http://trac.xapian.org/ticket/128)
710 """
711
712 def setUp(self):
713 datadir = os.path.join(DATA_DIR, "desktop")
714 self.db = get_test_db_from_app_install_data(datadir)
715
716 def test_name_mangling_for_query_parser(self):
717 # test that pkgnames with "-" get added in a mangled form
718 i=0
719 for it in self.db.postlist("APMsoftware_center"):
720 i+=1
721 self.assertEqual(i, 1)
722
723 def test_query_parser_wildcard(self):
724 enquire = xapian.Enquire(self.db)
725 parser = xapian.QueryParser()
726 parser.set_database(self.db)
727 parser.add_prefix("pkg_wildcard", "AP")
728 # this demonstrates the xapian bug with the query parser
729 # and "-" special chars, note that once this test fails (i.e.
730 # the returned mset is "1" we can remove this workaround
731 query = parser.parse_query(
732 "pkg_wildcard:software-*", xapian.QueryParser.FLAG_WILDCARD)
733 enquire.set_query(query)
734 mset = enquire.get_mset(0, 100)
735 self.assertEqual(len(mset), 0)
736 # and the workaround
737 parser.add_prefix("pkg_wildcard", "APM")
738 query = parser.parse_query(
739 "pkg_wildcard:software_*", xapian.QueryParser.FLAG_WILDCARD)
740 enquire.set_query(query)
741 mset = enquire.get_mset(0, 100)
742 self.assertEqual(len(mset), 1)
743
744
705class TrackDBTestCase(unittest.TestCase):745class TrackDBTestCase(unittest.TestCase):
706746
707 def test_track_db_open(self):747 def test_track_db_open(self):
708748
=== modified file 'tests/test_xapian.py'
--- tests/test_xapian.py 2012-07-02 09:51:31 +0000
+++ tests/test_xapian.py 2012-08-21 13:19:20 +0000
@@ -1,5 +1,6 @@
1import os
2import platform
1import unittest3import unittest
2import os
3import xapian4import xapian
45
5from mock import Mock, patch6from mock import Mock, patch
@@ -103,6 +104,31 @@
103 #print len(matches)104 #print len(matches)
104 self.assertTrue(len(matches) > 0)105 self.assertTrue(len(matches) > 0)
105106
107
108class AptXapianIndexTestCase(unittest.TestCase):
109
110 # this will fail on precise so we skip the test there
111 @unittest.skipIf(platform.dist()[2] == "precise" and
112 not os.path.exists("/var/lib/apt-xapian-index/index"),
113 "Need populated apt-xapian-index for this test")
114 def test_wildcard_bug1025579_workaround(self):
115 db = xapian.Database("/var/lib/apt-xapian-index/index")
116 enquire = xapian.Enquire(db)
117 parser = xapian.QueryParser()
118 parser.set_database(db)
119 # this is the gist, the mangled version of the XPM term
120 parser.add_prefix("pkg_wildcard", "XPM")
121 parser.add_prefix("pkg_wildcard", "XP")
122 parser.add_prefix("pkg_wildcard", "AP")
123 s = 'pkg_wildcard:unity_lens_*'
124 query = parser.parse_query(s, xapian.QueryParser.FLAG_WILDCARD)
125 enquire.set_query(query)
126 mset = enquire.get_mset(0, 100)
127 for m in mset:
128 self.assertTrue(m.document.get_data().startswith("unity-lens-"))
129 self.assertNotEqual(len(mset), 0)
130
131
106class XapianPluginsTestCase(unittest.TestCase):132class XapianPluginsTestCase(unittest.TestCase):
107133
108 def make_mock_document(self):134 def make_mock_document(self):
@@ -146,5 +172,6 @@
146 got_values.add(args[0])172 got_values.add(args[0])
147 self.assertTrue(expected_values.issubset(got_values))173 self.assertTrue(expected_values.issubset(got_values))
148174
175
149if __name__ == "__main__":176if __name__ == "__main__":
150 unittest.main()177 unittest.main()
151178
=== modified file 'tests/utils.py'
--- tests/utils.py 2012-05-31 12:50:01 +0000
+++ tests/utils.py 2012-08-21 13:19:20 +0000
@@ -44,6 +44,8 @@
44)44)
45from softwarecenter.ui.gtk3.utils import get_sc_icon_theme45from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
46from softwarecenter.utils import get_uuid46from softwarecenter.utils import get_uuid
47from softwarecenter.db.update import update_from_app_install_data
48
4749
48m_dbus = m_polkit = m_aptd = None50m_dbus = m_polkit = m_aptd = None
4951
@@ -107,6 +109,16 @@
107 return db109 return db
108110
109111
112def get_test_db_from_app_install_data(datadir):
113 db = xapian.inmemory_open()
114 cache = get_pkg_info()
115 cache.open()
116 res = update_from_app_install_data(db, cache, datadir)
117 if res is False:
118 raise AssertionError("Failed to build db from '%s'" % datadir)
119 return db
120
121
110def get_test_install_backend():122def get_test_install_backend():
111 backend = get_install_backend()123 backend = get_install_backend()
112 return backend124 return backend

Subscribers

People subscribed via source and target branches