Skip to content

Commit

Permalink
Update project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jul 23, 2015
1 parent 20b6901 commit 2edafbf
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 67 deletions.
22 changes: 7 additions & 15 deletions .pylintrc
@@ -1,23 +1,15 @@
[MESSAGES CONTROL]

# I0011: Locally disabling warning
# W0142: Used * or ** magic
# W0511: TODO in comments
# RO903: Too few public methods
# R0904: Too many public methods
# C0103: Invalid constant name
# W0603: Using the global statement
# R0901: Too many ancestors
disable=I0011,W0142,W0511,R0903,R0904,C0103,W0603,R0901

[REPORTS]

reports=no

msg-template={msg_id}:{line:3d},{column}:{msg}
disable=locally-disabled,fixme,too-few-public-methods,too-many-public-methods,invalid-name,global-statement,too-many-ancestors

[FORMAT]

max-line-length=80

ignore-long-lines=^.*((https?:)|(pragma:)|(TODO:)).*$

[REPORTS]

reports=no

msg-template={msg_id} ({symbol}):{line:3d},{column}: {msg}
7 changes: 6 additions & 1 deletion .travis.yml
@@ -1,10 +1,15 @@
sudo: false

language: python
python: 3.4
python:
- 3.4

cache: pip

env:
global:
- RANDOM_SEED=12345

install:
- pip install coveralls scrutinizer-ocular

Expand Down
22 changes: 11 additions & 11 deletions Makefile
Expand Up @@ -100,6 +100,11 @@ launch: env
validate: env
CONFIG=$(CONFIG) $(PYTHON) manage.py validate

.PHONY: watch
watch: depends-dev .clean-test
@ rm -rf $(FAILED_FLAG)
$(SNIFFER)

# Development Installation #####################################################

.PHONY: env
Expand Down Expand Up @@ -175,34 +180,34 @@ check: pep8 pep257 pylint

.PHONY: pep8
pep8: depends-ci
$(PEP8) $(PACKAGE) --config=.pep8rc
$(PEP8) $(PACKAGE) tests --config=.pep8rc

.PHONY: pep257
pep257: depends-ci
# D102: docstring missing (checked by PyLint)
# D202: No blank lines allowed *after* function docstring (personal preference)
# D203: 1 blank line required before class (deprecated warning)
$(PEP257) $(PACKAGE) --ignore=D100,D101,D102,D103,D202,D203
$(PEP257) $(PACKAGE) tests --ignore=D100,D101,D102,D103,D202,D203

.PHONY: pylint
pylint: depends-ci
# These warnings shouldn't fail builds, but warn in editors:
# C0111: Line too long
# R0913: Too many arguments
# R0914: Too many local variables
$(PYLINT) $(PACKAGE) --rcfile=.pylintrc --disable=C0111,R0913,R0914
$(PYLINT) $(PACKAGE) tests --rcfile=.pylintrc --disable=C0111,R0913,R0914

.PHONY: fix
fix: depends-dev
$(PEP8RADIUS) --docformatter --in-place

# Testing ######################################################################

TIMESTAMP := $(shell date +%s)
RANDOM_SEED ?= $(shell date +%s)

PYTEST_CORE_OPTS := --doctest-modules --verbose -r X --maxfail=3
PYTEST_COV_OPTS := --cov=$(PACKAGE) --cov-report=term-missing --no-cov-on-fail
PYTEST_RANDOM_OPTS := --random --random-seed=$(TIMESTAMP)
PYTEST_RANDOM_OPTS := --random --random-seed=$(RANDOM_SEED)

PYTEST_OPTS := $(PYTEST_CORE_OPTS) $(PYTEST_COV_OPTS) $(PYTEST_RANDOM_OPTS)
PYTEST_OPTS_FAILFAST := $(PYTEST_OPTS) --failed --exitfirst
Expand Down Expand Up @@ -244,16 +249,11 @@ endif
read-coverage:
$(OPEN) htmlcov/index.html

.PHONY: watch
watch: depends-dev .clean-test
@ rm -rf $(FAILED_FLAG)
$(SNIFFER)

# Cleanup ######################################################################

.PHONY: clean
clean: .clean-dist .clean-test .clean-doc .clean-build
rm -rf $(ALL)
rm -rf $(ALL_FLAG)

.PHONY: clean-env
clean-env: clean
Expand Down
76 changes: 53 additions & 23 deletions scent.py
Expand Up @@ -11,47 +11,77 @@
notify = Notifier.notify


watch_paths = ['memegen/', 'tests/', 'data/']
show_coverage = True
watch_paths = ['memegen/', 'tests/']


@select_runnable('python_tests')
@select_runnable('python')
@file_validator
def py_files(filename):
return all((filename.endswith('.py') or filename.endswith('.yml'),
not os.path.basename(filename).startswith('.')))


@runnable
def python_tests(*_):

group = int(time.time()) # unique per run
def python(*_):

for count, (command, title) in enumerate((
(('make', 'test-unit'), "Unit Tests"),
(('make', 'test-all'), "Integration Tests"),
(('make', 'test'), "Unit Tests"),
(('make', 'tests'), "Integration Tests"),
(('make', 'check'), "Static Analysis"),
(('make', 'validate'), "Meme Validation"),
(('make', 'doc'), None),
), start=1):

print("")
print("$ %s" % ' '.join(command))
failure = subprocess.call(command)
if not run(command, title, count):
return False

return True


if failure:
if notify and title:
mark = "❌" * count
notify(mark + " [FAIL] " + mark, title=title, group=group)
GROUP = int(time.time()) # unique per run

_show_coverage = True
_rerun_args = None


def run(command, title, count):
global _rerun_args

if _rerun_args:
args = _rerun_args
_rerun_args = None
if not run(*args):
return False
else:
if notify and title:
mark = "✅" * count
notify(mark + " [PASS] " + mark, title=title, group=group)

global show_coverage # pylint: disable=W0603
if show_coverage:
print("")
print("$ %s" % ' '.join(command))
failure = subprocess.call(command)

if failure:
mark = "❌" * count
message = mark + " [FAIL] " + mark
else:
mark = "✅" * count
message = mark + " [PASS] " + mark
show_notification(message, title)

show_coverage()

if failure:
_rerun_args = command, title, count

return not failure


def show_notification(message, title):
if notify and title:
notify(message, title=title, group=GROUP)


def show_coverage():
global _show_coverage

if _show_coverage:
subprocess.call(['make', 'read-coverage'])
show_coverage = False

return True
_show_coverage = False
15 changes: 3 additions & 12 deletions tests/conftest.py
@@ -1,3 +1,5 @@
# pylint: disable=redefined-outer-name

import json
import logging

Expand All @@ -6,18 +8,7 @@
from memegen.app import create_app
from memegen.settings import get_config


def pytest_configure(config):
terminal = config.pluginmanager.getplugin('terminal')

class QuietReporter(terminal.TerminalReporter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.verbosity = 0
self.showlongtestinfo = False
self.showfspath = False

terminal.TerminalReporter = QuietReporter
from memegen.test.conftest import pytest_configure # pylint: disable=unused-import


def load(response, as_json=True, key=None):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_routes_image.py
@@ -1,3 +1,5 @@
# pylint: disable=no-self-use

import os

from .conftest import load
Expand All @@ -8,7 +10,6 @@

class TestImage:


def test_get_visible_jpg(self, client):
path = os.path.join(ROOT, 'data', 'images', 'iw', 'hello', 'world.jpg')
if os.path.exists(path):
Expand Down Expand Up @@ -62,4 +63,4 @@ def test_get_redirects_when_jpeg_with_text(self, client):
response = client.get("/iw/hello/world.jpeg")
assert response.status_code == 302
assert '<a href="/iw/hello/world.jpg">' in \
load(response, as_json=False)
load(response, as_json=False)
5 changes: 3 additions & 2 deletions tests/test_routes_links.py
@@ -1,4 +1,4 @@
# pylint: disable=R,C
# pylint: disable=no-self-use

from .conftest import load

Expand Down Expand Up @@ -54,7 +54,8 @@ def test_get_redirects_when_masked_with_1_line(self, client):
def test_get_redirects_to_default(self, client):
response = client.get("/live")
assert response.status_code == 302
assert '<a href="/live/_/do-it-live%7Ee">' in load(response, as_json=False)
assert '<a href="/live/_/do-it-live%7Ee">' in \
load(response, as_json=False)

def test_get_redirects_when_alias(self, client):
response = client.get("/insanity-wolf")
Expand Down
4 changes: 3 additions & 1 deletion tests/test_routes_root.py
@@ -1,3 +1,5 @@
# pylint: disable=no-self-use

from .conftest import load

GITHUB_BASE = "http://github.com/jacebrowning/memegen/"
Expand All @@ -10,7 +12,7 @@ def test_get_root(self, client):
assert response.status_code == 200
assert dict(
home="http://localhost/",
templates="http://localhost/templates/",
templates="http://localhost/templates/",
overview="http://localhost/overview",
source=GITHUB_BASE,
contributing=GITHUB_BASE + "blob/master/CONTRIBUTING.md",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_routes_static.py
@@ -1,3 +1,5 @@
# pylint: disable=no-self-use

from .conftest import load


Expand Down
2 changes: 2 additions & 0 deletions tests/test_routes_templates.py
@@ -1,3 +1,5 @@
# pylint: disable=no-self-use

from .conftest import load


Expand Down

0 comments on commit 2edafbf

Please sign in to comment.