mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #20792: Expand idle_test.test_pathbowser. Tweak file to not copy twice.
Original patch by Saimadhav Heblikar.
This commit is contained in:
parent
c0b1e0f868
commit
19c1a8725c
2 changed files with 22 additions and 5 deletions
|
@ -17,6 +17,7 @@ class PathBrowser(ClassBrowser):
|
||||||
self.init(flist)
|
self.init(flist)
|
||||||
|
|
||||||
def settitle(self):
|
def settitle(self):
|
||||||
|
"Set window titles."
|
||||||
self.top.wm_title("Path Browser")
|
self.top.wm_title("Path Browser")
|
||||||
self.top.wm_iconname("Path Browser")
|
self.top.wm_iconname("Path Browser")
|
||||||
|
|
||||||
|
@ -69,16 +70,17 @@ class DirBrowserTreeItem(TreeItem):
|
||||||
return sublist
|
return sublist
|
||||||
|
|
||||||
def ispackagedir(self, file):
|
def ispackagedir(self, file):
|
||||||
|
" Return true for directories that are packages."
|
||||||
if not os.path.isdir(file):
|
if not os.path.isdir(file):
|
||||||
return 0
|
return False
|
||||||
init = os.path.join(file, "__init__.py")
|
init = os.path.join(file, "__init__.py")
|
||||||
return os.path.exists(init)
|
return os.path.exists(init)
|
||||||
|
|
||||||
def listmodules(self, allnames):
|
def listmodules(self, allnames):
|
||||||
modules = {}
|
modules = {}
|
||||||
suffixes = importlib.machinery.EXTENSION_SUFFIXES[:]
|
suffixes = importlib.machinery.EXTENSION_SUFFIXES[:]
|
||||||
suffixes += importlib.machinery.SOURCE_SUFFIXES[:]
|
suffixes += importlib.machinery.SOURCE_SUFFIXES
|
||||||
suffixes += importlib.machinery.BYTECODE_SUFFIXES[:]
|
suffixes += importlib.machinery.BYTECODE_SUFFIXES
|
||||||
sorted = []
|
sorted = []
|
||||||
for suff in suffixes:
|
for suff in suffixes:
|
||||||
i = -len(suff)
|
i = -len(suff)
|
||||||
|
@ -93,7 +95,7 @@ class DirBrowserTreeItem(TreeItem):
|
||||||
sorted.sort()
|
sorted.sort()
|
||||||
return sorted
|
return sorted
|
||||||
|
|
||||||
def _path_browser(parent):
|
def _path_browser(parent): # htest #
|
||||||
flist = PyShellFileList(parent)
|
flist = PyShellFileList(parent)
|
||||||
PathBrowser(flist, _htest=True)
|
PathBrowser(flist, _htest=True)
|
||||||
parent.mainloop()
|
parent.mainloop()
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import unittest
|
import unittest
|
||||||
import idlelib.PathBrowser as PathBrowser
|
import os
|
||||||
|
import sys
|
||||||
|
import idlelib
|
||||||
|
from idlelib import PathBrowser
|
||||||
|
|
||||||
class PathBrowserTest(unittest.TestCase):
|
class PathBrowserTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -7,6 +10,18 @@ class PathBrowserTest(unittest.TestCase):
|
||||||
# Issue16226 - make sure that getting a sublist works
|
# Issue16226 - make sure that getting a sublist works
|
||||||
d = PathBrowser.DirBrowserTreeItem('')
|
d = PathBrowser.DirBrowserTreeItem('')
|
||||||
d.GetSubList()
|
d.GetSubList()
|
||||||
|
self.assertEqual('', d.GetText())
|
||||||
|
|
||||||
|
dir = os.path.split(os.path.abspath(idlelib.__file__))[0]
|
||||||
|
self.assertEqual(d.ispackagedir(dir), True)
|
||||||
|
self.assertEqual(d.ispackagedir(dir + '/Icons'), False)
|
||||||
|
|
||||||
|
def test_PathBrowserTreeItem(self):
|
||||||
|
p = PathBrowser.PathBrowserTreeItem()
|
||||||
|
self.assertEqual(p.GetText(), 'sys.path')
|
||||||
|
sub = p.GetSubList()
|
||||||
|
self.assertEqual(len(sub), len(sys.path))
|
||||||
|
self.assertEqual(type(sub[0]), PathBrowser.DirBrowserTreeItem)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main(verbosity=2, exit=False)
|
unittest.main(verbosity=2, exit=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue