Commit da1347096c125a6234371587f73eba45e9098266
1 parent
c6a519ea
Exists in
master
and in
1 other branch
Updated PopconXapianIndex and its tests to deal with new index_mode option. Chan…
…ges on tests avoid using xapian.Database.close() which is is not available in old versions of the lib.
Showing
2 changed files
with
13 additions
and
25 deletions
Show diff stats
src/data.py
... | ... | @@ -129,13 +129,14 @@ class PopconXapianIndex(xapian.WritableDatabase): |
129 | 129 | """ |
130 | 130 | self.axi = xapian.Database(cfg.axi) |
131 | 131 | self.path = os.path.expanduser(cfg.popcon_index) |
132 | - if reindex or not self.load_index(): | |
132 | + self.source_dir = cfg.popcon_dir | |
133 | + if cfg.index_mode.startswith("1") or not self.load_index(): | |
133 | 134 | if not os.path.exists(cfg.popcon_dir): |
134 | 135 | os.makedirs(cfg.popcon_dir) |
135 | 136 | if not os.listdir(cfg.popcon_dir): |
136 | 137 | logging.critical("Popcon dir seems to be empty.") |
137 | 138 | raise Error |
138 | - if not cfg.clustering: | |
139 | + if cfg.index_mode == "10": | |
139 | 140 | self.source_dir = os.path.expanduser(cfg.popcon_dir) |
140 | 141 | else: |
141 | 142 | self.source_dir = os.path.expanduser(cfg.clusters_dir) | ... | ... |
src/tests/data_tests.py
... | ... | @@ -56,41 +56,28 @@ class PopconXapianIndexTests(unittest2.TestCase): |
56 | 56 | self.cfg.popcon_index = "test_data/.sample_pxi" |
57 | 57 | self.cfg.popcon_dir = "test_data/popcon_dir" |
58 | 58 | self.cfg.clusters_dir = "test_data/clusters_dir" |
59 | + # build old index for all tests | |
59 | 60 | shutil.rmtree(self.cfg.popcon_index,1) |
60 | 61 | self.assertFalse(os.path.exists(self.cfg.popcon_index)) |
61 | - | |
62 | - def test_build_load(self): | |
63 | - # try to load, but index does not exist | |
62 | + # local variable, index will be closed before test | |
64 | 63 | pxi = PopconXapianIndex(self.cfg) |
65 | 64 | self.assertEqual(pxi.get_metadata("old"),"") |
66 | 65 | pxi.set_metadata("old","true") |
67 | - pxi.close() | |
66 | + | |
67 | + def test_load(self): | |
68 | 68 | # load the previously built index |
69 | - new_pxi = PopconXapianIndex(self.cfg) | |
70 | - self.assertEqual(new_pxi.get_metadata("old"),"true") | |
69 | + pxi = PopconXapianIndex(self.cfg) | |
70 | + self.assertEqual(pxi.get_metadata("old"),"true") | |
71 | 71 | |
72 | 72 | def test_reindex(self): |
73 | + # force reindex with no clustering | |
74 | + self.cfg.index_mode = "10" | |
73 | 75 | pxi = PopconXapianIndex(self.cfg) |
74 | 76 | self.assertEqual(pxi.get_metadata("old"),"") |
75 | - pxi.set_metadata("old","true") | |
76 | - pxi.close() | |
77 | - # force reindex | |
78 | - reindex = 1 | |
79 | - new_pxi = PopconXapianIndex(self.cfg,reindex,0) | |
80 | - self.assertEqual(new_pxi.get_metadata("old"),"") | |
81 | - | |
82 | - def test_no_clustering(self): | |
83 | - self.cfg.clustering = 0 | |
84 | - pxi = PopconXapianIndex(self.cfg) | |
85 | - self.assertEqual(pxi.source_dir,self.cfg.popcon_dir) | |
86 | - all_submissions = [submissions for (root, dirs, submissions) in | |
87 | - os.walk(pxi.source_dir)] | |
88 | - self.assertEqual(pxi.get_doccount(), | |
89 | - sum([len(submissions) for submissions in | |
90 | - all_submissions])) | |
91 | 77 | |
92 | 78 | def test_clustering(self): |
93 | - self.cfg.clustering = 1 | |
79 | + # force reindex with clustering | |
80 | + self.cfg.index_mode = "11" | |
94 | 81 | pxi = PopconXapianIndex(self.cfg) |
95 | 82 | self.assertEqual(pxi.source_dir,self.cfg.clusters_dir) |
96 | 83 | all_submissions = [submissions for (root, dirs, submissions) in | ... | ... |