Skip to content

Commit

Permalink
Merge pull request #3 from dealertrack/boolean-clauses
Browse files Browse the repository at this point in the history
Boolean clauses - 0.3
  • Loading branch information
miki725 committed Feb 20, 2017
2 parents 710a9bd + 0fea04f commit da3204c
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 111 deletions.
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
History
-------

0.3.0 (2017-02-18)
~~~~~~~~~~~~~~~~~~

* **New** ``--skipnose-include`` clauses now can either be ANDed or ORed.

ANDed example::

--skipnose-include=foo --skipnose-include=bar

ORed example::

--skipnose-include=foo:bar

0.2.0 (2016-02-24)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ clean-test-all: clean-test
rm -rf .tox/

lint:
flake8 skipnose tests
flake8 .

test:
nosetests ${NOSE_FLAGS} tests/
Expand Down
33 changes: 30 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests are executed.
Using
-----

Plugin adds 3 configuration options to nosetests:
Plugin adds 3 configuration options to ``nosetests``:

``--with-skipnose``
Required option to enable ``skipnose`` plugin functionality.
Expand Down Expand Up @@ -55,14 +55,41 @@ Plugin adds 3 configuration options to nosetests:

``--skipnose-include``
This option specifies using glob pattern the only folders nosetests
should run. This option can also be provided multiple times and
alternatively can be provided as a ``[,;:]``-delimited
should run. This option can also be provided multiple times.
Each given parameter clause will be ANDed.
Within each parameter ``:`` delimited clauses will be ORed.
In addition this parameter can be provided as a ``[,;:]``-delimited (``[,;]`` for AND and ``[:]`` for OR)
``NOSE_SKIPNOSE_INCLUDE`` environment variable::

$ nosetests --with-skipnose --skipnose-include=foo3 --skipnose-include=sub2foo?
$ # is equivalent to
$ NOSE_SKIPNOSE_INCLUDE=foo3,sub2foo? nosetests --with-skipnose

which would result in only the following folders being included in the tests::

tests/
foo1/
sub1foo1/
...
sub2foo1/
...
foo2/
sub1foo2/
...
sub2foo2/
...
foo3/ <= only this will run
sub1foo3/
...
sub2foo3/ <= only this will run
...

Here is an example when clauses are ORed::

$ nosetests --with-skipnose --skipnose-include=foo3:sub2foo?
$ # is equivalent to
$ NOSE_SKIPNOSE_INCLUDE=foo3:sub2foo? nosetests --with-skipnose

which would result in only the following folders being included in the tests::

tests/
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
exclude = .tox
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def read(fname):


test_requirements = (
read('requirements.txt').splitlines()
+ read('requirements-dev.txt').splitlines()[1:]
read('requirements.txt').splitlines() +
read('requirements-dev.txt').splitlines()[1:]
)


Expand Down
2 changes: 1 addition & 1 deletion skipnose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

__author__ = 'Miroslav Shubernetskiy'
__email__ = '[email protected]'
__version__ = '0.2.0'
__version__ = '0.3.0'
90 changes: 57 additions & 33 deletions skipnose/skipnose.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ def options(self, parser, env=os.environ):
"""
truth = ('true', '1', 'on')
skipnose_on = env.get(self.env_opt, 'False').lower() in truth
skip_include = filter(
bool, re.split(r'[,;:]', env.get(self.env_include_opt, ''))
)
skip_exclude = filter(

skip_include = list(filter(
bool, re.split(r'[,;]', env.get(self.env_include_opt, ''))
))

skip_exclude = list(filter(
bool, re.split(r'[,;:]', env.get(self.env_exclude_opt, ''))
)
))

parser.add_option(
'--with-skipnose',
action='store_true',
default=skipnose_on,
dest='skipnose',
help='skipnose: enable skipnose nose plugin '
'(alternatively, set ${}=1)'
''.format(self.env_opt)
'(alternatively, set ${env}=1)'
''.format(env=self.env_opt)
)
parser.add_option(
'--skipnose-debug',
Expand All @@ -79,24 +81,26 @@ def options(self, parser, env=os.environ):
parser.add_option(
'--skipnose-include',
action='append',
default=list(skip_include),
default=skip_include,
dest='skipnose_include',
help='skipnose: which directory to include in tests '
'using glob syntax.'
'can be specified multiple times. '
'(alternatively, set ${} as [,;:] delimited string)'
''.format(self.env_include_opt)
'Specifying multiple times will AND the clauses. '
'Single parameter ":" delimited clauses will be ORed. '
'Alternatively, set ${env} as [,;] delimited string for '
'AND and [:] for OR.'
''.format(env=self.env_include_opt)
)
parser.add_option(
'--skipnose-exclude',
action='append',
default=list(skip_exclude),
default=skip_exclude,
dest='skipnose_exclude',
help='skipnose: which directory to exclude in tests '
'using glob syntax.'
'can be specified multiple times. '
'(alternatively, set ${} as [,;:] delimited string)'
''.format(self.env_exclude_opt)
'Can be specified multiple times. '
'(alternatively, set ${env} as [,;:] delimited string)'
''.format(env=self.env_exclude_opt)
)
parser.add_option(
'--skipnose-skip-tests',
Expand All @@ -121,7 +125,10 @@ def configure(self, options, conf):
if options.skipnose:
self.enabled = True
self.debug = options.skipnose_debug
self.skipnose_include = options.skipnose_include
self.skipnose_include = list(map(
lambda i: i.split(':'),
options.skipnose_include
))
self.skipnose_exclude = options.skipnose_exclude

if options.skipnose_skip_tests:
Expand Down Expand Up @@ -169,27 +176,18 @@ def wantDirectory(self, dirname):
basename = os.path.basename(dirname)

if self.skipnose_include:
# check all subfolders to see if any of them match
# if yes, then this parent folder should be included
# so that nose can get to the subfolder
subfolders = map(os.path.basename,
list(walk_subfolders(dirname)) + [dirname])
want = any(map(lambda i: fnmatch.filter(subfolders, i),
self.skipnose_include))

# if directory is not wanted then there is a possibility
# it is a subfolder of a wanted directory so
# check against parent folder patterns
if not want:
parts = dirname.split(os.sep)
want = any(map(lambda i: fnmatch.filter(parts, i),
self.skipnose_include))
want = all(map(
lambda i: self._want_directory_by_includes(dirname, i),
self.skipnose_include
))

if self.skipnose_exclude and want is not False:
# exclude the folder if the folder path
# matches any of the exclude patterns
want = not any(map(lambda i: fnmatch.fnmatch(basename, i),
self.skipnose_exclude))
want = not any(map(
lambda i: fnmatch.fnmatch(basename, i),
self.skipnose_exclude
))

if self.debug:
if not want:
Expand All @@ -200,6 +198,32 @@ def wantDirectory(self, dirname):
# normalize boolean to only ``False`` or ``None``
return False if want is False else None

@staticmethod
def _want_directory_by_includes(dirname, includes):
# check all subfolders to see if any of them match
# if yes, then this parent folder should be included
# so that nose can get to the subfolder
subfolders = map(
os.path.basename,
list(walk_subfolders(dirname)) + [dirname]
)
want = any(map(
lambda i: fnmatch.filter(subfolders, i),
includes
))

# if directory is not wanted then there is a possibility
# it is a subfolder of a wanted directory so
# check against parent folder patterns
if not want:
parts = dirname.split(os.sep)
want = any(map(
lambda i: fnmatch.filter(parts, i),
includes
))

return want

def startTest(self, test):
"""
Skip tests when skipnose_skip_tests is provided
Expand Down
Loading

0 comments on commit da3204c

Please sign in to comment.