Browse Source

Use a modular Makefile and python-nose to automate tests

tags/3.40
Ben Finney 13 years ago
parent
commit
934e85b526
6 changed files with 162 additions and 59 deletions
  1. +1
    -0
      .bzrignore
  2. +55
    -0
      Makefile
  3. +26
    -0
      module.mk
  4. +0
    -0
      test/__init__.py
  5. +80
    -0
      test/module.mk
  6. +0
    -59
      test/suite.py

+ 1
- 0
.bzrignore View File

@@ -0,0 +1 @@
./.coverage

+ 55
- 0
Makefile View File

@@ -0,0 +1,55 @@
#! /usr/bin/make -f

# Makefile
# Part of reportbug, a Debian bug reporting tool.
#
# Copyright © 2008 Ben Finney <ben+debian@benfinney.id.au>
# This is free software; you may copy, modify and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later.
# No warranty expressed or implied. See the file LICENSE for details.

# Makefile for reportbug project

SHELL = /bin/bash
PATH = /usr/bin:/bin

# Directories with semantic meaning
CODE_PACKAGE_DIR := .
CODE_PROGRAM_DIR := .
TEST_DIR := test

# Variables that will be extended by module include files
GENERATED_FILES :=
CODE_MODULES :=
CODE_PROGRAMS :=

# List of modules (directories) that comprise our 'make' project
MODULES += ${CODE_PACKAGE_DIR}
MODULES += ${TEST_DIR}

RM = rm

# Include the make data for each module
include $(patsubst %,%/module.mk,${MODULES})

.PHONY: all
all: build

.PHONY: build
build:

.PHONY: install
install: build

.PHONY: clean
clean:
$(RM) -rf ${GENERATED_FILES}

.PHONY: test
test:

.PHONY: qa
qa:

+ 26
- 0
module.mk View File

@@ -0,0 +1,26 @@
# :vim: filetype=make : -*- makefile; coding: utf-8; -*-

# module.mk
# Part of reportbug, a Debian bug reporting tool.
#
# Copyright © 2008 Ben Finney <ben+debian@benfinney.id.au>
# This is free software; you may copy, modify and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later.
# No warranty expressed or implied. See the file LICENSE for details.

# Makefile module for reportbug Python package

MODULE_DIR := .

CODE_MODULES += $(shell find ${CODE_PACKAGE_DIR} -name '*.py')

CODE_PROGRAM_NAMES += reportbug
CODE_PROGRAM_NAMES += querybts
CODE_PROGRAM_NAMES += handle_bugscript
CODE_PROGRAM_NAMES += script

CODE_PROGRAMS += $(addprefix ${CODE_PROGRAM_DIR}/,${CODE_PROGRAM_NAMES})

GENERATED_FILES += $(shell find ${MODULE_DIR} -name '*.pyc')

PYTHON = python

+ 0
- 0
test/__init__.py View File


+ 80
- 0
test/module.mk View File

@@ -0,0 +1,80 @@
# :vim: filetype=make : -*- makefile; coding: utf-8; -*-

# test/module.mk
# Part of reportbug, a Debian bug reporting tool.
#
# Copyright © 2008 Ben Finney <ben+debian@benfinney.id.au>
# This is free software; you may copy, modify and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later.
# No warranty expressed or implied. See the file LICENSE for details.

# Makefile module for test suite

MODULE_DIR := ${TEST_DIR}

NOSETESTS = nosetests
NOSETESTS_OPTS = --exclude='^(?!test_)'
PYFLAKES = pyflakes
PYLINT = pylint
COVERAGE = python-coverage
DATE = date
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
INWAIT = inotifywait
INWAIT_OPTS = -q -r -e modify -e create -t 0
TEST_INWAIT_FILES = ${CODE_PACKAGE_DIR} ${CODE_PROGRAMS} ${TEST_DIR}

NOSETESTS_FILES = ${TEST_DIR}
nosetests_cmd = $(NOSETESTS) ${NOSETESTS_OPTS} ${NOSETESTS_FILES}

coverage_files += ${CODE_MODULES}
# Not until python-coverage is updated with upstream fixes (2008-05-04)
#coverage_files += ${CODE_PROGRAMS}

GENERATED_FILES += .coverage

# usage: $(call test-output-banner,message)
define test-output-banner
@ echo -n ${1} ; \
$(DATE) +${DATE_FORMAT}
endef


.PHONY: nosetests
nosetests:
$(call test-output-banner, "Test run: " )
$(nosetests_cmd)

test: nosetests

# usage: $(call test-wait)
define test-wait
$(INWAIT) ${INWAIT_OPTS} ${TEST_INWAIT_FILES}
endef

.PHONY: test-continuous
test-continuous:
while true ; do \
clear ; \
$(MAKE) test ; \
$(call test-wait) ; \
done

.PHONY: pyflakes
pyflakes:
$(PYFLAKES) .

.PHONY: pylint
pylint:
$(PYLINT) ${CODE_PACKAGE_DIR}
$(PYLINT) ${CODE_PROGRAMS}
$(PYLINT) ${TEST_DIR}

.PHONY: coverage
coverage: NOSETEST_OPTS += --with-coverage
coverage:
$(nosetests_cmd)
$(COVERAGE) -r -m ${coverage_files}

qa: pyflakes coverage

+ 0
- 59
test/suite.py View File

@@ -1,59 +0,0 @@
# -*- coding: utf-8; -*-

# test/suite.py
# Part of reportbug, a Debian bug reporting tool.
#
# Copyright © 2008 Ben Finney <ben+python@benfinney.id.au>
# This is free software; you may copy, modify and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later.
# No warranty expressed or implied. See the file COPYING for details.

""" Unit test suite for reportbug
"""

import unittest
import sys
import os

def get_python_modules(file_list, file_suffix = '.py'):
""" Return a list of module names from a filename list """
python_modules = [m[:m.rfind(file_suffix)] for m in file_list
if m.endswith(file_suffix)]
return python_modules

def get_test_modules(module_list, module_prefix = 'test_'):
""" Return the list of modules that are named as test modules """
test_modules = [m for m in module_list
if m.startswith(module_prefix)]
return test_modules

def suite():
""" Create the test suite for this module """
loader = unittest.TestLoader()
test_dir = os.path.dirname(__file__)
python_modules = get_python_modules(os.listdir(test_dir))
module_list = get_test_modules(python_modules)
suite = loader.loadTestsFromNames(module_list)

return suite

def __main__(argv=None):
""" Mainline function for this module """
from sys import argv as sys_argv
if not argv:
argv = sys_argv

exitcode = None
try:
unittest.main(argv=argv, defaultTest='suite')
except SystemExit, e:
exitcode = e.code

return exitcode

if __name__ == '__main__':
exitcode = __main__(sys.argv)
sys.exit(exitcode)

Loading…
Cancel
Save