[Piglit] [PATCH 1/7] framework_tests/summary.py: Tests Summary.py's assignment of statues

Kenneth Graunke kenneth at whitecape.org
Mon Oct 14 19:58:33 CEST 2013


On 10/14/2013 06:48 AM, Dylan Baker wrote:
> On Sunday, October 13, 2013 10:51:50 PM Kenneth Graunke wrote:
>> On 09/27/2013 02:39 PM, Dylan Baker wrote:
[snip]
>> pass?  Will it actually work if this doesn't get created?  I'm guessing
>> you need to abort the test (or just don't catch the exception)...
> 
> I'll look into this, but I think I actually just need to be more picky here 
> since what I want to 'pass' on is a 'File Exists' error, but you're right, we 
> don't want to pass on other errors like a "Permission Denied".

I think if you use the tempfile module, you're guaranteed to get your
own unique area to play in, so you shouldn't actually run into any "File
Exists" errors.  So you can probably just let the exceptions fly :)

[snip]
>>> +    @classmethod
>>> +    def tearDownClass(cls):
>>> +        # Remove any folders which were created and are empty
>>> +        for branch in cls.files:
>>> +            os.remove(branch)
>>> +            while branch != '/tmp':
>>> +                branch = path.dirname(branch)
>>> +                try:
>>> +                    os.rmdir(branch)
>>> +                except OSError:
>>> +                    # If there is an OSError the directory is not empty,
>>> so +                    # every additional attempt to call os.rmdir will
>>> fail. +                    break
>>
>> I'm glad to see this uses rmdir, so it won't accidentally rm -rf my
>> system if the path handling goes awry due to some bug.
> 
> Is that sarcasm I detect?

No...I just saw a bunch of path walking code that throws away things,
and it's really easy to accidentally introduce a bug in that.  In the
event of such a mistake, rmdir is still pretty safe, since it'll just
remove empty directories.

Thanks, Dylan.

--Ken


More information about the Piglit mailing list