Skip to content

Commit

Permalink
Fixing flake8 issues and adding tox job for flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvrbanac committed Apr 13, 2015
1 parent 3d13ba3 commit b05b481
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion specter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def _(msg):
""" Dealing with pylint problems"""
"""Dealing with pylint problems."""
return gettext.gettext(msg)

# Aliasing commonly used classes
Expand Down
32 changes: 18 additions & 14 deletions specter/expect.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import inspect
import functools
import inspect
# Making sure we support 2.7 and 3+
try:
from types import ClassType as ClassObjType
except:
except ImportError:
from types import ModuleType as ClassObjType

from specter import _
Expand All @@ -29,7 +29,7 @@ def __init__(self, target, required=False, src_params=None,
self.custom_msg = None

def serialize(self):
""" Serializes the ExpectAssert object for collection.
"""Serializes the ExpectAssert object for collection.
Warning, this will only grab the available information.
It is strongly that you only call this once all specs and
Expand Down Expand Up @@ -125,10 +125,13 @@ def raise_a(self, exception):
else:
name = type(self.expected).__name__

msg = _('function {func_name} {was} expected to raise "{excpt}"'
''.format(func_name=self.target_src_param,
excpt=name,
was=was))
msg = _(
'function {func_name} {was} expected to raise "{exc}"'.format(
func_name=self.target_src_param,
exc=name,
was=was
)
)
self.custom_msg = msg

def __str__(self):
Expand Down Expand Up @@ -162,7 +165,8 @@ def _add_expect_to_wrapper(obj_to_add):


def expect(obj, caller_args=[]):
""" Primary method for test assertions in Specter
"""Primary method for test assertions in Specter
:param obj: The evaluated target object
:param caller_args: Is only used when using expecting a raised Exception
"""
Expand All @@ -175,7 +179,8 @@ def expect(obj, caller_args=[]):


def require(obj, caller_args=[]):
""" Primary method for test assertions in Specter
"""Primary method for test assertions in Specter
:param obj: The evaluated target object
:param caller_args: Is only used when using expecting a raised Exception
"""
Expand All @@ -188,7 +193,7 @@ def require(obj, caller_args=[]):


def skip(reason):
""" The skip decorator allows for you to always bypass a test.
"""The skip decorator allows for you to always bypass a test.
:param reason: Expects a string
"""
Expand All @@ -212,8 +217,7 @@ def skip_wrapper(*args, **kwargs):


def skip_if(condition, reason=None):
""" The skip_if decorator allows for you to bypass a test given that a
specific condition is met.
"""The skip_if decorator allows for you to bypass a test on conditions
:param condition: Expects a boolean
:param reason: Expects a string
Expand All @@ -227,7 +231,7 @@ def wrapper(func):


def incomplete(test_func):
""" The incomplete decorator behaves much like a normal skip; however,
"""The incomplete decorator behaves much like a normal skip; however,
tests that are marked as incomplete get tracked under a different metric.
This allows for you to create a skeleton around all of your features and
specifications, and track what tests have been written and what
Expand All @@ -248,7 +252,7 @@ def skip_wrapper(*args, **kwargs):


def metadata(**key_value_pairs):
""" The metadata decorator allows for you to tag specific tests with
"""The metadata decorator allows for you to tag specific tests with
key/value data for run-time processing or reporting. The common use case
is to use metadata to tag a test as a positive or negative test type.
Expand Down
12 changes: 6 additions & 6 deletions specter/reporting/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def output_test_case_result(self, test_case, level):
self.use_color)

if test_case.doc and self.output_docstrings:
print_indent_msg(test_case.doc, level+1, status)
print_indent_msg(test_case.doc, level + 1, status)

# Print error if it exists
if test_case.error:
for line in test_case.error:
self.output(line, level+2, TestStatus.FAIL)
self.output(line, level + 2, TestStatus.FAIL)

if status == TestStatus.FAIL or self.show_all:
print_expects(test_case, level, self.use_color)
Expand Down Expand Up @@ -116,14 +116,14 @@ def start_spec(self, evt):

# Output Docstrings if enabled
if evt.payload.doc and self.output_docstrings:
print_indent_msg(evt.payload.doc, level+1)
print_indent_msg(evt.payload.doc, level + 1)

# Warn of duplicates
if isinstance(evt.payload, DataDescribe) and evt.payload.dup_count:
color = ConsoleColors.YELLOW if self.use_color else None
print_indent_msg('Warning: Noticed {0} duplicate data '
'set(s)'.format(evt.payload.dup_count),
level+1, color=color)
level + 1, color=color)

def output(self, msg, indent, status=None):
""" Alias for print_indent_msg with color determined by status."""
Expand Down Expand Up @@ -152,6 +152,6 @@ def print_summary(self):
status = TestStatus.PASS

print_to_screen('\n')
self.output('-'*24, 0, status)
self.output('-' * 24, 0, status)
self.output(msg, 0, status)
self.output('-'*24, 0, status)
self.output('-' * 24, 0, status)
7 changes: 6 additions & 1 deletion specter/reporting/dots.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def print_error(self, wrapper):

if wrapper.error:
for line in wrapper.error:
print_test_msg(line, level+2, TestStatus.FAIL, self.use_color)
print_test_msg(
line,
level + 2,
TestStatus.FAIL,
self.use_color
)

print_expects(wrapper, level, use_color=self.use_color)

Expand Down
2 changes: 1 addition & 1 deletion specter/reporting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def print_expects(test_case, level, use_color=True):

expect_msg = u'{mark} {msg}'.format(mark=mark, msg=expect)

print_test_msg(expect_msg, level+1, status=status)
print_test_msg(expect_msg, level + 1, status=status)

def hardcoded(param):
result = re.match('^(\'|"|\d)', str(param)) is not None
Expand Down
4 changes: 2 additions & 2 deletions specter/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def plugin_filter(cls, other):

@classmethod
def case_filter(cls, obj):
if type(obj) is not types.FunctionType:
if not isinstance(obj, types.FunctionType):
return False

reserved = [
Expand All @@ -401,7 +401,7 @@ def case_filter(cls, obj):

func_name = obj.__name__
return (not func_name.startswith('_') and
not func_name in reserved)
func_name not in reserved)


class Spec(Describe):
Expand Down
2 changes: 1 addition & 1 deletion specter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_numbered_source(lines, line_num, starting_line=0):
end = center + 2 if center + 2 <= len(lines) else len(lines)

orig_src_lines = [line.rstrip('\n') for line in lines[start:end]]
line_range = range(start+1+starting_line, end+1+starting_line)
line_range = range(start + 1 + starting_line, end + 1 + starting_line)
nums_and_source = zip(line_range, orig_src_lines)

traceback_lines = []
Expand Down
3 changes: 2 additions & 1 deletion tests/example_data/example_fixture.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from specter.spec import Spec, fixture
from specter.expect import expect


@fixture
class ExampleTestFixture(Spec):

Expand All @@ -15,4 +16,4 @@ def this_is_a_test(self):
class UsingFixture(ExampleTestFixture):

def another_test(self):
pass
pass
1 change: 1 addition & 0 deletions tools/test-requires
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tox
nose
flake8
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py33,py34,pypy
envlist = py27,py33,py34,pypy,flake8

[testenv]
VIRTUAL_ENV={envdir}
Expand All @@ -14,6 +14,9 @@ deps = -r{toxinidir}/tools/pip-requires
unittest2
importlib

[testenv:flake8]
commands = flake8

[flake8]
ignore = H301
ignore = H301,H405,H702
exclude = .tox,docs,build,setup.py

0 comments on commit b05b481

Please sign in to comment.