@@ -92,6 +92,57 @@ def loadTestsFromModule(module, pattern=None):
9292 ('test3' , 'test4' )])
9393 self .assertEqual (suite , expected )
9494
95+ def test_find_tests_with_unicode (self ):
96+ loader = unittest .TestLoader ()
97+
98+ original_listdir = os .listdir
99+ def restore_listdir ():
100+ os .listdir = original_listdir
101+ original_isfile = os .path .isfile
102+ def restore_isfile ():
103+ os .path .isfile = original_isfile
104+ original_isdir = os .path .isdir
105+ def restore_isdir ():
106+ os .path .isdir = original_isdir
107+
108+ path_lists = [['測試2.py' , '測試1.py' , '不是測試.py' , '測試_資料夾' ,
109+ '測試.付歐歐' , '測試-不是-一個-模組.py' , '另外的_資料夾' ],
110+ ['測試4.py' , '測試3.py' , ]]
111+ os .listdir = lambda path : path_lists .pop (0 )
112+ self .addCleanup (restore_listdir )
113+
114+ def isdir (path ):
115+ return path .endswith ('資料夾' )
116+ os .path .isdir = isdir
117+ self .addCleanup (restore_isdir )
118+
119+ def isfile (path ):
120+ # another_dir is not a package and so shouldn't be recursed into
121+ return not path .endswith ('資料夾' ) and not '另外的_資料夾' in path
122+ os .path .isfile = isfile
123+ self .addCleanup (restore_isfile )
124+
125+ loader ._get_module_from_name = lambda path : path + ' module'
126+ orig_load_tests = loader .loadTestsFromModule
127+ def loadTestsFromModule (module , pattern = None ):
128+ # This is where load_tests is called.
129+ base = orig_load_tests (module , pattern = pattern )
130+ return base + [module + ' tests' ]
131+ loader .loadTestsFromModule = loadTestsFromModule
132+ loader .suiteClass = lambda thing : thing
133+
134+ top_level = os .path .abspath ('/foo' )
135+ loader ._top_level_dir = top_level
136+ suite = list (loader ._find_tests (top_level , '測試*.py' ))
137+
138+ # The test suites found should be sorted alphabetically for reliable
139+ # execution order.
140+ expected = [[name + ' module tests' ] for name in
141+ ('測試1' , '測試2' , '測試_資料夾' )]
142+ expected .extend ([[('測試_資料夾.%s' % name ) + ' module tests' ] for name in
143+ ('測試3' , '測試4' )])
144+ self .assertEqual (suite , expected )
145+
95146 def test_find_tests_socket (self ):
96147 # A socket is neither a directory nor a regular file.
97148 # https://bugs.python.org/issue25320
0 commit comments