Commits

Anonymous committed 9d0a7fb

tests cleanup

  • Participants
  • Parent commits cc916c0

Comments (0)

Files changed (5)

File pymills/dbapi.py

     def __len__(self):
         "x.__len__() <==> len(x)"
 
-        return self.cursor.rowcount
+        rows = self.cursor.rowcount
+        if rows == -1:
+            return 0
+        else:
+            return rows
 
     def next(self):
         "x.next() -> the next value, or raise StopIteration"
 
         row = self.cursor.fetchone()
         if row:
-            return Record(self, zip(self.fields, row))
+            return Record(zip(self.fields, row))
         else:
             raise StopIteration
 
 class Record(odict):
 
-    def __init__(self, records, data):
-        "initializes x; see x.__class__.__doc__ for signature"
-
-        super(Record, self).__init__()
-
-        self.records = records
-
-        self.update(data)
-
     def __repr__(self):
         return "<%s (%r)>" % (self.__class__.__name__, self.keys())
 
         if type(k) == tuple:
             k = k[0]
 
-        if isinstance(v, self.records.cursor.__class__):
-            if self.records.cursor.description is not None:
-                fields = map(lambda x: x[0], v.description)
-                v = Records(self.records, v)
-
         super(Record, self).__setitem__(k, v)
         setattr(self, k, v)
-
-    def __delitem__(self, k):
-        super(Record, self).__delitem__(k)
-        delattr(self, k)

File tests/test_db.py

-# Module:	db
-# Date:		27th December 2007
-# Author:	James Mills, prologic at shortcircuit dot net dot au
-
-"""DB Test Suite
-
-Test all functionality of the db library.
-"""
-
-import unittest
-
-from pymills.db import newDB, DriverError
-
-class DBTestCase(unittest.TestCase):
-
-	def testSQLite(self):
-		"""Test SQLite Sessions
-
-		Tests the database library using SQLite Sessions.
-		"""
-
-		try:
-			db = newDB("sqlite://:memory:")
-		except DriverError:
-			self.assertTrue(True)
-			return
-
-		x = db.do("create table names (firstname, lastname)")
-		self.assertEquals(x, [])
-		x = db.do("insert into names values ('James', 'Mills')")
-		self.assertEquals(x, [])
-		x = db.do("insert into names values ('Danny', 'Rawlins')")
-		self.assertEquals(x, [])
-		rows = db.do("select firstname, lastname from names")
-		self.assertEquals(rows[0].firstname, "James")
-		self.assertEquals(rows[0].lastname, "Mills")
-
-def suite():
-	return unittest.makeSuite(DBTestCase, "test")
-
-if __name__ == "__main__":
-	unittest.main()

File tests/test_dbapi.py

+
+from pymills.dbapi import Connection
+
+def test_sqlite():
+    db = Connection("sqlite", ":memory:")
+
+    rows = db.do("CREATE TABLE foo (x, y)")
+    assert list(rows) == []
+
+    rows = db.do("INSERT INTO foo VALUES (?, ?)", 1, 2)
+    assert list(rows) == []
+
+    rows = db.do("INSERT INTO foo VALUES (?, ?)", 3, 4)
+    assert list(rows) == []
+
+    rows = db.do("SELECT x, y FROM foo")
+    rows = list(rows)
+    assert len(rows) == 2
+
+    assert rows[0].keys() == ["x", "y"]
+    assert rows[0].items() == [("x", 1), ("y", 2)]
+    assert rows[0].values() == [1, 2]
+
+    assert rows[1].x == 3
+    assert rows[1].y == 4

File tests/test_emailtools.py

-# Module:	utils
-# Date:		5th March 2008
-# Author:	James Mills, prologic at shortcircuit dot net dot au
-
-"""Email Tools Test Suite
-
-Test all functionality of the Email Tools library.
-"""
-
-import socket
-import unittest
-
-from pymills.emailtools import Email
-
-class EmailToolsTestCase(unittest.TestCase):
-
-	def test_Email(self):
-		"""Test Email class
-
-		Test the Email class
-		"""
-
-		fd = open("/tmp/foo", "w")
-		fd.write("This is a test file.")
-		fd.close()
-
-		sender = "root@localhost"
-		recipient = "root@localhost"
-		subject = "Test"
-		body = "This is a test email."
-		file = "/tmp/foo"
-		filename = "foo.txt"
-
-		try:
-			email = Email(sender, recipient, subject)
-			email.add(body)
-			email.add(file=file, attach=True, filename=filename)
-			email.send()
-		except socket.error, e:
-			pass
-
-def suite():
-	return unittest.makeSuite(EmailToolsTestCase, "test")
-
-if __name__ == "__main__":
-	unittest.main()

File tests/test_utils.py

-# Module:	utils
-# Date:		14th January 2008
-# Author:	James Mills, prologic at shortcircuit dot net dot au
+from pymills.utils import notags
 
-"""Utils Test Suite
-
-Test all functionality of the Utils library.
-"""
-
-import unittest
-
-from pymills.utils import notags, getProgName 
-
-class UtilsTestCase(unittest.TestCase):
-
-	def test_notags(self):
-		"""Test notags functions
-
-		Test the "notags" function.
-		"""
-
-		x = "<html>foo</html>"
-		y = "foo"
-		self.assertEquals(notags(x), y)
-
-	def test_getProgName(self):
-		"""Test getProgName functions
-
-		Test the "getProgName" function.
-		"""
-
-		self.assertEquals(getProgName(), "nosetests")
-
-def suite():
-	return unittest.makeSuite(UtilsTestCase, "test")
-
-if __name__ == "__main__":
-	unittest.main()
+def test_notags():
+    s = "<html>foo</html>"
+    x = notags(s)
+    assert x == "foo"