Skip to content

Commit

Permalink
Merge pull request django-pylibmc#53 from edmorley/flake8
Browse files Browse the repository at this point in the history
Add flake8 to the Travis run
  • Loading branch information
jwhitlock authored Apr 6, 2018
2 parents 0885019 + 2129995 commit 7fa7dbf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ script: tox
# while minimizing the work TravisCI does with each build.
matrix:
include:
- env: TOXENV=lint
python: "2.7"
- env: TOXENV=py27-django18
python: "2.7"
- env: TOXENV=py34-django18
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ branch = True
source = django_pylibmc,tests

[flake8]
exclude = .tox/*,build/*
exclude = .git,.tox,__pycache__,build,dist
max-line-length = 120

[bdist_wheel]
universal = 1

2 changes: 2 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from django.db import models
from datetime import datetime


def expensive_calculation():
expensive_calculation.num_runs += 1
return datetime.now()


class Poll(models.Model):
question = models.CharField(max_length=200)
answer = models.CharField(max_length=200)
Expand Down
28 changes: 14 additions & 14 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import unicode_literals

import time
import unittest
from unittest import skipIf

import django
from django.core import signals
Expand Down Expand Up @@ -95,10 +95,10 @@ def test_delete(self):
def test_has_key(self):
# The cache can be inspected for cache keys
self.cache.set("hello1", "goodbye1")
self.assertTrue(self.cache.has_key("hello1"))
self.assertFalse(self.cache.has_key("goodbye1"))
self.assertTrue(self.cache.has_key("hello1")) # noqa: W601
self.assertFalse(self.cache.has_key("goodbye1")) # noqa: W601
self.cache.set("no_expiry", "here", None)
self.assertTrue(self.cache.has_key("no_expiry"))
self.assertTrue(self.cache.has_key("no_expiry")) # noqa: W601

def test_in(self):
# The in operator can be used to inspet cache contents
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_expiration(self):

self.cache.add("expire2", "newvalue")
self.assertEqual(self.cache.get("expire2"), "newvalue")
self.assertFalse(self.cache.has_key("expire3"))
self.assertFalse(self.cache.has_key("expire3")) # noqa: W601

def test_unicode(self):
# Unicode values can be cached
Expand Down Expand Up @@ -369,9 +369,9 @@ def test_cache_versioning_has_key(self):
self.cache.set('answer1', 42)

# has_key
self.assertTrue(self.cache.has_key('answer1'))
self.assertTrue(self.cache.has_key('answer1', version=1))
self.assertFalse(self.cache.has_key('answer1', version=2))
self.assertTrue(self.cache.has_key('answer1')) # noqa: W601
self.assertTrue(self.cache.has_key('answer1', version=1)) # noqa: W601
self.assertFalse(self.cache.has_key('answer1', version=2)) # noqa: W601

def test_cache_versioning_delete(self):
self.cache.set('answer1', 37, version=1)
Expand Down Expand Up @@ -457,30 +457,30 @@ def test_set_fail_on_pickleerror(self):
with self.assertRaises(pickle.PickleError):
self.cache.set('unpicklable', Unpicklable())

@unittest.skipIf(django.VERSION < (1, 11),
'get_or_set with `None` not supported (Django ticket #26792)')
@skipIf(django.VERSION < (1, 11),
'get_or_set with `None` not supported (Django ticket #26792)')
def test_get_or_set(self):
self.assertIsNone(self.cache.get('projector'))
self.assertEqual(self.cache.get_or_set('projector', 42), 42)
self.assertEqual(self.cache.get('projector'), 42)
self.assertEqual(self.cache.get_or_set('null', None), None)

@unittest.skipIf(django.VERSION < (1, 9), 'get_or_set not supported')
@skipIf(django.VERSION < (1, 9), 'get_or_set not supported')
def test_get_or_set_callable(self):
def my_callable():
return 'value'

self.assertEqual(self.cache.get_or_set('mykey', my_callable), 'value')
self.assertEqual(self.cache.get_or_set('mykey', my_callable()), 'value')

@unittest.skipIf(django.VERSION < (1, 9), 'get_or_set not supported')
@skipIf(django.VERSION < (1, 9), 'get_or_set not supported')
def test_get_or_set_callable_returning_none(self):
self.assertIsNone(self.cache.get_or_set('mykey', lambda: None))
# Previous get_or_set() doesn't store None in the cache.
self.assertEqual(self.cache.get('mykey', 'default'), 'default')

@unittest.skipIf(django.VERSION < (1, 11),
'get_or_set with `None` not supported (Django ticket #26792)')
@skipIf(django.VERSION < (1, 11),
'get_or_set with `None` not supported (Django ticket #26792)')
def test_get_or_set_version(self):
msg = (
"get_or_set() missing 1 required positional argument: 'default'"
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[tox]
envlist =
lint
py{27,34,35}-django{18,19,110}
py{27,34,35,36}-django111
py{35,36}-django20
Expand All @@ -21,3 +22,8 @@ deps =
django-master: https://github.com/django/django/archive/master.tar.gz
pylibmc>=1.4.1
mock

[testenv:lint]
skipsdist = True
commands = flake8 --show-source
deps = flake8==3.5.0

0 comments on commit 7fa7dbf

Please sign in to comment.