4 new revisions:
Revision: e8899182e03a
Author: Pekka Klärck
Date: Sat Nov 5 16:32:49 2011
Log: utils.match: Removed eq_any(...) in favor or any(eq(...)) and
added a ...
http://code.google.com/p/robotframework/source/detail?r=e8899182e03a
Revision: f3a965a0b016
Author: Pekka Klärck
Date: Sat Nov 5 16:41:46 2011
Log: Extracterd (Suite|Test)NamePatterns from robot.result.filter to
robot....
http://code.google.com/p/robotframework/source/detail?r=f3a965a0b016
Revision: c49fed10ff0c
Author: Pekka Klärck
Date: Sat Nov 5 17:00:18 2011
Log: NamePatterns: better api for general usage
http://code.google.com/p/robotframework/source/detail?r=c49fed10ff0c
Revision: 43633d57b647
Author: Pekka Klärck
Date: Sat Nov 5 17:29:09 2011
Log: FromDirectoryPopulator: Use new robot.model.SuiteNamePattern when
matc...
http://code.google.com/p/robotframework/source/detail?r=43633d57b647
==============================================================================
Revision: e8899182e03a
Author: Pekka Klärck
Date: Sat Nov 5 16:32:49 2011
Log: utils.match: Removed eq_any(...) in favor or any(eq(...)) and
added a note about removing match_any too.
http://code.google.com/p/robotframework/source/detail?r=e8899182e03a
Modified:
/atest/resources/TestCheckerLibrary.py
/src/robot/utils/__init__.py
/src/robot/utils/match.py
/tools/libdoc/libdoc.py
/utest/utils/test_match.py
=======================================
--- /atest/resources/TestCheckerLibrary.py Tue Nov 1 01:13:28 2011
+++ /atest/resources/TestCheckerLibrary.py Sat Nov 5 16:32:49 2011
@@ -106,7 +106,7 @@
if len(actual_tests) != len(expected_names):
raise AssertionError("Wrong number of tests." + tests_msg)
for test in actual_tests:
- if utils.eq_any(test.name, expected_names):
+ if any(utils.matches(test.name, name) for name in
expected_names):
print "Verifying test '%s'" % test.name
self.check_test_status(test)
expected_names.remove(utils.normalize(test.name))
@@ -129,7 +129,7 @@
actual_names = [s.name for s in suite.suites]
utils.asserts.assert_equals(len(actual_names),
len(suite_names), 'Wrong number of subsuites')
for expected in suite_names:
- if not utils.eq_any(expected, actual_names):
+ if not any(utils.matches(expected, name) for name in
actual_names):
raise AssertionError('Suite %s not found' % expected)
def should_contain_tags(self, test, *tag_names):
=======================================
--- /src/robot/utils/__init__.py Fri Nov 4 22:14:26 2011
+++ /src/robot/utils/__init__.py Sat Nov 5 16:32:49 2011
@@ -23,7 +23,7 @@
from htmlutils import html_format, html_escape, html_attr_escape
from htmlwriter import HtmlWriter
from importing import simple_import, import_
-from match import eq, eq_any, matches, matches_any, Matcher
+from match import eq, matches, matches_any, Matcher
from misc import plural_or_not, printable_name, seq2str, seq2str2, getdoc
from normalizing import normalize, normalize_tags, NormalizedDict
from robotpath import normpath, abspath, get_link_path
=======================================
--- /src/robot/utils/match.py Fri Nov 4 22:47:41 2011
+++ /src/robot/utils/match.py Sat Nov 5 16:32:49 2011
@@ -24,15 +24,20 @@
return str1 == str2
-def eq_any(str_, str_list, ignore=[], caseless=True, spaceless=True):
- str_ = normalize(str_, ignore, caseless, spaceless)
- for s in str_list:
- if str_ == normalize(s, ignore, caseless, spaceless):
+def matches(string, pattern, ignore=[], caseless=True, spaceless=True):
+ return Matcher(pattern, ignore, caseless, spaceless).match(string)
+
+
+# TODO: matches_any should be removed and any(utils.match(...) for p in
patterns)
+# used instead. Currently mainly used in robot.common.model and can be
removed
+# after that module is nuked.
+def matches_any(string, patterns, ignore=[], caseless=True,
spaceless=True):
+ for pattern in patterns:
+ if matches(string, pattern, ignore, caseless, spaceless):
return True
return False
-
class Matcher(object):
_match_pattern_tokenizer = re.compile('(\*|\?)')
_wildcards = {'*': '.*', '?': '.'}
@@ -56,14 +61,3 @@
def match(self, string):
return self._regexp.match(self._normalize(string)) is not None
-
-
-def matches(string, pattern, ignore=[], caseless=True, spaceless=True):
- return Matcher(pattern, ignore, caseless, spaceless).match(string)
-
-
-def matches_any(string, patterns, ignore=[], caseless=True,
spaceless=True):
- for pattern in patterns:
- if matches(string, pattern, ignore, caseless, spaceless):
- return True
- return False
=======================================
--- /tools/libdoc/libdoc.py Tue Sep 20 05:32:51 2011
+++ /tools/libdoc/libdoc.py Sat Nov 5 16:32:49 2011
@@ -202,9 +202,9 @@
for kw in lib.keywords:
if utils.eq(name, kw.name):
return '<a href="#%s" class="name">%s</a>' % (kw.name,
name)
- if utils.eq_any(name, ['introduction', 'library introduction']):
+ if name.lower() in ['introduction', 'library introduction']:
return '<a href="#introduction" class="name">%s</a>' % name
- if utils.eq_any(name, ['importing', 'library importing']):
+ if name.lower() in ['importing', 'library importing']:
return '<a href="#importing" class="name">%s</a>' % name
return '<span class="name">%s</span>' % name
=======================================
--- /utest/utils/test_match.py Fri Nov 4 22:47:41 2011
+++ /utest/utils/test_match.py Sat Nov 5 16:32:49 2011
@@ -14,11 +14,6 @@
assert not eq("foo", "FOO", caseless=False)
assert not eq("foo", "foo ", spaceless=False)
- def test_eq_any(self):
- assert eq_any("foo", [ "a", "b", " F O O " ], caseless=True,
spaceless=True)
- assert not eq_any("foo", [ "f o o ", "hii", "hoo", "huu", "FOO" ],
- caseless=False, spaceless=False)
-
def test_matches_with_string(self):
for pattern in
['abc','ABC','*','a*','*C','a*c','*a*b*c*','AB?','???',
'?b*','*abc','abc*','*abc*']:
==============================================================================
Revision: f3a965a0b016
Author: Pekka Klärck
Date: Sat Nov 5 16:41:46 2011
Log: Extracterd (Suite|Test)NamePatterns from robot.result.filter to
robot.model.namepatterns
http://code.google.com/p/robotframework/source/detail?r=f3a965a0b016
Added:
/src/robot/model/namepatterns.py
Modified:
/src/robot/model/__init__.py
/src/robot/result/filter.py
=======================================
--- /dev/null
+++ /src/robot/model/namepatterns.py Sat Nov 5 16:41:46 2011
@@ -0,0 +1,54 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# 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.
+
+from robot import utils
+
+
+class _NamePatterns(object):
+
+ def __init__(self, patterns):
+ self._matchers = [utils.Matcher(p, ignore=['_'])
+ for p in self._ensure_list(patterns)]
+
+ def _ensure_list(self, patterns):
+ if patterns is None:
+ return []
+ if isinstance(patterns, basestring):
+ return [patterns]
+ return patterns
+
+ def match(self, item):
+ return self._match(item.name) or
self._match_longname(item.longname)
+
+ def _match(self, name):
+ return any(matcher.match(name) for matcher in self._matchers)
+
+ def __nonzero__(self):
+ return bool(self._matchers)
+
+
+class SuiteNamePatterns(_NamePatterns):
+
+ def _match_longname(self, name):
+ while '.' in name:
+ if self._match(name):
+ return True
+ name = name.split('.', 1)[1]
+ return False
+
+
+class TestNamePatterns(_NamePatterns):
+
+ def _match_longname(self, name):
+ return self._match(name)
=======================================
--- /src/robot/model/__init__.py Fri Nov 4 07:15:54 2011
+++ /src/robot/model/__init__.py Sat Nov 5 16:41:46 2011
@@ -14,3 +14,4 @@
from tags import Tags, TagPatterns
from critical import Critical
+from namepatterns import SuiteNamePatterns, TestNamePatterns
=======================================
--- /src/robot/result/filter.py Sat Nov 5 02:54:53 2011
+++ /src/robot/result/filter.py Sat Nov 5 16:41:46 2011
@@ -14,7 +14,7 @@
from robot import utils
from robot.output.loggerhelper import IsLogged
-from robot.model import TagPatterns
+from robot.model import TagPatterns, SuiteNamePatterns, TestNamePatterns
from visitor import SuiteVisitor
@@ -30,13 +30,13 @@
@utils.setter
def include_suites(self, suites):
- return _SuiteNameFilter(suites) \
- if not isinstance(suites, _SuiteNameFilter) else suites
+ return SuiteNamePatterns(suites) \
+ if not isinstance(suites, SuiteNamePatterns) else suites
@utils.setter
def include_tests(self, tests):
- return _TestNameFilter(tests) \
- if not isinstance(tests, _TestNameFilter) else tests
+ return TestNamePatterns(tests) \
+ if not isinstance(tests, TestNamePatterns) else tests
@utils.setter
def include_tags(self, tags):
@@ -98,45 +98,6 @@
self.include_tags or self.exclude_tags)
-class _NameFilter(object):
-
- def __init__(self, patterns):
- self._matchers = [utils.Matcher(p, ignore=['_'])
- for p in self._ensure_list(patterns)]
-
- def _ensure_list(self, patterns):
- if patterns is None:
- return []
- if isinstance(patterns, basestring):
- return [patterns]
- return patterns
-
- def match(self, item):
- return self._match(item.name) or
self._match_longname(item.longname)
-
- def _match(self, name):
- return any(matcher.match(name) for matcher in self._matchers)
-
- def __nonzero__(self):
- return bool(self._matchers)
-
-
-class _SuiteNameFilter(_NameFilter):
-
- def _match_longname(self, name):
- while '.' in name:
- if self._match(name):
- return True
- name = name.split('.', 1)[1]
- return False
-
-
-class _TestNameFilter(_NameFilter):
-
- def _match_longname(self, name):
- return self._match(name)
-
-
class MessageFilter(SuiteVisitor):
def __init__(self, loglevel):
==============================================================================
Revision: c49fed10ff0c
Author: Pekka Klärck
Date: Sat Nov 5 17:00:18 2011
Log: NamePatterns: better api for general usage
http://code.google.com/p/robotframework/source/detail?r=c49fed10ff0c
Modified:
/src/robot/model/namepatterns.py
/src/robot/result/filter.py
=======================================
--- /src/robot/model/namepatterns.py Sat Nov 5 16:41:46 2011
+++ /src/robot/model/namepatterns.py Sat Nov 5 17:00:18 2011
@@ -17,7 +17,7 @@
class _NamePatterns(object):
- def __init__(self, patterns):
+ def __init__(self, patterns=None):
self._matchers = [utils.Matcher(p, ignore=['_'])
for p in self._ensure_list(patterns)]
@@ -28,8 +28,8 @@
return [patterns]
return patterns
- def match(self, item):
- return self._match(item.name) or
self._match_longname(item.longname)
+ def match(self, name, longname=None):
+ return self._match(name) or longname and
self._match_longname(longname)
def _match(self, name):
return any(matcher.match(name) for matcher in self._matchers)
=======================================
--- /src/robot/result/filter.py Sat Nov 5 16:41:46 2011
+++ /src/robot/result/filter.py Sat Nov 5 17:00:18 2011
@@ -61,7 +61,7 @@
return bool(suite.suites)
def _filter_by_suite_name(self, suite):
- if self.include_suites.match(suite):
+ if self.include_suites.match(suite.name, suite.longname):
suite.visit(Filter(include_suites=[],
include_tests=self.include_tests,
include_tags=self.include_tags,
@@ -76,7 +76,7 @@
yield test
def _included_by_test_name(self, test):
- return self.include_tests.match(test)
+ return self.include_tests.match(test.name, test.longname)
def _included_by_tags(self, test):
return self.include_tags.match(test.tags)
==============================================================================
Revision: 43633d57b647
Author: Pekka Klärck
Date: Sat Nov 5 17:29:09 2011
Log: FromDirectoryPopulator: Use new robot.model.SuiteNamePattern when
matching suite names. Also other cleanup.
http://code.google.com/p/robotframework/source/detail?r=43633d57b647
Modified:
/src/robot/parsing/populators.py
=======================================
--- /src/robot/parsing/populators.py Mon Jun 27 00:04:28 2011
+++ /src/robot/parsing/populators.py Sat Nov 5 17:29:09 2011
@@ -17,6 +17,7 @@
from robot import utils
from robot.output import LOGGER
from robot.errors import DataError
+from robot.model import SuiteNamePatterns
from datarow import DataRow
from tablepopulators import (SettingTablePopulator, VariableTablePopulator,
@@ -107,8 +108,8 @@
def populate(self, path, datadir, include_suites, warn_on_skipped):
LOGGER.info("Parsing test data directory '%s'" % path)
- include_sub_suites = self._get_include_suites(path, include_suites)
- initfile, children = self._get_children(path, include_sub_suites)
+ include_suites = self._get_include_suites(path, include_suites)
+ initfile, children = self._get_children(path, include_suites)
datadir.initfile = initfile
if initfile:
try:
@@ -117,7 +118,7 @@
LOGGER.error(unicode(err))
for child in children:
try:
- datadir.add_child(child, include_sub_suites)
+ datadir.add_child(child, include_suites)
except DataError, err:
self._log_failed_parsing("Parsing data source '%s'
failed: %s"
% (child, unicode(err)), warn_on_skipped)
@@ -128,14 +129,22 @@
else:
LOGGER.info(message)
- def _get_include_suites(self, path, include_suites):
- # If directory is included also all it children should be included
- if
self._is_in_incl_suites(os.path.basename(os.path.normpath(path)),
- include_suites):
- return []
- return include_suites
-
- def _get_children(self, dirpath, include_suites):
+ def _get_include_suites(self, path, incl_suites):
+ if not isinstance(incl_suites, SuiteNamePatterns):
+ # Use only the last part of names given like '--suite
parent.child'
+ incl_suites = SuiteNamePatterns(i.split('.')[-1] for i in
incl_suites)
+ if not incl_suites:
+ return incl_suites
+ # If a directory is included, also all its children should be
included.
+ if self._directory_is_included(path, incl_suites):
+ return SuiteNamePatterns()
+ return incl_suites
+
+ def _directory_is_included(self, path, incl_suites):
+ name = os.path.basename(os.path.normpath(path))
+ return self._is_in_included_suites(name, incl_suites)
+
+ def _get_children(self, dirpath, incl_suites):
initfile = None
children = []
for name, path in self._list_dir(dirpath):
@@ -144,7 +153,7 @@
initfile = path
else:
LOGGER.error("Ignoring second test suite init
file '%s'." % path)
- elif self._is_included(name, path, include_suites):
+ elif self._is_included(name, path, incl_suites):
children.append(path)
else:
LOGGER.info("Ignoring file or directory '%s'." % name)
@@ -163,20 +172,17 @@
base, extension = os.path.splitext(name.lower())
return base == '__init__' and extension[1:] in READERS
- def _is_included(self, name, path, include_suites):
+ def _is_included(self, name, path, incl_suites):
if name.startswith(self.ignored_prefixes):
return False
if os.path.isdir(path):
return name not in self.ignored_dirs
base, extension = os.path.splitext(name.lower())
return (extension[1:] in READERS and
- self._is_in_incl_suites(base, include_suites))
-
- def _is_in_incl_suites(self, name, include_suites):
- if include_suites == []:
- return True
- # Match only to the last part of name given like '--suite
parent.child'
- include_suites = [ incl.split('.')[-1] for incl in include_suites ]
- name = name.split('__', 1)[-1] # Strip possible prefix
- return utils.matches_any(name, include_suites, ignore=['_'])
-
+ self._is_in_included_suites(base, incl_suites))
+
+ def _is_in_included_suites(self, name, incl_suites):
+ return not incl_suites or
incl_suites.match(self._split_prefix(name))
+
+ def _split_prefix(self, name):
+ return name.split('__', 1)[-1]