From b7ae73a14e2fde4c2dad46e18e5625f6095d18cc Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 09:01:13 -0400 Subject: [PATCH 01/10] Make test runner selectable --- Makefile | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index bad6d51..6eccfb3 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ PYTHON_MAJOR := 3 PYTHON_MINOR := 4 +# Test runner settings +# Options are: nose, pytest +TEST_RUNNER := nose + # Project settings (automatically detected from files/directories) PROJECT := $(patsubst ./%.sublime-project,%, $(shell find . -type f -name '*.sublime-p*')) PACKAGE := $(patsubst ./%/__init__.py,%, $(shell find . -maxdepth 2 -name '__init__.py')) @@ -46,6 +50,8 @@ PEP257 := $(BIN)/pep257 PYLINT := $(BIN)/pylint PYREVERSE := $(BIN)/pyreverse NOSE := $(BIN)/nosetests +PYTEST := $(BIN)/py.test +COVERAGE := $(BIN)/coverage # Flags for PHONY targets DEPENDS_CI := $(ENV)/.depends-ci @@ -82,7 +88,7 @@ depends: .depends-ci .depends-dev .PHONY: .depends-ci .depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_CI): Makefile - $(PIP) install --upgrade pep8 pep257 nose coverage + $(PIP) install --upgrade pep8 pep257 $(TEST_RUNNER) coverage touch $(DEPENDS_CI) # flag to indicate dependencies are installed .PHONY: .depends-dev @@ -144,13 +150,31 @@ pylint: .depends-dev # Testing #################################################################### .PHONY: test -test: .depends-ci - $(NOSE) --config=.noserc +test: test-$(TEST_RUNNER) .PHONY: tests -tests: .depends-ci +tests: tests-$(TEST_RUNNER) + +# Nosetest commands +.PHONY: test-nose +test-nose: .depends-ci + $(NOSE) --config=.noserc + +.PHONY: tests-nose +tests-nose: .depends-ci TEST_INTEGRATION=1 $(NOSE) --config=.noserc --cover-package=$(PACKAGE) -xv +# Pytest commands +.PHONY: test-py.test +test-pytest: .depends-ci + $(COVERAGE) run --source $(PACKAGE) -m py.test $(PACKAGE) --junitxml=pyunit.xml + $(COVERAGE) report -m + +.PHONY: tests-py.test +tests-pytest: .depends-ci + TEST_INTEGRATION=1 $(COVERAGE) run --source $(PACKAGE) -m py.test $(PACKAGE) --junitxml=pyunit.xml + $(COVERAGE) report -m + # Cleanup #################################################################### .PHONY: clean From 128aa94e009db6cc0972f9eacc1bf0809854f9e0 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 10:26:42 -0400 Subject: [PATCH 02/10] add dependency to package with test to check that it was installed. Fixes #9 --- foobar/test/test_foobar.py | 12 ++++++++++++ setup.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 foobar/test/test_foobar.py diff --git a/foobar/test/test_foobar.py b/foobar/test/test_foobar.py new file mode 100644 index 0000000..9fe6555 --- /dev/null +++ b/foobar/test/test_foobar.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import unittest + + +class TestFooBar(unittest.TestCase): + def test_dependency_import(self): + try: + import testpackage + assert True + except ImportError: + assert False diff --git a/setup.py b/setup.py index ba1feba..8ecd385 100644 --- a/setup.py +++ b/setup.py @@ -38,5 +38,5 @@ 'Programming Language :: Python :: 3.3', ], - install_requires=[], + install_requires=['testpackage'], ) From ed73fb87baa297063e7d7763c011bd440d3c8bd9 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 10:33:43 -0400 Subject: [PATCH 03/10] use requirements.txt file to specify dependenies. Fixes #31 --- Makefile | 2 +- requirements.txt | 1 + setup.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/Makefile b/Makefile index 6eccfb3..b749f2d 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ ci: pep8 pep257 test tests .PHONY: env env: .virtualenv $(EGG_INFO) -$(EGG_INFO): Makefile setup.py +$(EGG_INFO): Makefile setup.py requirements.txt $(PYTHON) setup.py develop touch $(EGG_INFO) # flag to indicate package is installed diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4066ad9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +testpackage==2.26 diff --git a/setup.py b/setup.py index 8ecd385..d493ff9 100644 --- a/setup.py +++ b/setup.py @@ -38,5 +38,5 @@ 'Programming Language :: Python :: 3.3', ], - install_requires=['testpackage'], + install_requires=open('requirements.txt').readlines(), ) From 2202fc1956928eebec4b4b44205e03bcb006d456 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Fri, 5 Sep 2014 11:40:17 -0400 Subject: [PATCH 04/10] Disable colorized Pylint This was showing up as garbage in my terminal. --- .pylintrc | 2 -- 1 file changed, 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index db9cb80..057fef2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,8 +7,6 @@ disable=I0011,W0142,W0511 [REPORTS] -output-format=colorized - reports=no msg-template={msg_id}:{line:3d},{column}:{msg} From 75df2cb026bca66d5373ef47fa42b449d6b3e4ce Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Fri, 5 Sep 2014 11:44:29 -0400 Subject: [PATCH 05/10] Pylint cleanup --- .pylintrc | 3 ++- foobar/test/test_foobar.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 057fef2..6a906d2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -3,7 +3,8 @@ # I0011: Locally disabling %s # W0142: Used * or ** magic # W0511: TODO in comments -disable=I0011,W0142,W0511 +# R0904: Too many public methods +disable=I0011,W0142,W0511,R0904 [REPORTS] diff --git a/foobar/test/test_foobar.py b/foobar/test/test_foobar.py index 9fe6555..bab5991 100644 --- a/foobar/test/test_foobar.py +++ b/foobar/test/test_foobar.py @@ -1,12 +1,18 @@ #!/usr/bin/env python +"""Sample test module.""" + import unittest class TestFooBar(unittest.TestCase): + + """Sample test class.""" + def test_dependency_import(self): + """Sample test method.""" try: - import testpackage + import testpackage # pylint: disable=W0612 assert True except ImportError: - assert False + self.fail() From 6d4028f1efed93bc2b34a1dc19b091436f0cf935 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 11:53:10 -0400 Subject: [PATCH 06/10] make runner selectable by environment variable --- .travis.yml | 3 +++ Makefile | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eeab73c..5af81c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: python python: - 3.3 - 3.4 +env: +- TEST_RUNNER=nose +- TEST_RUNNER=pytest install: - pip install coveralls scrutinizer-ocular script: make ci diff --git a/Makefile b/Makefile index b749f2d..9d33259 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,10 @@ PYTHON_MINOR := 4 # Test runner settings # Options are: nose, pytest -TEST_RUNNER := nose +ifndef TEST_RUNNER + # Default is 'nose' unless set by environment variable TEST_RUNNER + TEST_RUNNER := nose +endif # Project settings (automatically detected from files/directories) PROJECT := $(patsubst ./%.sublime-project,%, $(shell find . -type f -name '*.sublime-p*')) @@ -88,7 +91,7 @@ depends: .depends-ci .depends-dev .PHONY: .depends-ci .depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_CI): Makefile - $(PIP) install --upgrade pep8 pep257 $(TEST_RUNNER) coverage + $(PIP) install --upgrade pep8 pep257 nose pytest coverage touch $(DEPENDS_CI) # flag to indicate dependencies are installed .PHONY: .depends-dev From 34c49c43b7d03eb079dec360eca07bba0ee32f17 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 13:27:24 -0400 Subject: [PATCH 07/10] use file flag to indicate if chosen test runner is installed --- Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9d33259..8c9b037 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ COVERAGE := $(BIN)/coverage # Flags for PHONY targets DEPENDS_CI := $(ENV)/.depends-ci DEPENDS_DEV := $(ENV)/.depends-dev +DEPENDS_TEST := $(ENV)/.depends-test-$(TEST_RUNNER) ALL := $(ENV)/.all # Main Targets ############################################################### @@ -86,12 +87,18 @@ $(PIP): $(SYS_VIRTUALENV) --python $(SYS_PYTHON) $(ENV) .PHONY: depends -depends: .depends-ci .depends-dev +depends: .depends-ci .depends-dev .depends-test + +.PHONY: .depends-test +.depends-test: $(DEPENDS_TEST) +$(DEPENDS_TEST): Makefile + $(PIP) install $(TEST_RUNNER) + touch $(DEPENDS_TEST) # flag to indicate dependencies are installed .PHONY: .depends-ci -.depends-ci: env Makefile $(DEPENDS_CI) +.depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_TEST) $(DEPENDS_CI): Makefile - $(PIP) install --upgrade pep8 pep257 nose pytest coverage + $(PIP) install --upgrade pep8 pep257 coverage touch $(DEPENDS_CI) # flag to indicate dependencies are installed .PHONY: .depends-dev From 2d5a1b445b5f192e8c2c6c4640e3eca8f5f69af9 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 5 Sep 2014 14:49:50 -0400 Subject: [PATCH 08/10] revert test runner flag changes. update README. --- Makefile | 13 +++---------- README.md | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 8c9b037..80f1c82 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,6 @@ COVERAGE := $(BIN)/coverage # Flags for PHONY targets DEPENDS_CI := $(ENV)/.depends-ci DEPENDS_DEV := $(ENV)/.depends-dev -DEPENDS_TEST := $(ENV)/.depends-test-$(TEST_RUNNER) ALL := $(ENV)/.all # Main Targets ############################################################### @@ -87,18 +86,12 @@ $(PIP): $(SYS_VIRTUALENV) --python $(SYS_PYTHON) $(ENV) .PHONY: depends -depends: .depends-ci .depends-dev .depends-test - -.PHONY: .depends-test -.depends-test: $(DEPENDS_TEST) -$(DEPENDS_TEST): Makefile - $(PIP) install $(TEST_RUNNER) - touch $(DEPENDS_TEST) # flag to indicate dependencies are installed +depends: .depends-ci .depends-dev .PHONY: .depends-ci -.depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_TEST) +.depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_CI): Makefile - $(PIP) install --upgrade pep8 pep257 coverage + $(PIP) install --upgrade pep8 pep257 $(TEST_RUNNER) coverage touch $(DEPENDS_CI) # flag to indicate dependencies are installed .PHONY: .depends-dev diff --git a/README.md b/README.md index 6704a11..2cf9e02 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ To adopt for a new project: * replace `foobar` and `template-python` with your package name * replace `Foobar` with your project name (might be the same as the package) +* set `TEST_RUNNER` in the `Makefile` to your prefered test runner (`nose` or `pytest`) * update the links to point to your code repository and badges * change the license From 71d916c554fec59b6fb66034e11ad4b77d559e21 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Fri, 5 Sep 2014 14:56:01 -0400 Subject: [PATCH 09/10] Ignore pyunit.xml --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9d0329b..72e3942 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ docs/*.png # Testing and coverage results .coverage +pyunit.xml # Build and release directories build From 7b67f7daafe3a7f9e6c5358f4a7ce7be6ad2cda4 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Fri, 5 Sep 2014 15:01:24 -0400 Subject: [PATCH 10/10] Instruct user to remove Travis env lines --- Makefile | 3 +-- README.md | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 80f1c82..7bb2130 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,8 @@ PYTHON_MAJOR := 3 PYTHON_MINOR := 4 # Test runner settings -# Options are: nose, pytest ifndef TEST_RUNNER - # Default is 'nose' unless set by environment variable TEST_RUNNER + # options are: nose, pytest TEST_RUNNER := nose endif diff --git a/README.md b/README.md index 2cf9e02..48864dc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ To adopt for a new project: * replace `foobar` and `template-python` with your package name * replace `Foobar` with your project name (might be the same as the package) -* set `TEST_RUNNER` in the `Makefile` to your prefered test runner (`nose` or `pytest`) +* set `TEST_RUNNER` in the `Makefile` to your preferred test runner (`nose` or `pytest`) +* remove the `TEST_RUNNER` environment lines in `.travis.yml` * update the links to point to your code repository and badges * change the license