Skip to content

Commit

Permalink
Added a test runner that runs all the tests in the test/ directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toru Maesaka committed Apr 3, 2011
1 parent 0195fb1 commit fe3e7e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions tests/t_all.py
@@ -0,0 +1,28 @@
#!/usr/bin/env python
#
# Copyright 2011, Toru Maesaka
#
# Redistribution and use of this source code is licensed under
# the BSD license. See COPYING file for license description.

import os
import re
import unittest

_TEST_MODULE_PATTERN = re.compile(r'^(t_.+)\.py$')

def _run_all_tests():
module_names = []
loader = unittest.TestLoader()
test_path = os.path.join(os.path.split(__file__)[0], '.')

for filename in os.listdir(test_path):
match = _TEST_MODULE_PATTERN.search(filename)
if match:
module_names.append(match.group(1))

return loader.loadTestsFromNames(module_names)

if __name__ == '__main__':
unittest.main(defaultTest='_run_all_tests')
pass
4 changes: 2 additions & 2 deletions tests/t_simple.py
Expand Up @@ -13,7 +13,7 @@ class UnitTest(unittest.TestCase):
def setUp(self):
self.kt_handle = KyotoTycoon()
self.kt_handle.open()
self.LARGE_KEY = 8000
self.LARGE_KEY_LEN = 8000

def test_set(self):
self.assertTrue(self.kt_handle.clear())
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_add(self):
self.assertFalse(self.kt_handle.add(None, 'value'))

def test_large_key(self):
large_key = 'x' * self.LARGE_KEY
large_key = 'x' * self.LARGE_KEY_LEN
self.assertTrue(self.kt_handle.set(large_key, 'value'))
self.assertEqual(self.kt_handle.get(large_key), 'value')

Expand Down

0 comments on commit fe3e7e4

Please sign in to comment.