Permalink
Browse files

Convert tests to unittest.TestCase

  • Loading branch information...
1 parent 1d1a67f commit b4c92abe27bcf2a08c6f32527a06b9964085d41f @andrewschaaf committed Feb 5, 2014
Showing with 37 additions and 34 deletions.
  1. +37 −0 test.py
  2. +0 −34 test/test_codegen.py
View
37 test.py
@@ -0,0 +1,37 @@
+import unittest
+import codegen
+import ast
+
+class TestCodegen(unittest.TestCase):
+
+ def assertPreserved(self, code):
+ result = codegen.to_source(ast.parse(code))
+ self.assertEqual(result.rstrip(), code.rstrip())
+
+ def test_Pow(self):
+ self.assertPreserved("y = (x ** 2)")
+
+ def test_del(self):
+ self.assertPreserved("del l[0]")
+ self.assertPreserved("del obj.x")
+
+ def test_try_expect(self):
+ source = ("try:\n"
+ " '#'[2]\n"
+ "except IndexError:\n"
+ " print 'What did you expect?!'")
+ self.assertPreserved(source)
+ source = ("try:\n"
+ " l = []\n"
+ " l[1]\n"
+ "except IndexError, index_error:\n"
+ " print index_error")
+ self.assertPreserved(source)
+
+ def test_import(self):
+ self.assertPreserved("import intertools as iterators")
+ self.assertPreserved("from math import floor as fl, ceil as cl")
+
+
+if __name__ == '__main__':
+ unittest.main()
View
@@ -1,34 +0,0 @@
-import codegen
-import ast
-
-def to_ast_and_back_again(source):
- return codegen.to_source(ast.parse(source))
-
-def test_Pow():
- source = "y = (x ** 2)\n"
- assert source == to_ast_and_back_again(source)
-
-def test_del():
- source = "del l[0]"
- assert source == to_ast_and_back_again(source)
- source = "del obj.x"
- assert source == to_ast_and_back_again(source)
-
-def test_try_expect():
- source = ("try:\n"
- " '#'[2]\n"
- "except IndexError:\n"
- " print 'What did you expect?!'")
- assert source == to_ast_and_back_again(source)
- source = ("try:\n"
- " l = []\n"
- " l[1]\n"
- "except IndexError, index_error:\n"
- " print index_error")
- assert source == to_ast_and_back_again(source)
-
-def test_import():
- source = "import intertools as iterators"
- assert source == to_ast_and_back_again(source)
- source = "from math import floor as fl, ceil as cl"
- assert source == to_ast_and_back_again(source)

0 comments on commit b4c92ab

Please sign in to comment.