Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: tools/telemetry/third_party/rope/ropetest/simplifytest.py

Issue 1132103009: Example of refactoring using rope library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/rope/ropetest/simplifytest.py
diff --git a/tools/telemetry/third_party/rope/ropetest/simplifytest.py b/tools/telemetry/third_party/rope/ropetest/simplifytest.py
new file mode 100644
index 0000000000000000000000000000000000000000..05969e36dd7a10300e8151bd0e2079586d49e443
--- /dev/null
+++ b/tools/telemetry/third_party/rope/ropetest/simplifytest.py
@@ -0,0 +1,68 @@
+import unittest
+
+from rope.base import simplify
+
+
+class SimplifyTest(unittest.TestCase):
+
+ def setUp(self):
+ super(SimplifyTest, self).setUp()
+
+ def tearDown(self):
+ super(SimplifyTest, self).tearDown()
+
+ def test_trivial_case(self):
+ self.assertEquals('', simplify.real_code(''))
+
+ def test_empty_strs(self):
+ code = 's = ""\n'
+ self.assertEquals(code, simplify.real_code(code))
+
+ def test_blanking_strs(self):
+ code = 's = "..."\n'
+ self.assertEquals('s = " "\n', simplify.real_code(code))
+
+ def test_changing_to_double_quotes(self):
+ code = 's = \'\'\n'
+ self.assertEquals('s = ""\n', simplify.real_code(code))
+
+ def test_changing_to_double_quotes2(self):
+ code = 's = """\n"""\n'
+ self.assertEquals('s = " "\n', simplify.real_code(code))
+
+ def test_removing_comments(self):
+ code = '# c\n'
+ self.assertEquals(' \n', simplify.real_code(code))
+
+ def test_removing_comments_that_contain_strings(self):
+ code = '# "c"\n'
+ self.assertEquals(' \n', simplify.real_code(code))
+
+ def test_removing_strings_containing_comments(self):
+ code = '"#c"\n'
+ self.assertEquals('" "\n', simplify.real_code(code))
+
+ def test_joining_implicit_continuations(self):
+ code = '(\n)\n'
+ self.assertEquals('( )\n', simplify.real_code(code))
+
+ def test_joining_explicit_continuations(self):
+ code = '1 + \\\n 2\n'
+ self.assertEquals('1 + 2\n', simplify.real_code(code))
+
+ def test_replacing_tabs(self):
+ code = '1\t+\t2\n'
+ self.assertEquals('1 + 2\n', simplify.real_code(code))
+
+ def test_replacing_semicolons(self):
+ code = 'a = 1;b = 2\n'
+ self.assertEquals('a = 1\nb = 2\n', simplify.real_code(code))
+
+
+def suite():
+ result = unittest.TestSuite()
+ result.addTests(unittest.makeSuite(SimplifyTest))
+ return result
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/telemetry/third_party/rope/ropetest/runmodtest.py ('k') | tools/telemetry/third_party/rope/ropetest/testutils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698