def setUp(self): options.working_dir = 'temp' reload(database_update) with open(options.get_cfg(),'w') as cfg: cfg.write(self.cfg_text) database_update.update_remote() database_update.update_local()
def testBadRemote(self): with sqlite3.connect(options.get_database()) as db: c = db.cursor() #Test for a malformed JSON file. repo0 = os.path.join(options.get_working_dir(), os.path.basename(options.get_repos()[0])) with open(repo0, 'a') as r: r.write(',') self.assertRaises(ValueError, database_update.update_remote_url, options.get_repos()[0], c) # Test for incorrect version. #with open(repo0, 'w') as r: # r.write(self.repotxt % (os.path.basename(repo0), 99.7)) #self.assertRaises(database_update.RepoError, # database_update.update_remote_url, # database_update.open_repos()[0], c) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') database_update.update_remote() # Check appropriate warning is shown. self.assertEqual(len(w), 1) self.assertIn('Could not process', str(w[0].message)) # Bad repo (first) must be empty. self.assertRaises(TypeError, self._check_entries, options.get_repos()[0]) # Good repo (second) should have correct entries. self._check_entries(options.get_repos()[1]) # Make sure we don't get a TypeError warning, as was caused by issues # with last_full_update being unset after an error. with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') database_update.update_remote() self.assertEqual(len(w), 1) self.assertIn('ValueError', str(w[0].message))
def run(thread): with warnings.catch_warnings(record=True) as w: warnings.filterwarnings('always') self.statusbar.push(self.cid, 'Updating remote package list...') database_update.update_remote() self.statusbar.pop(self.cid) self.statusbar.push(self.cid, 'Updating local package list...') database_update.update_local() self.statusbar.pop(self.cid) self.update_treeview() for msg in w: self.show_error(str(msg.message))
def testMissingRemote(self): # Add extra non-existent URL to middle of config. with open(options.get_cfg()) as f: txt = f.read() new = txt.split('\n') new.insert(3, '"http://notreal.ihope",') with open(options.get_cfg(), 'w') as f: f.write('\n'.join(new)) # Make sure other two still update correctly. with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') database_update.update_remote() # Check appropriate warning is shown. self.assertEqual(len(w), 1) self.assertIn('Could not reach repo', str(w[0].message)) r = options.get_repos() self._check_entries(r[0]) self.assertRaises(TypeError, self._check_entries, r[1]) self._check_entries(r[2])
def testMissingTables(self): os.remove(options.get_database()) reload(database_update) # To trigger base table creation. database_update.update_local() # Empty index table. p = packages.Package('not-even-real') self.assertFalse(p.local.exists) self.assertItemsEqual(p.remote, []) self.assertEqual(len(packages.get_all_local()), len(packages.get_all())) # Table in index, but doesn't successfully reach it. with open(options.get_cfg()) as f: txt = f.read() new = txt.split('\n') new.insert(2, '"http://notreal.ihope",') with open(options.get_cfg(), 'w') as f: f.write('\n'.join(new)) with warnings.catch_warnings(): warnings.simplefilter('ignore') database_update.update_remote() packages.get_all()
def testUpdateRemote(self): database_update.update_remote() for r in options.get_repos(): self._check_entries(r)