[Piglit] [PATCH 01/10] grouptools.py: Add a module specifically for working with group strings

Jose Fonseca jfonseca at vmware.com
Fri Dec 12 03:50:25 PST 2014


On 05/12/14 19:24, Dylan Baker wrote:
> On Friday, December 05, 2014 11:55:41 AM Jose Fonseca wrote:
>> On 04/12/14 23:09, Dylan Baker wrote:
>>> 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 <dylanx.c.baker at intel.com>
>>> ---
>>>    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 \\'
>>
>> I think the series is a good cleanup.
>>
>> But have you run any tests on Windows? There are so many places that
>> could introduce '\\' in the paths, so I'm concerned this can leave
>> Windows totally broken.
>>
>> I can test this myself if you want. Just please push the series to some
>> repos I can pull from.
>>
>> Jose
>
> I do not have a windows machine to run piglit on, unfortunately. If you
> could test it and let me know if/where there are problems that would be
> great.
>
> I pushed it here:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_dcbaker_piglit&d=AAICAg&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=zfmBZnnVGHeYde45pMKNnVyzeaZbdIqVLprmZCM2zzE&m=Ya5i-WqfM5bB1nUyv-ABJ_NcpPuUPmsxdCtTaHNmJuQ&s=4etl2wGfhzGwO-NLt_BF0RjgxQSj4S2TUTwkqhKBKB4&e=  submit/group-tools
>

I finally had the time to test it.  I ran sanity w/ JSON and JUnit 
without incidents on Windows.  Plus started the quick tests.

So all looks good AFAICT!

Jose


More information about the Piglit mailing list