Repository: cdent/gabbi

Issue:
Q: What characters are legal / recommended for test name in YAML?
I suspect plain alphanum + spaces is recommended, but I might sometimes want to do hyphen or parens.  So, just being thorough.

Thanks!


Discussion:

Patch:
diff --git a/gabbi/driver.py b/gabbi/driver.py
index 9cb88fe..22a48c4 100644
--- a/gabbi/driver.py
+++ b/gabbi/driver.py
@@ -29,8 +29,10 @@ import os
 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
@@ -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)
@@ -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)
diff --git a/gabbi/exception.py b/gabbi/exception.py
index 3d4ef45..2bc93e4 100644
--- a/gabbi/exception.py
+++ b/gabbi/exception.py
@@ -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


Test patch:
diff --git a/gabbi/tests/gabbits_intercept/json_extensions.yaml b/gabbi/tests/gabbits_intercept/json-extensions.yaml
similarity index 100%
rename from gabbi/tests/gabbits_intercept/json_extensions.yaml
rename to gabbi/tests/gabbits_intercept/json-extensions.yaml
diff --git a/gabbi/tests/gabbits_intercept/last_url.yaml b/gabbi/tests/gabbits_intercept/last-url.yaml
similarity index 100%
rename from gabbi/tests/gabbits_intercept/last_url.yaml
rename to gabbi/tests/gabbits_intercept/last-url.yaml
diff --git a/gabbi/tests/gabbits_intercept/method_shortcut.yaml b/gabbi/tests/gabbits_intercept/method-shortcut.yaml
similarity index 100%
rename from gabbi/tests/gabbits_intercept/method_shortcut.yaml
rename to gabbi/tests/gabbits_intercept/method-shortcut.yaml
diff --git a/gabbi/tests/test_syntax_warning.py b/gabbi/tests/test_syntax_warning.py
new file mode 100644
index 0000000..529dbf6
--- /dev/null
+++ b/gabbi/tests/test_syntax_warning.py
@@ -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))
diff --git a/gabbi/tests/warning_gabbits/underscore_sample.yaml b/gabbi/tests/warning_gabbits/underscore_sample.yaml
new file mode 100644
index 0000000..185e378
--- /dev/null
+++ b/gabbi/tests/warning_gabbits/underscore_sample.yaml
@@ -0,0 +1,6 @@
+
+tests:
+    - name: one
+      url: /
+    - name: two
+      url: http://example.com/moo