def test_basic(self): db = WarningsDatabase() self.assertEqual(len(db), 0) for i in range(10): db.insert(get_warning(), compute_hash=False) self.assertEqual(len(db), 10) warnings = list(db) self.assertEqual(len(warnings), 10)
def test_basic(self): db = WarningsDatabase() self.assertEqual(len(db), 0) for i in range(10): db.insert(get_warning(), compute_hash=False) self.assertEqual(len(db), 10) warnings = list(db) self.assertEqual(len(warnings), 10)
def test_pruning(self): """Ensure old warnings are removed from database appropriately.""" db = WarningsDatabase() source_files = [] for i in range(1, 21): temp = NamedTemporaryFile(mode='wt') temp.write('x' * (100 * i)) temp.flush() # Keep reference so it doesn't get GC'd and deleted. source_files.append(temp) w = CompilerWarning() w['filename'] = temp.name w['line'] = 1 w['column'] = i * 10 w['message'] = 'irrelevant' db.insert(w) self.assertEqual(len(db), 20) # If we change a source file, inserting a new warning should nuke the # old one. source_files[0].write('extra') source_files[0].flush() w = CompilerWarning() w['filename'] = source_files[0].name w['line'] = 1 w['column'] = 50 w['message'] = 'replaced' db.insert(w) self.assertEqual(len(db), 20) warnings = list(db.warnings_for_file(source_files[0].name)) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['column'], w['column']) # If we delete the source file, calling prune should cause the warnings # to go away. old_filename = source_files[0].name del source_files[0] self.assertFalse(os.path.exists(old_filename)) db.prune() self.assertEqual(len(db), 19)
def test_pruning(self): """Ensure old warnings are removed from database appropriately.""" db = WarningsDatabase() source_files = [] for i in range(1, 21): temp = NamedTemporaryFile(mode='wt') temp.write('x' * (100 * i)) temp.flush() # Keep reference so it doesn't get GC'd and deleted. source_files.append(temp) w = CompilerWarning() w['filename'] = temp.name w['line'] = 1 w['column'] = i * 10 w['message'] = 'irrelevant' db.insert(w) self.assertEqual(len(db), 20) # If we change a source file, inserting a new warning should nuke the # old one. source_files[0].write('extra') source_files[0].flush() w = CompilerWarning() w['filename'] = source_files[0].name w['line'] = 1 w['column'] = 50 w['message'] = 'replaced' db.insert(w) self.assertEqual(len(db), 20) warnings = list(db.warnings_for_file(source_files[0].name)) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['column'], w['column']) # If we delete the source file, calling prune should cause the warnings # to go away. old_filename = source_files[0].name del source_files[0] self.assertFalse(os.path.exists(old_filename)) db.prune() self.assertEqual(len(db), 19)
def test_hashing(self): """Ensure that hashing files on insert works.""" db = WarningsDatabase() temp = NamedTemporaryFile(mode='wt') temp.write('x' * 100) temp.flush() w = CompilerWarning() w['filename'] = temp.name w['line'] = 1 w['column'] = 4 w['message'] = 'foo bar' # Should not throw. db.insert(w) w['filename'] = 'DOES_NOT_EXIST' with self.assertRaises(Exception): db.insert(w)
def test_hashing(self): """Ensure that hashing files on insert works.""" db = WarningsDatabase() temp = NamedTemporaryFile(mode='wt') temp.write('x' * 100) temp.flush() w = CompilerWarning() w['filename'] = temp.name w['line'] = 1 w['column'] = 4 w['message'] = 'foo bar' # Should not throw. db.insert(w) w['filename'] = 'DOES_NOT_EXIST' with self.assertRaises(Exception): db.insert(w)
def test_hashing(self): """Ensure that hashing files on insert works.""" db = WarningsDatabase() temp = NamedTemporaryFile(mode="wt") temp.write("x" * 100) temp.flush() w = CompilerWarning() w["filename"] = temp.name w["line"] = 1 w["column"] = 4 w["message"] = "foo bar" # Should not throw. db.insert(w) w["filename"] = "DOES_NOT_EXIST" with self.assertRaises(Exception): db.insert(w)