From 5f009374fd28aba381f375391b70ac131926bd9d Mon Sep 17 00:00:00 2001 From: Kyle Lawlor Date: Mon, 22 Aug 2016 14:52:54 -0400 Subject: [PATCH] Update minitwit & improve testing for examples (#1954) * Update minitwit & improve testing for examples * Related to #1945 * Re-works minitwit to be installed and run as: pip install --editable . export FLASK_APP=minitwit.minitwit export FLASK_DEBUG=1 flask initdb flask run * added flaskr and minitwit to norecursedirs * tests not properly run when using pytest standards * see: http://stackoverflow.com/questions/38313171/configuring-pytest-with-installable-examples-in-a-project * Both flaskr and minitwit now follow pytest standards. * Tests can for them as `py.test` or `python setup.py test` * Update minitwit readme * updates the instructions for running * Fixes for updating the minitwit example - This reverts the changes to the *docs/* (I will file separate PR). - Running the app is now: `export FLASK_APP=minitwit` & `flask run` (After installing the app) * Remove unnecessary comma from flaskr/setup.py --- examples/flaskr/tests/context.py | 6 ------ examples/flaskr/tests/test_flaskr.py | 4 ++-- examples/minitwit/.gitignore | 2 ++ examples/minitwit/MANIFEST.in | 3 +++ examples/minitwit/README | 2 +- examples/minitwit/minitwit/__init__.py | 1 + examples/minitwit/{ => minitwit}/minitwit.py | 0 examples/minitwit/{ => minitwit}/schema.sql | 0 .../minitwit/{ => minitwit}/static/style.css | 0 .../{ => minitwit}/templates/layout.html | 0 .../minitwit/{ => minitwit}/templates/login.html | 0 .../{ => minitwit}/templates/register.html | 0 .../{ => minitwit}/templates/timeline.html | 0 examples/minitwit/setup.cfg | 2 ++ examples/minitwit/setup.py | 16 ++++++++++++++++ examples/minitwit/{ => tests}/test_minitwit.py | 2 +- setup.cfg | 2 +- 17 files changed, 29 insertions(+), 11 deletions(-) delete mode 100644 examples/flaskr/tests/context.py create mode 100644 examples/minitwit/.gitignore create mode 100644 examples/minitwit/MANIFEST.in create mode 100644 examples/minitwit/minitwit/__init__.py rename examples/minitwit/{ => minitwit}/minitwit.py (100%) rename examples/minitwit/{ => minitwit}/schema.sql (100%) rename examples/minitwit/{ => minitwit}/static/style.css (100%) rename examples/minitwit/{ => minitwit}/templates/layout.html (100%) rename examples/minitwit/{ => minitwit}/templates/login.html (100%) rename examples/minitwit/{ => minitwit}/templates/register.html (100%) rename examples/minitwit/{ => minitwit}/templates/timeline.html (100%) create mode 100644 examples/minitwit/setup.cfg create mode 100644 examples/minitwit/setup.py rename examples/minitwit/{ => tests}/test_minitwit.py (99%) diff --git a/examples/flaskr/tests/context.py b/examples/flaskr/tests/context.py deleted file mode 100644 index 3c773332..00000000 --- a/examples/flaskr/tests/context.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys, os - -basedir = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, basedir + '/../') - -from flaskr import flaskr \ No newline at end of file diff --git a/examples/flaskr/tests/test_flaskr.py b/examples/flaskr/tests/test_flaskr.py index 4715c417..663e92e0 100644 --- a/examples/flaskr/tests/test_flaskr.py +++ b/examples/flaskr/tests/test_flaskr.py @@ -9,11 +9,11 @@ :license: BSD, see LICENSE for more details. """ -import pytest import os import tempfile +import pytest +from flaskr import flaskr -from context import flaskr @pytest.fixture def client(request): diff --git a/examples/minitwit/.gitignore b/examples/minitwit/.gitignore new file mode 100644 index 00000000..c3accd82 --- /dev/null +++ b/examples/minitwit/.gitignore @@ -0,0 +1,2 @@ +minitwit.db +.eggs/ diff --git a/examples/minitwit/MANIFEST.in b/examples/minitwit/MANIFEST.in new file mode 100644 index 00000000..973d6586 --- /dev/null +++ b/examples/minitwit/MANIFEST.in @@ -0,0 +1,3 @@ +graft minitwit/templates +graft minitwit/static +include minitwit/schema.sql \ No newline at end of file diff --git a/examples/minitwit/README b/examples/minitwit/README index a2a7f395..4561d836 100644 --- a/examples/minitwit/README +++ b/examples/minitwit/README @@ -31,5 +31,5 @@ ~ Is it tested? - You betcha. Run the `test_minitwit.py` file to + You betcha. Run the `python setup.py test` file to see the tests pass. diff --git a/examples/minitwit/minitwit/__init__.py b/examples/minitwit/minitwit/__init__.py new file mode 100644 index 00000000..0b8bd697 --- /dev/null +++ b/examples/minitwit/minitwit/__init__.py @@ -0,0 +1 @@ +from minitwit import app \ No newline at end of file diff --git a/examples/minitwit/minitwit.py b/examples/minitwit/minitwit/minitwit.py similarity index 100% rename from examples/minitwit/minitwit.py rename to examples/minitwit/minitwit/minitwit.py diff --git a/examples/minitwit/schema.sql b/examples/minitwit/minitwit/schema.sql similarity index 100% rename from examples/minitwit/schema.sql rename to examples/minitwit/minitwit/schema.sql diff --git a/examples/minitwit/static/style.css b/examples/minitwit/minitwit/static/style.css similarity index 100% rename from examples/minitwit/static/style.css rename to examples/minitwit/minitwit/static/style.css diff --git a/examples/minitwit/templates/layout.html b/examples/minitwit/minitwit/templates/layout.html similarity index 100% rename from examples/minitwit/templates/layout.html rename to examples/minitwit/minitwit/templates/layout.html diff --git a/examples/minitwit/templates/login.html b/examples/minitwit/minitwit/templates/login.html similarity index 100% rename from examples/minitwit/templates/login.html rename to examples/minitwit/minitwit/templates/login.html diff --git a/examples/minitwit/templates/register.html b/examples/minitwit/minitwit/templates/register.html similarity index 100% rename from examples/minitwit/templates/register.html rename to examples/minitwit/minitwit/templates/register.html diff --git a/examples/minitwit/templates/timeline.html b/examples/minitwit/minitwit/templates/timeline.html similarity index 100% rename from examples/minitwit/templates/timeline.html rename to examples/minitwit/minitwit/templates/timeline.html diff --git a/examples/minitwit/setup.cfg b/examples/minitwit/setup.cfg new file mode 100644 index 00000000..b7e47898 --- /dev/null +++ b/examples/minitwit/setup.cfg @@ -0,0 +1,2 @@ +[aliases] +test=pytest diff --git a/examples/minitwit/setup.py b/examples/minitwit/setup.py new file mode 100644 index 00000000..1e580216 --- /dev/null +++ b/examples/minitwit/setup.py @@ -0,0 +1,16 @@ +from setuptools import setup + +setup( + name='minitwit', + packages=['minitwit'], + include_package_data=True, + install_requires=[ + 'flask', + ], + setup_requires=[ + 'pytest-runner', + ], + tests_require=[ + 'pytest', + ], +) \ No newline at end of file diff --git a/examples/minitwit/test_minitwit.py b/examples/minitwit/tests/test_minitwit.py similarity index 99% rename from examples/minitwit/test_minitwit.py rename to examples/minitwit/tests/test_minitwit.py index bd58d4dc..50ca26d9 100644 --- a/examples/minitwit/test_minitwit.py +++ b/examples/minitwit/tests/test_minitwit.py @@ -9,9 +9,9 @@ :license: BSD, see LICENSE for more details. """ import os -import minitwit import tempfile import pytest +from minitwit import minitwit @pytest.fixture diff --git a/setup.cfg b/setup.cfg index 69feced4..47c225ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,4 +5,4 @@ release = egg_info -RDb '' universal = 1 [pytest] -norecursedirs = .* *.egg *.egg-info env* artwork docs +norecursedirs = .* *.egg *.egg-info env* artwork docs examples