Skip to content

Commit

Permalink
Formatting cleanups
Browse files Browse the repository at this point in the history
Prompted by flake8 and pylint.
  • Loading branch information
cdent committed Jan 26, 2015
1 parent 85434f4 commit 5a88364
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
14 changes: 9 additions & 5 deletions gabbi/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""A single HTTP request reprensented as a ``unittest.TestCase``
The test case encapsulates the request headers and body and expected
response headers and body. When the test is run an HTTP request is
made using httplib2. Assertions are made against the reponse.
"""

import json
import os
import re

import jsonpath_rw
import unittest
from six.moves.urllib import parse as urlparse
import unittest


class HTTPTestCase(unittest.TestCase):
Expand Down Expand Up @@ -74,8 +80,7 @@ def _assert_response(self, response, content, status, headers=None,
for expect in expected:
self.assertIn(expect, decoded_output)

# Decode body as JSON and compare.
# NOTE(chdent): This just here for now to see if it is workable.
# Decode body as JSON and test against json_paths
if json_paths:
response_data = json.loads(decoded_output)
self.json_data = response_data
Expand Down Expand Up @@ -113,8 +118,7 @@ def _extract_json_path_value(data, path):
return matches[0]
except IndexError:
raise ValueError(
"JSONPath '%s' failed to match on data: '%s'"
% (path, data))
"JSONPath '%s' failed to match on data: '%s'" % (path, data))

def _load_data_file(self, filename):
"""Read a file from the current test directory."""
Expand Down
8 changes: 4 additions & 4 deletions gabbi/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import httplib2
import yaml

from .suite import GabbiSuite
from .case import HTTPTestCase
from gabbi import case
from gabbi import suite as gabbi_suite


# Empty test from which all others inherit
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_suite_from_yaml(loader, test_base_name, test_yaml, test_directory,
host, port, fixture_module, intercept):
"""Generate a TestSuite from YAML data."""

file_suite = GabbiSuite()
file_suite = gabbi_suite.GabbiSuite()
test_data = test_yaml['tests']
fixtures = test_yaml.get('fixtures', None)

Expand Down Expand Up @@ -142,7 +142,7 @@ def test_suite_from_yaml(loader, test_base_name, test_yaml, test_directory,

# Use metaclasses to build a class of the necessary type
# with relevant arguments.
klass = TestBuilder(test_name, (HTTPTestCase,),
klass = TestBuilder(test_name, (case.HTTPTestCase,),
{'test_data': test,
'test_directory': test_directory,
'fixtures': fixture_classes,
Expand Down
26 changes: 13 additions & 13 deletions gabbi/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

"""Manage fixtures for gabbi at the test suite level."""

import contextlib
import sys
from contextlib import contextmanager

import six
import wsgi_intercept
Expand All @@ -44,7 +44,7 @@ class GabbiFixture(object):
def __enter__(self):
self.start_fixture()

def __exit__(self, type, value, traceback):
def __exit__(self, exc_type, value, traceback):
self.stop_fixture()

def start_fixture(self):
Expand Down Expand Up @@ -74,7 +74,7 @@ def stop_fixture(self):
wsgi_intercept.remove_wsgi_intercept(self.host, self.port)


@contextmanager
@contextlib.contextmanager
def nest(fixtures):
"""Nest a series of fixtures.
Expand All @@ -84,25 +84,25 @@ def nest(fixtures):
of fixtures dynamically, so the ``with`` syntax that replaces
``nested`` will not work.
"""
vars = []
contexts = []
exits = []
exc = (None, None, None)
try:
for fixture in fixtures:
enter = fixture.__enter__
exit = fixture.__exit__
vars.append(enter())
exits.append(exit)
yield vars
except:
enter_func = fixture.__enter__
exit_func = fixture.__exit__
contexts.append(enter_func())
exits.append(exit_func)
yield contexts
except Exception:
exc = sys.exc_info()
finally:
while exits:
exit = exits.pop()
exit_func = exits.pop()
try:
if exit(*exc):
if exit_func(*exc):
exc = (None, None, None)
except:
except Exception:
exc = sys.exc_info()
if exc != (None, None, None):
six.reraise(exc[0], exc[1], exc[2])
10 changes: 8 additions & 2 deletions gabbi/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""A TestSuite for containing gabbi tests.
This suite has two features: the contained tests are ordered and there
are suite-level fixtures that operate as context managers.
"""

from unittest import case
from unittest import suite

from . import fixture
from gabbi import fixture


class GabbiSuite(suite.TestSuite):
Expand Down Expand Up @@ -65,6 +70,7 @@ def run(self, result, debug=False):
else:
result = super(GabbiSuite, self).run(result, debug)
except case.SkipTest as exc:
[result.addSkip(test, str(exc)) for test in self._tests]
for test in self._tests:
result.addSkip(test, str(exc))

return result

0 comments on commit 5a88364

Please sign in to comment.