Permalink
Browse files

Consolidate tests in tox.ini and other testing enhancements.

 * pyrseas/testutils.py (remove_temp_files): New function to be used
   by test cases.  (DatabaseToMapTestCase.remove_tempfiles): New
   method.  (DbMigrateTestCase.to_map): Use TEST_DIR instead of
   tempfile.gettempdir().  (DbMigrateTestCase.remove_tempfiles):
   Refactor code out to remove_temp_files.
 * tests/dbobject/test_extern_file.py
   (ExternalFilenameMapTestCase.setUp): Remove temporary files before
   running tests.
 * tests/functional/pagila-schema.sql: Remove COMMENT on public schema
   (caused problems with other tests).
 * tox.ini: Run all tests (dbobject, functional and relation).
  • Loading branch information...
1 parent fd88686 commit f6ccbc0f9389562267831adeed503472d46b9794 @jmafc jmafc committed Mar 27, 2013
Showing with 29 additions and 24 deletions.
  1. +23 −15 pyrseas/testutils.py
  2. +5 −1 tests/dbobject/test_extern_file.py
  3. +0 −7 tests/functional/pagila-schema.sql
  4. +1 −1 tox.ini
View
@@ -20,10 +20,27 @@ def fix_indent(stmt):
replace('( ', '(')
+def remove_temp_files(tmpdir, prefix=''):
+ "Remove files in a temporary directory"
+ for tfile in glob.glob(os.path.join(tmpdir, prefix + '*')):
+ if os.path.isdir(tfile):
+ for entry in os.listdir(tfile):
+ entry = os.path.join(tmpdir, tfile, entry)
+ if os.path.isdir(entry):
+ for file in os.listdir(entry):
+ os.remove(os.path.join(entry, file))
+ os.rmdir(entry)
+ else:
+ os.remove(entry)
+ os.rmdir(tfile)
+ else:
+ os.remove(tfile)
+
+
TEST_DBNAME = os.environ.get("PYRSEAS_TEST_DB", 'pyrseas_testdb')
TEST_USER = os.environ.get("PYRSEAS_TEST_USER", getpass.getuser())
TEST_HOST = os.environ.get("PYRSEAS_TEST_HOST", None)
-TEST_PORT = os.environ.get("PYRSEAS_TEST_PORT", None)
+TEST_PORT = int(os.environ.get("PYRSEAS_TEST_PORT", 5432))
PG_OWNER = 'postgres'
TEST_DIR = os.path.join(tempfile.gettempdir(),
os.environ.get("PYRSEAS_TEST_DIR", 'pyrseas_test'))
@@ -315,6 +332,9 @@ def yaml_load(self, filename, subdir=None):
inmap = f.read()
return yaml.safe_load(inmap)
+ def remove_tempfiles(self):
+ remove_temp_files(TEST_DIR)
+
class InputMapToSqlTestCase(PyrseasTestCase):
"""Base class for "input map to SQL" test cases"""
@@ -383,23 +403,11 @@ def setUpClass(cls):
progdir = os.path.abspath(os.path.dirname(__file__))
cls.dbtoyaml = os.path.join(progdir, 'dbtoyaml.py')
cls.yamltodb = os.path.join(progdir, 'yamltodb.py')
- cls.tmpdir = tempfile.gettempdir()
+ cls.tmpdir = TEST_DIR
@classmethod
def remove_tempfiles(cls, prefix):
- for tfile in glob.glob(os.path.join(cls.tmpdir, prefix + '*')):
- if os.path.isdir(tfile):
- for entry in os.listdir(tfile):
- entry = os.path.join(cls.tmpdir, tfile, entry)
- if os.path.isdir(entry):
- for file in os.listdir(entry):
- os.remove(os.path.join(entry, file))
- os.rmdir(entry)
- else:
- os.remove(entry)
- os.rmdir(tfile)
- else:
- os.remove(tfile)
+ remove_temp_files(cls.tmpdir, prefix)
def execute_script(self, path, scriptname):
scriptfile = os.path.join(os.path.abspath(os.path.dirname(path)),
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
"""Test external files used in --directory option"""
import sys
-from pyrseas.testutils import DatabaseToMapTestCase
from pyrseas.testutils import PyrseasTestCase
+from pyrseas.testutils import DatabaseToMapTestCase
from pyrseas.dbobject.schema import Schema
from pyrseas.dbobject.function import Function
from pyrseas.dbobject.table import Sequence, Table, View
@@ -23,6 +23,10 @@
class ExternalFilenameMapTestCase(DatabaseToMapTestCase):
+ def setUp(self):
+ super(ExternalFilenameMapTestCase, self).setUp()
+ self.remove_tempfiles()
+
def test_map_casts(self):
"Map casts"
self.to_map(["CREATE FUNCTION int2_bool(smallint) RETURNS boolean "
@@ -9,13 +9,6 @@ SET client_min_messages = warning;
SET escape_string_warning = off;
--
--- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
---
-
-COMMENT ON SCHEMA public IS 'Standard public schema';
-
-
---
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--
View
@@ -59,4 +59,4 @@ deps=pytest
setenv =
PYTHONPATH = {toxinidir}
commands =
- py.test tests/dbobject
+ py.test tests

0 comments on commit f6ccbc0

Please sign in to comment.