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 testWorkingDir(self): #Ensure the full returned path is in this test directory. self.assertEqual(options.get_working_dir()[-9:], 'test/temp')