Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a warning when a yaml filename has an underscore #157

Merged
merged 1 commit into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gabbi/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import unittest
from unittest import suite
import uuid
import warnings

from gabbi import case
from gabbi import exception
from gabbi import handlers
from gabbi import reporter
from gabbi import suitemaker
Expand Down Expand Up @@ -83,6 +85,10 @@ def build_tests(path, loader, host=None, port=8001, intercept=None,

top_suite = suite.TestSuite()
for test_file in glob.iglob('%s/*.yaml' % path):
if '_' in os.path.basename(test_file):
warnings.warn(exception.GabbiSyntaxWarning(
"'_' in test filename %s. This can break suite grouping."
% test_file))
if intercept:
host = str(uuid.uuid4())
suite_dict = utils.load_yaml(yaml_file=test_file)
Expand Down Expand Up @@ -134,7 +140,6 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None,
def test_suite_from_yaml(loader, test_base_name, test_yaml, test_directory,
host, port, fixture_module, intercept, prefix=''):
"""Legacy wrapper retained for backwards compatibility."""
import warnings

with warnings.catch_warnings(): # ensures warnings filter is restored
warnings.simplefilter('default', DeprecationWarning)
Expand Down
5 changes: 5 additions & 0 deletions gabbi/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
class GabbiFormatError(ValueError):
"""An exception to encapsulate poorly formed test data."""
pass


class GabbiSyntaxWarning(SyntaxWarning):
"""A warning about syntax that is not desirable."""
pass
41 changes: 41 additions & 0 deletions gabbi/tests/test_syntax_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Test that the driver warns on bad yaml name."""

import os
import unittest
import warnings

from gabbi import driver
from gabbi import exception


TESTS_DIR = 'warning_gabbits'


class DriverTest(unittest.TestCase):

def setUp(self):
super(DriverTest, self).setUp()
self.loader = unittest.defaultTestLoader
self.test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)

def test_driver_warngs_on_files(self):
with warnings.catch_warnings(record=True) as the_warnings:
driver.build_tests(
self.test_dir, self.loader, host='localhost', port=8001)
self.assertEqual(1, len(the_warnings))
the_warning = the_warnings[-1]
self.assertEqual(
the_warning.category, exception.GabbiSyntaxWarning)
self.assertIn("'_' in test filename", str(the_warning.message))
6 changes: 6 additions & 0 deletions gabbi/tests/warning_gabbits/underscore_sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

tests:
- name: one
url: /
- name: two
url: http://example.com/moo