-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor is_hidden to address kivy#5873
* Added failing test before implementing fix. * Added super-basic iconview test, because the code is never exercised. * Refactor is_hidden so it doesn't fail: Use built-in `os.stat` instead of win32file's `GetFileAttributesExW()` because it handles (in use) system files. * Sort imports according to PEP8. * Stop (conditionally) importing win32file. * Add support for macOS's UF_Hidden attributes. * Confirm new tests are now passing.
- Loading branch information
Showing
2 changed files
with
64 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,47 @@ | ||
import logging | ||
from os import environ | ||
from os.path import expanduser, exists | ||
from sys import version_info | ||
import unittest | ||
|
||
from kivy.tests.common import GraphicUnitTest | ||
from kivy.uix.filechooser import FileChooserListView, FileChooserIconView | ||
|
||
|
||
class FileChooserTestCase(GraphicUnitTest): | ||
|
||
def test_filechooserlistview(self): | ||
from kivy.uix.filechooser import FileChooserListView | ||
from os.path import expanduser | ||
r = self.render | ||
wid = FileChooserListView(path=expanduser('~')) | ||
r(wid, 2) | ||
widget = FileChooserListView(path=expanduser("~")) | ||
r(widget, 2) | ||
|
||
def test_filechoosericonview(self): | ||
r = self.render | ||
widget = FileChooserIconView(path=expanduser("~"), show_hidden=True) | ||
r(widget, 2) | ||
|
||
@unittest.skipIf( | ||
("SystemDrive" not in environ) or | ||
(not exists(environ["SystemDrive"] + "\\pagefile.sys")), | ||
"Only runs on Windows with example system file present", | ||
) | ||
@unittest.skipIf( | ||
version_info < (3, 10), "assertNoLogs requires in Python 3.10" | ||
) | ||
def test_filechooser_files_in_use_5873(self): | ||
# Per Kivy Issue #5873, initially viewing C:\ on Windows would | ||
# crash. | ||
# Later versions, it merely logged warnings. | ||
# The cause was hidden system files which could not be interrogated to | ||
# find out if they were hidden, because they were in use by the system. | ||
|
||
# This variant always worked, because there was no call to is_hidden. | ||
with self.assertNoLogs(logging.getLogger("kivy"), logging.WARNING): | ||
widget = FileChooserListView( | ||
path=environ["SystemDrive"] + "/", show_hidden=True | ||
) | ||
self.render(widget, 1) | ||
|
||
# This used to fail, because the call to is_hidden logged errors. | ||
with self.assertNoLogs(logging.getLogger("kivy"), logging.WARNING): | ||
widget = FileChooserListView(path=environ["SystemDrive"] + "/") | ||
self.render(widget, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters