]> git.phdru.name Git - sqlconvert.git/commitdiff
Use pytest for testing
authorOleg Broytman <phd@phdru.name>
Sun, 11 Sep 2016 18:37:36 +0000 (21:37 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 11 Sep 2016 18:37:36 +0000 (21:37 +0300)
ChangeLog
requirements_dev.txt [new file with mode: 0644]
tests/Makefile
tests/__init__.py [deleted file]
tests/run_all.py [deleted file]
tests/test_stgrouper.py [changed mode: 0755->0644]
tests/test_tokens.py [changed mode: 0755->0644]

index ec6b82f7953467d0bf1a43b54def6b6177b0d18d..cbf159e6ec209409aac6c2871cec8ded8d6ec248 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@ Version 0.0.6 (2016-09-??)
 
     Unescape strings.
 
+    Use pytest for testing.
+
 Version 0.0.5 (2016-09-07)
 
     Remove /*! directives */; and newlines after them.
diff --git a/requirements_dev.txt b/requirements_dev.txt
new file mode 100644 (file)
index 0000000..73c8ac6
--- /dev/null
@@ -0,0 +1,3 @@
+-r requirements.txt
+
+pytest
index b990065cfd8bab40e800e4f3987644c570fca99e..a6a5e1f64fcca64b44fc4d8a7e2de2345b4999b9 100644 (file)
@@ -1,4 +1,4 @@
 
 .PHONY: all
 all:
-       ./run_all.py
+       python `which pytest`
diff --git a/tests/__init__.py b/tests/__init__.py
deleted file mode 100644 (file)
index d26523d..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-
-import unittest
-
-__all__ = ['TestCase', 'main']
-
-
-class TestCase(unittest.TestCase):
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-
-
-def main():
-    try:
-        unittest.main(testRunner=unittest.TextTestRunner())
-    except SystemExit as msg:
-        result = msg.args[0]
-    else:
-        result = 0
-    raise SystemExit(result)
diff --git a/tests/run_all.py b/tests/run_all.py
deleted file mode 100755 (executable)
index 9503411..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#! /usr/bin/env python
-from __future__ import print_function
-
-
-import os
-import sys
-import subprocess
-
-
-def isexecutable(filename):
-    infile = open(filename, 'r')
-    magic = infile.read(2)
-    infile.close()
-    return magic == "#!"
-
-
-def collect_tests():
-    tests = []
-    for dirpath, dirs, files in os.walk("tests"):
-        tests.extend(
-            [os.path.join(dirpath, filename) for filename in files
-             if filename.startswith("test") and filename.endswith(".py")
-             ])
-    return [test[:-3].replace(os.sep, '.') for test in tests
-            if isexecutable(test)]
-
-
-def main():
-    os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
-    tests = collect_tests()
-
-    os.environ["PYTHONPATH"] = os.curdir
-
-    for test in sorted(tests):
-        print(test)
-        subprocess.call((sys.executable, '-m', test))
-
-if __name__ == '__main__':
-    main()
old mode 100755 (executable)
new mode 100644 (file)
index 299ea6c..88d0fcf
@@ -1,33 +1,26 @@
-#! /usr/bin/env python
-
-
-import unittest
 
+from pytest import raises
 from sqlconvert.print_tokens import tlist2str
 from sqlconvert.process_mysql import requote_names
 from sqlconvert.process_tokens import StatementGrouper
-from tests import main
 
 
-class TestStGrouper(unittest.TestCase):
+class TestStGrouper(object):
     def test_incomplete(self):
         grouper = StatementGrouper()
         grouper.process_line("select * from `T`")
-        self.assertFalse(grouper.statements)
-        self.assertEqual(len(grouper.statements), 0)
-        self.assertRaises(ValueError, grouper.close)
+        assert not grouper.statements
+        assert len(grouper.statements) == 0
+        raises(ValueError, grouper.close)
 
     def test_statements(self):
         grouper = StatementGrouper()
         grouper.process_line("select * from `T`;")
-        self.assertTrue(grouper.statements)
-        self.assertEqual(len(grouper.statements), 1)
+        assert grouper.statements
+        assert len(grouper.statements) == 1
         for statement in grouper.get_statements():
             requote_names(statement)
             query = tlist2str(statement)
-            self.assertEqual(query, 'SELECT * FROM "T";')
-        self.assertEqual(len(grouper.statements), 0)
-        self.assertEqual(grouper.close(), None)
-
-if __name__ == "__main__":
-    main()
+            assert query == 'SELECT * FROM "T";'
+        assert len(grouper.statements) == 0
+        assert grouper.close() is None
old mode 100755 (executable)
new mode 100644 (file)
index de11485..8201e74
@@ -1,58 +1,51 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import unittest
 from sqlparse import parse
 
 from sqlconvert.print_tokens import tlist2str
 from sqlconvert.process_mysql import remove_directive_tokens, \
         is_directive_statement, requote_names, unescape_strings, \
         process_statement
-from tests import main
 
 
-class TestTokens(unittest.TestCase):
+class TestTokens(object):
     def test_encoding(self):
         parsed = parse("insert into test (1, 'тест')", 'utf-8')[0]
         query = tlist2str(parsed).encode('utf-8')
-        self.assertEqual(query,
-                         u"INSERT INTO test (1, 'тест')".encode('utf-8'))
+        assert query == \
+            u"INSERT INTO test (1, 'тест')".encode('utf-8')
 
     def test_unicode(self):
         parsed = parse(u"insert into test (1, 'тест')")[0]
         query = tlist2str(parsed)
-        self.assertEqual(query, u"INSERT INTO test (1, 'тест')")
+        assert query, u"INSERT INTO test (1 == 'тест')"
 
     def test_directive(self):
         parsed = parse("select /*! test */ * from /* test */ `T`")[0]
         remove_directive_tokens(parsed)
         query = tlist2str(parsed)
-        self.assertEqual(query, u'SELECT * FROM /* test */ `T`')
+        assert query == u'SELECT * FROM /* test */ `T`'
 
     def test_directive_statement(self):
         parsed = parse("/*! test */ test ;")[0]
-        self.assertFalse(is_directive_statement(parsed))
+        assert not is_directive_statement(parsed)
         parsed = parse("/*! test */ ;")[0]
-        self.assertTrue(is_directive_statement(parsed))
+        assert is_directive_statement(parsed)
 
     def test_requote(self):
         parsed = parse("select * from `T`")[0]
         requote_names(parsed)
         query = tlist2str(parsed)
-        self.assertEqual(query, u'SELECT * FROM "T"')
+        assert query == u'SELECT * FROM "T"'
 
     def test_string(self):
         parsed = parse("insert into test values ('\"test\\\"')")[0]
         unescape_strings(parsed)
         query = tlist2str(parsed)
-        self.assertEqual(query, u"INSERT INTO test VALUES ('\"test\"')")
+        assert query == u"INSERT INTO test VALUES ('\"test\"')"
 
     def test_process(self):
         parsed = parse("select /*! test */ * from /* test */ `T`")[0]
         process_statement(parsed)
         query = tlist2str(parsed)
-        self.assertEqual(query, u'SELECT * FROM /* test */ "T"')
-
-
-if __name__ == "__main__":
-    main()
+        assert query == u'SELECT * FROM /* test */ "T"'