Skip to content

Commit

Permalink
Test tags example
Browse files Browse the repository at this point in the history
Let's move `tags` test script from selftests to examples. With such
change we can use this test in other places, for example in tags
documentation.

Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja committed Sep 12, 2023
1 parent cfce417 commit d582c06
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 79 deletions.
79 changes: 79 additions & 0 deletions examples/tests/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import time

from avocado import Test


class DisabledTest(Test):
"""
:avocado: disable
:avocado: tags=fast,net
"""

def test_disabled(self):
pass


class FastTest(Test):
"""
:avocado: tags=fast
"""

def test_fast(self):
"""
:avocado: tags=net
"""

def test_fast_other(self):
"""
:avocado: tags=net
"""


class SlowTest(Test):
"""
:avocado: tags=slow,disk
"""

def test_slow(self):
time.sleep(1)


class SlowUnsafeTest(Test):
"""
:avocado: tags=slow,disk,unsafe
"""

def test_slow_unsafe(self):
time.sleep(1)


class SafeTest(Test):
"""
:avocado: tags=safe
"""

def test_safe(self):
pass


class SafeX86Test(Test):
"""
:avocado: tags=safe,arch:x86_64
"""

def test_safe_x86(self):
pass


class NoTagsTest(Test):
def test_no_tags(self):
pass


class SafeAarch64Test(Test):
"""
:avocado: tags=safe,arch:aarch64
"""

def test_safe_aarch64(self):
pass
4 changes: 2 additions & 2 deletions selftests/functional/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def test_list_filter_by_tags(self):
)
stdout_lines = result.stdout_text.splitlines()
self.assertIn("TEST TYPES SUMMARY", stdout_lines)
self.assertIn("avocado-instrumented: 2", stdout_lines)
self.assertIn("avocado-instrumented: 4", stdout_lines)
self.assertIn("TEST TAGS SUMMARY", stdout_lines)
self.assertIn("fast: 2", stdout_lines)
self.assertIn("fast: 4", stdout_lines)

@skipOnLevelsInferiorThan(2)
def test_sleep_a_lot(self):
Expand Down
82 changes: 5 additions & 77 deletions selftests/unit/tags.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,17 @@
import os
import stat
import unittest

from avocado.core import resolver, tags
from avocado.utils import script
from selftests.utils import BASEDIR

#: What is commonly known as "0664" or "u=rw,g=rw,o=r"
DEFAULT_NON_EXEC_MODE = (
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH
)


AVOCADO_TEST_TAGS = """from avocado import Test
import time
class DisabledTest(Test):
'''
:avocado: disable
:avocado: tags=fast,net
'''
def test_disabled(self):
pass
class FastTest(Test):
'''
:avocado: tags=fast
'''
def test_fast(self):
'''
:avocado: tags=net
'''
pass
def test_fast_other(self):
'''
:avocado: tags=net
'''
pass
class SlowTest(Test):
'''
:avocado: tags=slow,disk
'''
def test_slow(self):
time.sleep(1)
class SlowUnsafeTest(Test):
'''
:avocado: tags=slow,disk,unsafe
'''
def test_slow_unsafe(self):
time.sleep(1)
class SafeTest(Test):
'''
:avocado: tags=safe
'''
def test_safe(self):
pass
class SafeX86Test(Test):
'''
:avocado: tags=safe,arch:x86_64
'''
def test_safe_x86(self):
pass
class NoTagsTest(Test):
def test_no_tags(self):
pass
class SafeAarch64Test(Test):
'''
:avocado: tags=safe,arch:aarch64
'''
def test_safe_aarch64(self):
pass
"""


AVOCADO_TEST_OK = """from avocado import Test
class PassTest(Test):
Expand Down Expand Up @@ -123,14 +56,9 @@ class DerivedTwo(Derived):

class TagFilter(unittest.TestCase):
def setUp(self):
with script.TemporaryScript(
"tags.py",
AVOCADO_TEST_TAGS,
"avocado_resolver_tag_unittest",
DEFAULT_NON_EXEC_MODE,
) as test_script:
self.result = resolver.resolve([test_script.path])
self.input_file_path = test_script.path
tags_example = os.path.join(BASEDIR, "examples", "tests", "tags.py")
self.result = resolver.resolve([tags_example])
self.input_file_path = tags_example

def test_no_tag_filter(self):
self.assertEqual(len(self.result), 1)
Expand Down

0 comments on commit d582c06

Please sign in to comment.