def testBatch(self): scrubber = java_scrubber.EmptyJavaFileScrubber(base.ACTION_DELETE) empty_file = test_util.FakeFile('', 'EmptyFile.java') nonempty_file = test_util.FakeFile('public class Foo {}', 'Foo.java') fake_context = FakeContext() scrubber.BatchScrubFiles([empty_file, nonempty_file], fake_context) self.assert_(empty_file.deleted, 'ScrubFile did not delete empty file') self.assert_(not nonempty_file.deleted, 'ScrubFile deleted non-empty file')
def _ResetBatchScrubbers(self): """Set batch scrubbers to run before and after by-file scrubbing. See ScrubberContext.Scan below. First, the pre-batch scrubbers are run for applicable files, then by-file scrubbers, then post-batch scrubbers. ("Pre-batch" and "post-batch" are misnomers, but used for simplicity. Respectively, they're really "pre-(by-file)" and "post-(by-file)".) """ c_like_comment_pre_batch_scrubbers = [ comment_scrubber.CommentScrubber( comment_scrubber.CLikeCommentExtractor(), self._CommentScrubbers()) ] java_pre_batch_scrubbers = [] java_pre_batch_scrubbers.extend(c_like_comment_pre_batch_scrubbers) proto_pre_batch_scrubbers = (self.scrub_proto_comments and c_like_comment_pre_batch_scrubbers or []) self.extension_to_pre_batch_scrubbers_map = { '.c': c_like_comment_pre_batch_scrubbers, '.cc': c_like_comment_pre_batch_scrubbers, '.go': c_like_comment_pre_batch_scrubbers, '.h': c_like_comment_pre_batch_scrubbers, '.java': java_pre_batch_scrubbers, '.jj': java_pre_batch_scrubbers, '.js': c_like_comment_pre_batch_scrubbers, '.jslib': c_like_comment_pre_batch_scrubbers, '.l': c_like_comment_pre_batch_scrubbers, '.php': c_like_comment_pre_batch_scrubbers, '.php4': c_like_comment_pre_batch_scrubbers, '.php5': c_like_comment_pre_batch_scrubbers, '.proto': proto_pre_batch_scrubbers, '.protodevel': proto_pre_batch_scrubbers, '.swig': c_like_comment_pre_batch_scrubbers, } java_post_batch_scrubbers = [] if self.empty_java_file_action != base.ACTION_IGNORE: java_post_batch_scrubbers.append( java_scrubber.EmptyJavaFileScrubber( self.empty_java_file_action)) self.extension_to_post_batch_scrubbers_map = { '.java': java_post_batch_scrubbers, '.jj': java_post_batch_scrubbers, }
def testRaises(self): scrubber = java_scrubber.EmptyJavaFileScrubber(base.ACTION_IGNORE) fake_file = test_util.FakeFile('', 'EmptyFile.java') fake_context = FakeContext() self.assertRaises(base.Error, scrubber.BatchScrubFiles, [fake_file], fake_context)
def testDelete(self): scrubber = java_scrubber.EmptyJavaFileScrubber(base.ACTION_DELETE) fake_file = test_util.FakeFile('', 'EmptyFile.java') fake_context = FakeContext() scrubber.BatchScrubFiles([fake_file], fake_context) self.assert_(fake_file.deleted, 'ScrubFile did not delete')
def testError(self): scrubber = java_scrubber.EmptyJavaFileScrubber(base.ACTION_ERROR) fake_file = test_util.FakeFile('') fake_context = FakeContext() scrubber.BatchScrubFiles([fake_file], fake_context) self.assert_(fake_context.error_added, 'ScrubFile did not error')
def assertNotMeaningful(self, text, filename=None): scrubber = java_scrubber.EmptyJavaFileScrubber(base.ACTION_DELETE) file_obj = test_util.FakeFile(text, filename) scrubber.BatchScrubFiles([file_obj], None) if not file_obj.deleted: self.fail('Text %s is not meaningful, but should be' % text)