提交 ca6675bd 编写于 作者: C Cleber Rosa

Test Loader: add the concept of test tags

Inside test classes there may docstrings which may contain tags that
give special meaning. The tags are defined by "🥑 <value>" in a
single line. For now the only two "official" Avocado tags values
exist:

 * enable: the class is an Avocado INSTRUMENTED test, even if it
   doesn't "look like" one.
 * disable: the class is *NOT* an Avocado INSTRUMENTED test, even if
   looks like one.

Changes from v0:
 * Use unittest2 on Python 2.6
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 52c8f93b
......@@ -23,6 +23,7 @@ import fnmatch
import imp
import inspect
import os
import re
import shlex
import sys
......@@ -39,6 +40,28 @@ AVAILABLE = None # Available tests (for listing purposes)
ALL = True # All tests (inicluding broken ones)
#: Gets the tag value from a string. Used to tag a test class in various ways
AVOCADO_DOCSTRING_TAG_RE = re.compile(r'\s*:avocado:\s*(\S+)\s*')
def get_docstring_tag(docstring):
if docstring is None:
return None
result = AVOCADO_DOCSTRING_TAG_RE.search(docstring)
if result is not None:
return result.groups()[0]
def is_docstring_tag_enable(docstring):
result = get_docstring_tag(docstring)
return result == 'enable'
def is_docstring_tag_disable(docstring):
result = get_docstring_tag(docstring)
return result == 'disable'
class LoaderError(Exception):
""" Loader exception """
......
import os
import re
import sys
import unittest
import multiprocessing
import tempfile
import shutil
if sys.version_info[:2] == (2, 6):
import unittest2 as unittest
else:
import unittest
from avocado.core import test
from avocado.core import exceptions
from avocado.core import loader
......@@ -154,5 +159,32 @@ class LoaderTest(unittest.TestCase):
avocado_multiple_tests.remove()
class DocstringTagTests(unittest.TestCase):
def test_longline(self):
docstring = ("This is a very long docstring in a single line. "
"Since we have nothing useful to put in here let's just "
"mention avocado: it's awesome, but that was not a tag. "
"a tag would be something line this: :avocado: enable")
self.assertIsNotNone(loader.get_docstring_tag(docstring))
def test_newlines(self):
docstring = ("\n\n\nThis is a docstring with many new\n\nlines "
"followed by an avocado tag\n"
"\n\n:avocado: enable\n\n")
self.assertIsNotNone(loader.get_docstring_tag(docstring))
def test_enabled(self):
self.assertTrue(loader.is_docstring_tag_enable(":avocado: enable"))
self.assertTrue(loader.is_docstring_tag_enable(":avocado:\tenable"))
self.assertFalse(loader.is_docstring_tag_enable(":AVOCADO: ENABLE"))
self.assertFalse(loader.is_docstring_tag_enable(":avocado: enabled"))
def test_disabled(self):
self.assertTrue(loader.is_docstring_tag_disable(":avocado: disable"))
self.assertTrue(loader.is_docstring_tag_disable(":avocado:\tdisable"))
self.assertFalse(loader.is_docstring_tag_disable(":AVOCADO: DISABLE"))
self.assertFalse(loader.is_docstring_tag_disable(":avocado: disabled"))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册