Esempio n. 1
0
 def testFilesUntouched(self):
   fake_file = test_util.FakeFile('', 'goo.xml')
   self.scrubber.ScrubFile(fake_file, None)
   self.assertFalse(fake_file.written)
   fake_file = test_util.FakeFile('<module></module>')
   self.scrubber.ScrubFile(fake_file, None)
   self.assertFalse(fake_file.written)
Esempio n. 2
0
 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')
Esempio n. 3
0
    def assertTestSizeScrubbed(self, original, expected=None):
        if expected is None:
            expected = original

        fake_file = test_util.FakeFile(original)
        self.scrubber.ScrubFile(fake_file, None)
        self.assertMultiLineEqual(expected, fake_file.Contents())
Esempio n. 4
0
def TestCommentExtractor(test_case, extractor, source_file, expected_file):
    comments = extractor.ExtractComments(
        test_util.FakeFile(filename=source_file))
    expected_text = file_util.Read(expected_file)
    expected_json = simplejson.loads(expected_text)
    expected_comments = comment_scrubber.CommentsFromJson(expected_json)
    test_case.assertListEqual(expected_comments, comments)
Esempio n. 5
0
 def assertContentsError(self, lines):
     context = FakeContext()
     scrubber = comment_scrubber.CommentScrubber(
         comment_scrubber.CLikeCommentExtractor())
     file_obj = test_util.FakeFile(contents=u'\n'.join(lines))
     scrubber.ScrubFile(file_obj, context)
     self.assertEqual(1, len(context.errors))
     error, = context.errors
     self.assertEqual('COMMENT_SCRUBBER_ERROR', error.filter)
Esempio n. 6
0
    def assertCoalesces(self, original, expected=None, maximum_blank_lines=1):
        scrubber = java_scrubber.CoalesceBlankLinesScrubber(
            maximum_blank_lines)

        if not expected:
            expected = original

        fake_file = test_util.FakeFile(original)
        scrubber.ScrubFile(fake_file, None)
        self.assertMultiLineEqual(expected, fake_file.Contents())
Esempio n. 7
0
 def assertNotScrubbed(self,
                       text,
                       internal_package,
                       public_package,
                       filename=''):
     scrubber = java_scrubber.JavaRenameScrubber(internal_package,
                                                 public_package)
     f = test_util.FakeFile(text, filename)
     scrubber.ScrubFile(f, None)
     if f.Contents() != text:
         self.fail("Text %s was scrubbed, but shouldn't be" % text)
Esempio n. 8
0
 def RunScenario(self, scenario_name, extractor=None):
     if not extractor:
         extractor = comment_scrubber.CLikeCommentExtractor()
     scrubber = comment_scrubber.CommentScrubber(extractor)
     scenario_dir = os.path.join(TEST_DATA_DIR, 'directives', scenario_name)
     unstripped = os.path.join(scenario_dir, 'input.txt')
     file_obj = test_util.FakeFile(filename=unstripped)
     scrubber.ScrubFile(file_obj, None)
     expected = os.path.join(scenario_dir, 'expected.txt')
     out = os.path.join(FLAGS.test_tmpdir, scenario_name + '.out.txt')
     file_util.Write(out, file_obj.new_contents)
     basetest.DiffTestFiles(out, expected)
Esempio n. 9
0
    def assertScrubbed(self,
                       expected,
                       text,
                       internal_package,
                       public_package,
                       filename=''):
        scrubber = java_scrubber.JavaRenameScrubber(internal_package,
                                                    public_package)
        f = test_util.FakeFile(text, filename)
        scrubber.ScrubFile(f, None)
        if f.Contents() == text:
            self.fail("Text %s was not scrubbed, but should've been" % text)

        self.assertEqual(expected, f.Contents())
Esempio n. 10
0
 def assertScrubbing(self, contents, expected):
   fake_file = test_util.FakeFile(contents, 'fake_file.gwt.xml')
   self.scrubber.ScrubFile(fake_file, None)
   basetest.DiffTestStrings(expected, fake_file.Contents())
Esempio n. 11
0
 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)
Esempio n. 12
0
 def assertContents(self, scrubber, expected_lines, actual_lines):
     context = FakeContext()
     file_obj = test_util.FakeFile(contents=u'\n'.join(actual_lines))
     scrubber.ScrubFile(file_obj, context)
     self.assertMultiLineEqual(u'\n'.join(expected_lines),
                               file_obj.new_contents)
Esempio n. 13
0
 def testRegexSucceeds(self):
     subs = [(r'fo{2}', 'bar'), (r'(he)(l)\2o', r'\1\2\2 no')]
     repl = replacer.RegexReplacerScrubber(subs)
     fake_file = test_util.FakeFile('hello foo')
     repl.ScrubFile(fake_file, None)
     self.assertEqual('hell no bar', fake_file.Contents())
Esempio n. 14
0
 def testNoRegex(self):
     subs = [(r'fo*', 'bar')]
     repl = replacer.ReplacerScrubber(subs)
     fake_file = test_util.FakeFile('hello fo*')  # Matches literal 'fo*'
     repl.ScrubFile(fake_file, None)
     self.assertEqual('hello bar', fake_file.Contents())
Esempio n. 15
0
 def assertContentsPreserved(self, contents, extractor):
     scrubber = comment_scrubber.CommentScrubber(extractor)
     fake_file = test_util.FakeFile(contents=contents)
     scrubber.ScrubFile(fake_file, None)
     self.assertMultiLineEqual(contents, fake_file.new_contents)
Esempio n. 16
0
 def testScrubbing(self):
   contents = '<module><inherits name="banana.banana"/></module>'
   fake_file = test_util.FakeFile(contents)
   self.scrubber.ScrubFile(fake_file, None)
   self.assertEquals(contents, fake_file.Contents())
Esempio n. 17
0
 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)
Esempio n. 18
0
 def testPlainSucceeds(self):
     subs = [('foo', 'bar'), ('hello', 'goodbye')]
     repl = replacer.RegexReplacerScrubber(subs)
     fake_file = test_util.FakeFile('hello foo')
     repl.ScrubFile(fake_file, None)
     self.assertEqual('goodbye bar', fake_file.Contents())
Esempio n. 19
0
 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')
Esempio n. 20
0
 def testNoMatch(self):
     subs = [(r'bl(a)h', 'bar')]
     repl = replacer.RegexReplacerScrubber(subs)
     fake_file = test_util.FakeFile('hello foo')  # r'bl(a)h' not found here
     repl.ScrubFile(fake_file, None)
     self.assertEqual('hello foo', fake_file.Contents())  # No new contents
Esempio n. 21
0
 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')