Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Added first unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
FSX committed Dec 13, 2012
1 parent 75de28c commit 223a6d1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
50 changes: 50 additions & 0 deletions momoko/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import unittest

import momoko
from tornado.testing import AsyncTestCase


db_database = os.environ.get('MOMOKO_TEST_DB', None)
db_user = os.environ.get('MOMOKO_TEST_USER', None)
db_password = os.environ.get('MOMOKO_TEST_PASSWORD', None)
db_host = os.environ.get('MOMOKO_TEST_HOST', None)
db_port = os.environ.get('MOMOKO_TEST_PORT', None)

assert (db_database or db_user or db_password or db_host or db_port) is not None, (
'Environment variables for the unit tests are not set. Please set the following '
'variables: MOMOKO_TEST_DB, MOMOKO_TEST_USER, MOMOKO_TEST_PASSWORD, '
'MOMOKO_TEST_HOST, MOMOKO_TEST_PORT')


class MomokoTest(AsyncTestCase):
def setUp(self):
super(MomokoTest, self).setUp()

dsn = 'dbname=%s user=%s password=%s host=%s port=%s' % (
db_database,
db_user,
db_password,
db_host,
db_port
)

self.db = momoko.Pool(
dsn=dsn,
minconn=1,
maxconn=10,
cleanup_timeout=10,
ioloop=self.io_loop
)

def tearDown(self):
self.db.close()
super(MomokoTest, self).tearDown()

def stop_callback(self, result, error):
self.stop((result, error))

def test_single_query(self):
self.db.execute('SELECT 42, 12, 40, 11;', callback=self.stop_callback)
cursor, error = self.wait()
self.assertEqual(cursor.fetchall(), [(42, 12, 40, 11)])
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env python

# The multiprocessingimport is to prevent the following error
# after all the tests have been executed.
# Error in atexit._run_exitfuncs:
# TypeError: 'NoneType' object is not callable

# From: http://article.gmane.org/gmane.comp.python.peak/2509
# Work around setuptools bug
# http://article.gmane.org/gmane.comp.python.peak/2509
import multiprocessing

try:
from setuptools import setup, Extension, Command
except ImportError:
Expand All @@ -16,6 +26,7 @@
url='http://momoko.61924.nl/',
packages=['momoko'],
license='MIT',
test_suite = 'momoko.tests',
install_requires=[
'tornado',
'psycopg2'
Expand Down

0 comments on commit 223a6d1

Please sign in to comment.