This module is largely just posixpath (sometimes the functions are
renamed), with a couple of unique functions, which are basically
wrappers around posixpath functions with some special exceptions. Having
and using the module presents the advantage of being able to change the
implementation, including how the groups are manipulated. It also is
clearer than working with posixpath directly.
Signed-off-by: Dylan Baker <[email protected]>
---
framework/grouptools.py | 151 +++++++++++++++++++++++++++++++
framework/tests/grouptools_tests.py | 174
++++++++++++++++++++++++++++++++++++
2 files changed, 325 insertions(+)
create mode 100644 framework/grouptools.py
create mode 100644 framework/tests/grouptools_tests.py
diff --git a/framework/grouptools.py b/framework/grouptools.py
new file mode 100644
index 0000000..64e08b7
--- /dev/null
+++ b/framework/grouptools.py
@@ -0,0 +1,151 @@
+# Copyright (c) 2014 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+"""Module providing utility functions to work with piglit groups.
+
+Instead of using posixpath (or the generic os.path) for working with tests this
+module should be prefered.
+
+Piglit groups look much like posix paths, they are '/' delimited with each
+element representing a group, and the final element being the test name. Unlike
+posix paths they may not start with a leading '/'.
+
+"""
+
+import posixpath
+
+__all__ = [
+ 'join',
+ 'commonprefix',
+ 'relgroup',
+ 'split',
+ 'groupname',
+ 'testname',
+ 'splitname',
+ 'from_path'
+]
+
+
+def testname(group):
+ """Return the last element of a group name.
+
+ Provided the value 'group1/group2/test1' will provide 'test1', this
+ does not enforce any rules that the final element is a test name, and can
+ be used to shaved down groups.
+
+ Analogous to os.path.basename
+
+ """
+ assert '\\' not in group, 'Groups are not paths and cannot contain \\'
+ assert not group.startswith('/'), 'Groups cannot start with /'
+
+ return posixpath.basename(group)
+
+
+def groupname(group):
+ """Return all groups except the last.
+
+ Provided the value 'group1/group2/test1' will provide 'group1/group2', this
+ does not enforce any rules that the final element is a test name, and can
+ be used to shaved down groups.
+
+ Analogous to os.path.dirname
+
+ """
+ assert '\\' not in group, 'Groups are not paths and cannot contain \\'
+ assert not group.startswith('/'), 'Groups cannot start with /'
+
+ return posixpath.dirname(group)
+
+
+def splitname(group):
+ """Split a group name, Returns tuple "(group, test)"."""
+ assert '\\' not in group, 'Groups are not paths and cannot contain \\'