def testSearchpath(self): # This get_searchpath test is brittle; it'll break if libpnd changes # its default behaviour, even though this won't cause problems. self.assertItemsEqual(options.get_searchpath(), ['/media/*/pandora/apps','/media/*/pandora/desktop', '/media/*/pandora/menu','/usr/pandora/apps', '/media/*/<1>', '/media/*/pandora/mmenu','/usr/pandora/mmenu'], """This failure could indicate a change in the behaviour of libpnd, rather than a failure in the Python wrapper. Check that.""" ) with open(options.get_cfg(), 'w') as cfg: cfg.write( """{ "repositories": [ "file://firsturl" ], "locales": ["default"], "searchpath": [ "/lolbuts", "/home/places/things/stuff/" ] }""") self.assertItemsEqual(options.get_searchpath(), ['/lolbuts', '/home/places/things/stuff/'] )
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 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 setUp(self): options.working_dir = 'temp' reload(database_update) # To trigger base table creation. #Create some local repository files for testing. repo_files = ('temp/first.json', 'temp/second.json') with open(options.get_cfg(),'w') as cfg: cfg.write(self.cfg_text % tuple(map(os.path.abspath, repo_files))) for i in repo_files: with open(i,'w') as repo: repo.write(self.repotxt % ( os.path.basename(i).replace('.',' '), repo_version))
def testRepositories(self): with open(options.get_cfg(), 'w') as cfg: cfg.write( """{ "repositories": [ "file://firsturl", "http://secondurl", "ftp://thirdurl", "http://fourthurl" ], "locales": ["default"], "searchpath": ["default"] }""") self.assertEqual(options.get_repos(), ['file://firsturl', 'http://secondurl','ftp://thirdurl','http://fourthurl'])
def testLocale(self): # Should return list in desired order, always ending with en_US. # If no list is specified, should return (system lang, en_US). # If system has no default locale, it shouldn't appear in the list. l = locale.getdefaultlocale()[0] if l: locs = [l, 'en_US'] else: locs = ['en_US'] self.assertEquals(options.get_locale(), locs) with open(options.get_cfg(), 'w') as cfg: cfg.write( """{ "repositories": [ "file://firsturl" ], "locales": [ "en_CA", "de_DE" ], "searchpath": ["default"] }""") self.assertEquals(options.get_locale(), ['en_CA','de_DE','en_US'])
def testCopyCfg(self): options.get_cfg() self.assertEqual(options.get_cfg(), os.path.abspath('temp/pndstore.cfg')) self.assertTrue(os.path.isfile(options.get_cfg()))