Skip to content

Commit

Permalink
set up CI environment
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofgentoo committed Feb 28, 2023
1 parent 2ff3581 commit 0a2a76c
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .circleci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifacts
test-reports
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2
jobs:
build:
docker:
- image: level12/python-test-multi
steps:
- checkout

- run:
name: folder listing for debugging
command: ls -al

- run:
name: install tox
command: pip install tox

- run:
name: version checks
command: |
python --version
pip --version
virtualenv --version
tox --version
- run:
name: run tox
command: tox

- store_test_results:
path: .circleci/test-reports/

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
docs/_build
Flask_WebTest.egg-info
__pycache__
tests/__pycache__
build
dist
.tox
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
-e .[test]
2 changes: 1 addition & 1 deletion flask_webtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def do_request(self, *args, **kwargs):
if self.use_session_scopes:
scope = SessionScope(self.db)
scope.push()

context = nullcontext
if self.app.config.get('FLASK_WEBTEST_PUSH_APP_CONTEXT', False):
context = self.app.app_context
Expand Down
15 changes: 10 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* `development version
<http://github.com/aromanovich/flask-webtest/zipball/master#egg=Flask-WebTest-dev>`_
"""
from setuptools import setup
from setuptools import setup, find_packages


setup(
Expand All @@ -23,18 +23,23 @@
long_description=__doc__,
author='Anton Romanovich',
author_email='[email protected]',
py_modules=['flask_webtest'],
test_suite='tests.test',
tests_require=['Flask-SQLAlchemy>=2.5.0'],
include_package_data=True,
packages=find_packages(exclude=[]),
zip_safe=False,
install_requires=[
'Flask>=2.1.0',
'Flask>=1.1.0',
'WebTest',
'blinker',
],
extras_require={
'tests': [
'flask-sqlalchemy',
],
},
classifiers=[
'Topic :: Software Development :: Testing',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
],
)
25 changes: 25 additions & 0 deletions stable-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
attrs==22.2.0
beautifulsoup4==4.11.2
blinker==1.5
click==8.1.3
exceptiongroup==1.1.0
Flask==2.2.3
Flask-SQLAlchemy==3.0.3
greenlet==2.0.2
importlib-metadata==6.0.0
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
packaging==23.0
pluggy==1.0.0
pytest==7.2.1
soupsieve==2.4
SQLAlchemy==2.0.4
tomli==2.0.1
typing_extensions==4.5.0
waitress==2.1.2
WebOb==1.8.7
WebTest==3.0.0
Werkzeug==2.2.3
zipp==3.15.0
12 changes: 9 additions & 3 deletions tests/core_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, request
from flask import Flask, abort, request
from flask_sqlalchemy import SQLAlchemy
from flask_webtest import get_scopefunc

Expand All @@ -12,6 +12,7 @@ def make_db(app):

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.testing = True
db = make_db(app)

Expand All @@ -27,12 +28,17 @@ def greet(self):

@app.route('/user/<int:id>/')
def user(id):
return User.query.get_or_404(id).greet()
user = db.session.get(User, id)
if not user:
return abort(404)
return user.greet()


@app.route('/user/<int:id>/preview/', methods=['POST'])
def preview(id):
user = User.query.get_or_404(id)
user = db.session.get(User, id)
if not user:
return abort(404)
user.greeting = request.form['greeting']
db.session.expunge(user)
return user.greet()
24 changes: 6 additions & 18 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from .core import app as app1
from .core_sqlalchemy import app as app2, db, User

try:
from flask.signals import message_flashed
except ImportError:
flask_gte_0_10 = False
else:
flask_gte_0_10 = True


class TestMainFeatures(unittest.TestCase):
def setUp(self):
Expand All @@ -32,17 +25,12 @@ def test_two_templates_and_flash_messages(self):
r = self.w.get('/').form.submit()
self.assertEqual(len(r.contexts), 2)

if flask_gte_0_10:
self.assertEqual(len(r.flashes), 2)
category, message = r.flashes[0]
self.assertEqual(message, 'You have pressed "Quit"...')

category, message = r.flashes[1]
self.assertEqual(message, 'Flash message that will never be shown')
else:
self.assertEqual(len(r.flashes), 1)
category, message = r.flashes[0]
self.assertEqual(message, 'You have pressed "Quit"...')
self.assertEqual(len(r.flashes), 2)
category, message = r.flashes[0]
self.assertEqual(message, 'You have pressed "Quit"...')

category, message = r.flashes[1]
self.assertEqual(message, 'Flash message that will never be shown')

with self.assertRaises(AssertionError):
r.context # Because there are more than one used templates
Expand Down
50 changes: 50 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[tox]
envlist = py37-base,py39-lowest,py{38,39,310}-{base,stable},project,docs


[testenv]
# Ignore all "not installed in testenv" warnings.
allowlist_externals = *
skip_install = true
# Force recreation of virtualenvs for each run. When testing in CI, this won't matter b/c the
# virtualenvs won't exist in the container. When testing locally, if you've ran tox previously
# then the libraries in the tox virtualenv won't get updated on pip-install. That means CI will
# test different library versions than you are testing locally. Recreating virtualenvs should
# prevent most of that mismatch.
recreate=False
commands =
pip --version
lowest: pip install flask<2.0.0 sqlalchemy~=1.4.1 flask-sqlalchemy~=2.5.1 markupsafe<2.1.0
stable: pip install --progress-bar off -r ./stable-requirements.txt
pip install --progress-bar off .[tests]
# Output installed versions to compare with previous test runs in case a dependency's change
# breaks things for our build.
pip freeze
./test.sh

[testenv:project]
basepython = python3.9
skip_install = true
usedevelop = false
deps =
flake8
twine
commands =
# check-manifest --ignore tox.ini,tests*
python setup.py sdist
twine check dist/*
flake8 flask_webtest.py tests

[flake8]
exclude = .tox,*egg,build,.git,dist,docs
max-line-length = 100
ignore = E265,E123,E133,E226,E241,E242

[testenv:docs]
basepython = python3.9
recreate = false
skip_install = false
usedevelop = true
commands =
pip install -r docs/requirements.txt
make -C docs/ html

0 comments on commit 0a2a76c

Please sign in to comment.