Add test_prettysize to tests.py.
authorRadek Brich <radek.brich@devl.cz>
Sat, 29 Sep 2012 14:01:47 +0200
changeset 50 f71d3abbb18f
parent 49 08e4dfe1b0cb
child 51 bdc44f96cb0b
Add test_prettysize to tests.py.
tests.py
tests/test_mymanager.py
tests/test_pgmanager.py
tests/test_prettysize.py
tests/testpgmanager.py
tests/testprettysize.py
--- a/tests.py	Sat Sep 29 13:53:54 2012 +0200
+++ b/tests.py	Sat Sep 29 14:01:47 2012 +0200
@@ -3,7 +3,8 @@
 import unittest
 
 from tests import test_rowdict
-from tests import testpgmanager
+from tests import test_pgmanager
+from tests import test_prettysize
 
 enable_mysql = True
 try:
@@ -15,7 +16,8 @@
 
 suite = unittest.TestSuite()
 suite.addTests(loader.loadTestsFromModule(test_rowdict))
-suite.addTests(loader.loadTestsFromModule(testpgmanager))
+suite.addTests(loader.loadTestsFromModule(test_pgmanager))
+suite.addTests(loader.loadTestsFromModule(test_prettysize))
 
 if enable_mysql:
     suite.addTests(loader.loadTestsFromModule(test_mymanager))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_pgmanager.py	Sat Sep 29 14:01:47 2012 +0200
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+
+from tests.config import Config
+from pgtoolkit import pgmanager
+
+import unittest
+
+
+class TestSuite(unittest.TestCase):
+
+    def setUp(self):
+        cfg = Config('pgtoolkit.conf')
+        test_db_conn_params = cfg['databases']['test']
+        self.m = pgmanager.get_instance()
+        self.m.create_conn(dsn=test_db_conn_params)
+        self.m.create_conn('autocommit', isolation_level='autocommit', dsn=test_db_conn_params)
+
+    def tearDown(self):
+        self.m.destroy_conn()
+        self.m.destroy_conn('autocommit')
+
+    def test_connection_get_put(self):
+        conn = self.m.get_conn()
+
+        curs = conn.cursor()
+        curs.execute('SELECT %s AS t', [True])
+        d = curs.fetchone_dict()
+        self.assertTrue(d.t)
+
+        self.m.put_conn(conn)
+
+    def test_connection_with(self):
+        with self.m.cursor() as curs:
+            curs.execute('SELECT %s AS t', [True])
+            d = curs.fetchone_dict()
+            self.assertTrue(d.t)
+
+    def test_connection_autocommit(self):
+        conn = self.m.get_conn('autocommit')
+        curs = conn.cursor()
+        name = 'test'
+        curs.execute('DELETE FROM test WHERE name = %s', [name])
+        curs.execute('INSERT INTO test (name) VALUES (%s)', [name])
+        conn.close()
+
+        conn = self.m.get_conn('autocommit')
+        curs = conn.cursor()
+        curs.execute('SELECT * FROM test WHERE name = %s', [name])
+        self.assertTrue(curs.rowcount == 1)
+        self.m.put_conn(conn)
+
+
+if __name__ == '__main__':
+    unittest.main()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_prettysize.py	Sat Sep 29 14:01:47 2012 +0200
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+from pgtoolkit import prettysize
+
+import unittest
+
+
+class TestPrettySize(unittest.TestCase):
+    def test_prettysize(self):
+        psize = prettysize.prettysize_short
+        expected = (
+            (0, '0'),
+            (1000, '1000'),
+            (1024, '1K'),
+            (1050, '1.03K'),
+            (2050, '2K'),
+            (333333, '325.52K'),
+            (1048576, '1M'),
+            (1050000, '1M'),
+            (5555555, '5.3M'),
+            (1073741824, '1G'),
+            )
+        for input, result in expected:
+            self.assertEqual(psize(input), result)
+
+
+if __name__ == '__main__':
+    unittest.main()
+
--- a/tests/testpgmanager.py	Sat Sep 29 13:53:54 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#!/usr/bin/env python3
-
-from tests.config import Config
-from pgtoolkit import pgmanager
-
-import unittest
-
-
-class TestSuite(unittest.TestCase):
-
-    def setUp(self):
-        cfg = Config('pgtoolkit.conf')
-        test_db_conn_params = cfg['databases']['test']
-        self.m = pgmanager.get_instance()
-        self.m.create_conn(dsn=test_db_conn_params)
-        self.m.create_conn('autocommit', isolation_level='autocommit', dsn=test_db_conn_params)
-
-    def tearDown(self):
-        self.m.destroy_conn()
-        self.m.destroy_conn('autocommit')
-
-    def test_connection_get_put(self):
-        conn = self.m.get_conn()
-
-        curs = conn.cursor()
-        curs.execute('SELECT %s AS t', [True])
-        d = curs.fetchone_dict()
-        self.assertTrue(d.t)
-
-        self.m.put_conn(conn)
-
-    def test_connection_with(self):
-        with self.m.cursor() as curs:
-            curs.execute('SELECT %s AS t', [True])
-            d = curs.fetchone_dict()
-            self.assertTrue(d.t)
-
-    def test_connection_autocommit(self):
-        conn = self.m.get_conn('autocommit')
-        curs = conn.cursor()
-        name = 'test'
-        curs.execute('DELETE FROM test WHERE name = %s', [name])
-        curs.execute('INSERT INTO test (name) VALUES (%s)', [name])
-        conn.close()
-
-        conn = self.m.get_conn('autocommit')
-        curs = conn.cursor()
-        curs.execute('SELECT * FROM test WHERE name = %s', [name])
-        self.assertTrue(curs.rowcount == 1)
-        self.m.put_conn(conn)
-
-
-if __name__ == '__main__':
-    unittest.main()
-
--- a/tests/testprettysize.py	Sat Sep 29 13:53:54 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#!/usr/bin/env python3
-
-import unittest
-from pgtoolkit import prettysize
-
-class TestHumansize(unittest.TestCase):
-    def test_humansize(self):
-        psize = prettysize.prettysize_short
-        expected = (
-            (0, '0'),
-            (1000, '1000'),
-            (1024, '1K'),
-            (1050, '1.03K'),
-            (2050, '2K'),
-            (333333, '325.52K'),
-            (1048576, '1M'),
-            (1050000, '1M'),
-            (5555555, '5.3M'),
-            (1073741824, '1G'),
-            )
-        for input, result in expected:
-            self.assertEqual(psize(input), result)
-
-
-if __name__ == '__main__':
-    unittest.main()