Skip to content

Commit

Permalink
Merge pull request #165 from zopefoundation/implicit-namespaces
Browse files Browse the repository at this point in the history
Implicit namespaces support
  • Loading branch information
gforcada committed Feb 27, 2024
2 parents a68a866 + 4a41c25 commit 4e98a1e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 70 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
6.4 (unreleased)
================

- Nothing changed yet.

- Add PEP 440 support (implicit namespaces).
(`#160 <https://github.com/zopefoundation/zope.testrunner/issues/160>`_)

6.3.1 (2024-02-12)
==================
Expand Down
16 changes: 9 additions & 7 deletions src/zope/testrunner/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from zope.testrunner.filter import build_filtering_func


identifier = re.compile(r'[_a-zA-Z]\w*$').match
identifier = re.compile(r'[_a-z]\w*$', re.I).match
IGNORE_FOLDERS = {
'.git',
'node_modules',
'__pycache__'
}


class DuplicateTestIDError(Exception):
Expand Down Expand Up @@ -292,13 +297,10 @@ def update_root2ext(dirname, noext, withext):

for (p, package) in test_dirs(options, {}):
for dirname, dirs, files in walk_with_symlinks(options, p):
if dirname != p and not contains_init_py(options, files):
# This is not a plausible test directory. Avoid descending
# further.
del dirs[:]
continue
root2ext = {}
dirs[:] = [d for d in dirs if identifier(d)]
dirs[:] = [
d for d in dirs if identifier(d) and d not in IGNORE_FOLDERS
]
d = os.path.split(dirname)[1]
if tests_pattern(d) and contains_init_py(options, files):
# tests directory
Expand Down
16 changes: 16 additions & 0 deletions src/zope/testrunner/tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ def test_DuplicateTestIDError_message_contains_all_test_ids(self):
self.assertIn(
os.path.join('testrunner-ex', 'sampletestsl.rst'),
str(e.exception))


class TestIdentifierMatches(unittest.TestCase):
"""Test which folders are ignored by the test runner."""

def test_ignored(self):
folders = ('spaces are bad', 'dashes-bad', 'ünicodeLeading')
for name in folders:
self.assertFalse(find.identifier(name), f'{name} is accepted')

def test_accepted(self):
folders = (
'random', 'CamelCase', 'Under_scores', '_leading_scores', 'unicöde'
)
for name in folders:
self.assertTrue(find.identifier(name), f'{name} is not accepted')
4 changes: 3 additions & 1 deletion src/zope/testrunner/tests/testrunner-edge-cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,10 @@ Post-mortem debugging of a docfile doctest failure:

Post-mortem debugging with triple verbosity

>>> sys.stdin = Input('p x\nc')
>>> sys.argv = 'test --layer samplelayers.Layer1$ -vvv -D'.split()
>>> testrunner.run_internal(defaults)
>>> try: testrunner.run_internal(defaults)
... finally: sys.stdin = real_stdin
Running tests at level 1
Running samplelayers.Layer1 tests:
Set up samplelayers.Layer1 in 0.000 seconds.
Expand Down

This file was deleted.

0 comments on commit 4e98a1e

Please sign in to comment.