diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -264,4 +264,7 @@ print("%d of %d tests failed" % (num_fail, num_tests)) if __name__ == '__main__': - main() + #main() + from unittest import main + from idlelib.idle_test import test_calltips as t + main(t, verbosity=2, exit=False) diff --git a/Lib/idlelib/PathBrowser.py b/Lib/idlelib/PathBrowser.py --- a/Lib/idlelib/PathBrowser.py +++ b/Lib/idlelib/PathBrowser.py @@ -95,4 +95,6 @@ mainloop() if __name__ == "__main__": - main() + from unittest import main + from idlelib.idle_test import test_pathbrowser as t + main(t, verbosity=2, exit=False) diff --git a/Lib/idlelib/idle_test/@README.txt b/Lib/idlelib/idle_test/@README.txt new file mode 100644 --- /dev/null +++ b/Lib/idlelib/idle_test/@README.txt @@ -0,0 +1,48 @@ +IDLE TESTS + +The idle directory, idlelib, has over 60 .py files/ Eventually, there should +be more or less one test module for each code module in this sub-directory, +idle_tests. Each should be named test_xxx, where 'xxx' is the lowercase name +of the code module. Each should start with the following cut and paste +template, with the blank after after '.'. 'as', and '_' filled in. +--- +import unittest +import idlelib. as + +class Test(unittest.TestCase): + + def test_(self): + + +if __name__ == '__main__': + unittest.main() +--- + +Once test_xyy is written, the following should go at the end of xyy.py, +with xyz replacing the blank after 'test_'. F5 in xyz.py will then run +the test with Idle and traceback's appear in the Shell window. +--- +if __name__ == "__main__": + import unittest + from idlelib.idle_test import test_ as t + unittest.main(t, verbosity=2, exit=False) +--- +The options are adjusted for developers running one test rather than +buildbots running all tests: verbosity=2 lists all test_y methods; +exit=False avoids spurious sys.exit traceback when running in Idle. + +The following runs all idle tests interactively with the same options. +--- +import unittest, idlelib.idle_test;\ +unittest.main(idlelib.idle_test, verbosity=2, exit=False) +--- +From a command line, run one or all idle tests with the following: +path: python -m idlelib.xyz +path: python -m test.test_idle +Replace 'path' or 'python' with whatever is necessary to start the proper +version of the interpreter. + +The buildbots and anyone running the test suite with 'python -m test' +will run idle tests via test.test_idle. That uses idlelib.idle_test. +load_tests to discover the idle tests in the idle_test directory. The file +test_idle should not normally need editing. diff --git a/Lib/idlelib/idle_test/__init__.py b/Lib/idlelib/idle_test/__init__.py new file mode 100644 --- /dev/null +++ b/Lib/idlelib/idle_test/__init__.py @@ -0,0 +1,9 @@ +from os.path import dirname + +def load_tests(loader, standard_tests, pattern): + this_dir = dirname(__file__) + top_dir = dirname(dirname(this_dir)) + package_tests = loader.discover(start_dir=this_dir, pattern='test*.py', + top_level_dir=top_dir) + standard_tests.addTests(package_tests) + return standard_tests diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py new file mode 100644 --- /dev/null +++ b/Lib/idlelib/idle_test/test_calltips.py @@ -0,0 +1,11 @@ +import unittest +import idlelib.CallTips as ct + +class Test_get_entity(unittest.TestCase): + def test_bad_entity(self): + self.assertIsNone(ct.get_entity('1/0')) + def test_good_entity(self): + self.assertIs(ct.get_entity('int'), int) + +if __name__ == '__main__': + unittest.main() diff --git a/Lib/idlelib/idle_test/test_pathbrowser.py b/Lib/idlelib/idle_test/test_pathbrowser.py new file mode 100644 --- /dev/null +++ b/Lib/idlelib/idle_test/test_pathbrowser.py @@ -0,0 +1,12 @@ +import unittest +import idlelib.PathBrowser as PathBrowser + +class PathBrowserTest(unittest.TestCase): + + def test_DirBrowserTreeItem(self): + # Issue16226 - make sure that getting a sublist works + d = PathBrowser.DirBrowserTreeItem('') + d.GetSubList() + +if __name__ == '__main__': + unittest.main() diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_idle.py @@ -0,0 +1,14 @@ +# Skip test if tkinter wasn't built or idlelib was deleted. +from test.support import import_module as sim +sim('tkinter') # discard return +itdir = sim('idlelib.idle_test') + +# Without test_main present, regrtest.runtest_inner (line1219) +# calls unittest.TestLoader().loadTestsFromModule(the_module) +# which will look for load_tests and use if if found. +load_tests = itdir.load_tests + +if __name__ == '__main__': + # unittest.main makes same method call given above + import unittest + unittest.main(itdir)