Permalink
Browse files

Fix pep8 issues

Set the maximum line length to 100 as a better default

Fixes #27
  • Loading branch information...
abadger committed Oct 19, 2017
1 parent b794de3 commit 9e55f3ae8e7f7f7ab327dbb2e2ae7d2ca87d09a7
@@ -22,10 +22,6 @@ matrix:
env: TOXENV=py3flake8
- python: 2.7
env: TOXENV=py2flake8
- python: 3.6
env: TOXENV=py3pyflakes
- python: 2.7
env: TOXENV=py2pyflakes

install:
- travis_retry pip install tox
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 100

[pycodestyle]
max-line-length = 100

[pep8]
max-line-length = 100
@@ -6,11 +6,12 @@
# an arbitrary but consistent time
when = time.struct_time((2010, 10, 28, 2, 15, 57, 3, 301, 0))


def make_mesg():
return Message(twiggy.levels.DEBUG,
"Hello {0} {who}",
{'shirt':42, 'name': 'jose'},
{'shirt': 42, 'name': 'jose'},
Message._default_options,
args=["Mister"],
kwargs={'who':"Funnypants"},
kwargs={'who': "Funnypants"},
)
@@ -1,20 +1,24 @@
import sys

from twiggy.lib.converter import Converter, ConversionTable, same_item, same_value, drop

if sys.version_info >= (2, 7):
import unittest
else:
try:
try:
import unittest2 as unittest
except ImportError:
raise RuntimeError("unittest2 is required for Python < 2.7")

from twiggy.lib.converter import Converter, ConversionTable, same_item, same_value, drop


def conv_val(x):
return x


def conv_item(x, y):
return x, y


class HelperTestCase(unittest.TestCase):

def test_drop(self):
@@ -27,17 +31,19 @@ def test_same_value(self):
def test_same_item(self):
o1 = object()
o2 = object()
x1, x2 = same_item(o1, o2)

x1, x2 = same_item(o1, o2)
assert o1 is x1
assert o2 is x2


class ConverterTestCase(unittest.TestCase):

def test_repr(self):
c = Converter("pants", conv_val, conv_item)
assert repr(c) == "<Converter('pants')>"


class ConversionTableTestCase(unittest.TestCase):

def test_init_None(self):
@@ -112,14 +118,13 @@ def test_duplicate(self):

def test_get(self):
c = Converter("pants", conv_val, conv_item)

ct = ConversionTable([c,
("shirt", conv_val, conv_item, True)])

assert ct.get("belt") is None
assert ct.get("pants") is c


def test_get_all_no_match(self):
ct = ConversionTable([("pants", conv_val, conv_item),
("shirt", conv_val, conv_item, True)])
@@ -132,30 +137,29 @@ def test_convert(self):
ct = ConversionTable([
("joe", "I wear {0}".format, conv_item),
("frank", "You wear {0}".format, conv_item)])

ct.generic_value = "Someone wears {0}".format
d = ct.convert({'joe':'pants', 'frank':'shirt', 'bob':'shoes'})

d = ct.convert({'joe': 'pants', 'frank': 'shirt', 'bob': 'shoes'})
self.assertDictEqual(d, {'joe': "I wear pants", 'frank': "You wear shirt", 'bob': "Someone wears shoes"})

def test_drop(self):
ct = ConversionTable([
("joe", "I wear {0}".format, conv_item),
("frank", "You wear {0}".format, lambda k, v: None)])

ct.generic_item = drop

d = ct.convert({'joe':'pants', 'frank':'shirt', 'bob':'shoes'})
assert d == {'joe': "I wear pants"}

d = ct.convert({'joe': 'pants', 'frank': 'shirt', 'bob': 'shoes'})
assert d == {'joe': "I wear pants"}

def test_generic(self):
c = Converter("pants", conv_val, conv_item)
ct = ConversionTable([c])
assert ct.convert({'shirt':42}) == {'shirt':42}
assert ct.convert({'shirt': 42}) == {'shirt': 42}

def test_missing(self):
c = Converter("pants", conv_val, conv_item, True)
ct = ConversionTable([c])
with self.assertRaises(ValueError):
ct.convert({'shirt':42}) == {'shirt':42}
ct.convert({'shirt': 42}) == {'shirt': 42}
@@ -1,22 +1,23 @@
import sys
import re

from twiggy import filters, levels

from . import make_mesg

if sys.version_info >= (2, 7):
import unittest
else:
try:
try:
import unittest2 as unittest
except ImportError:
raise RuntimeError("unittest2 is required for Python < 2.7")

import re

from twiggy import filters, levels

from . import make_mesg

m = make_mesg()

class MsgFilterTestCase(unittest.TestCase):

class MsgFilterTestCase(unittest.TestCase):
# XXX more robust testing of the exact type/func.__name__ of the returned f
# might be nice (instead of just callable), but eh.

@@ -52,10 +53,13 @@ def test_regex(self):
assert callable(f)
assert not f(m)

@staticmethod
def _always_true(mesg):
return True

def test_callable(self):
my_func = lambda mesg: True
f = filters.msg_filter(my_func)
assert f is my_func
f = filters.msg_filter(self._always_true)
assert f is self._always_true

def test_bad_arg(self):
with self.assertRaises(ValueError):
@@ -68,7 +72,7 @@ def test_list(self):
f = filters.msg_filter(l)
assert callable(f)
assert f(m)

re3 = "^.*Sillyhead$"
l = (re1, re3)
f = filters.msg_filter(l)
@@ -83,7 +87,7 @@ def test_nested_list(self):
f = filters.msg_filter(l)
assert callable(f)
assert f(m)

def test_single_list(self):
re1 = "^Hello.*$"
l = [re1]
@@ -108,6 +112,7 @@ def test_glob_names(self):
assert filters.glob_names("jo*", "frank")(m)
assert not filters.glob_names("*bob", "frank")(m)


class EmitterTestCase(unittest.TestCase):

def test_bad_min_level(self):
Oops, something went wrong.

0 comments on commit 9e55f3a

Please sign in to comment.