summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2022-02-13 00:52:37 (GMT)
committerGitHub <noreply@github.com>2022-02-13 00:52:37 (GMT)
commit9fabcfbe68ff81ef5f17f86a93daf9cce9d83876 (patch)
tree85e79df4004c90260ec0a46ca3ec8a128abfe6e3 /Lib/idlelib/idle_test
parentb7a65c939c93e7910abc8c9d4a129ff385714824 (diff)
downloadcpython-9fabcfbe68ff81ef5f17f86a93daf9cce9d83876.zip
cpython-9fabcfbe68ff81ef5f17f86a93daf9cce9d83876.tar.gz
cpython-9fabcfbe68ff81ef5f17f86a93daf9cce9d83876.tar.bz2
bpo-45447: Add syntax highlighting for `.pyi` files in IDLE (GH-28950)
Also add .pyi to the python extensions in the "File-open" and "File-save" dialogues. Add util.py to contain objects that are used in multiple idlelib modules and have no dependencies on any of them. Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> (cherry picked from commit 50cf4991c49e19f917305dd7b9c71085c11edddb) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/example_noext4
-rw-r--r--Lib/idlelib/idle_test/example_stub.pyi2
-rw-r--r--Lib/idlelib/idle_test/test_iomenu.py24
-rw-r--r--Lib/idlelib/idle_test/test_util.py14
4 files changed, 43 insertions, 1 deletions
diff --git a/Lib/idlelib/idle_test/example_noext b/Lib/idlelib/idle_test/example_noext
new file mode 100644
index 0000000..7d2510e
--- /dev/null
+++ b/Lib/idlelib/idle_test/example_noext
@@ -0,0 +1,4 @@
+#!usr/bin/env python
+
+def example_function(some_argument):
+ pass
diff --git a/Lib/idlelib/idle_test/example_stub.pyi b/Lib/idlelib/idle_test/example_stub.pyi
new file mode 100644
index 0000000..a9811a7
--- /dev/null
+++ b/Lib/idlelib/idle_test/example_stub.pyi
@@ -0,0 +1,2 @@
+class Example:
+ def method(self, argument1: str, argument2: list[int]) -> None: ...
diff --git a/Lib/idlelib/idle_test/test_iomenu.py b/Lib/idlelib/idle_test/test_iomenu.py
index 99f4048..e338893 100644
--- a/Lib/idlelib/idle_test/test_iomenu.py
+++ b/Lib/idlelib/idle_test/test_iomenu.py
@@ -1,6 +1,6 @@
"Test , coverage 17%."
-from idlelib import iomenu
+from idlelib import iomenu, util
import unittest
from test.support import requires
from tkinter import Tk
@@ -45,5 +45,27 @@ class IOBindingTest(unittest.TestCase):
eq(fix(), 'a'+io.eol_convention)
+def _extension_in_filetypes(extension):
+ return any(
+ f'*{extension}' in filetype_tuple[1]
+ for filetype_tuple in iomenu.IOBinding.filetypes
+ )
+
+
+class FiletypesTest(unittest.TestCase):
+ def test_python_source_files(self):
+ for extension in util.py_extensions:
+ with self.subTest(extension=extension):
+ self.assertTrue(
+ _extension_in_filetypes(extension)
+ )
+
+ def test_text_files(self):
+ self.assertTrue(_extension_in_filetypes('.txt'))
+
+ def test_all_files(self):
+ self.assertTrue(_extension_in_filetypes(''))
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_util.py b/Lib/idlelib/idle_test/test_util.py
new file mode 100644
index 0000000..20721fe
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_util.py
@@ -0,0 +1,14 @@
+"""Test util, coverage 100%"""
+
+import unittest
+from idlelib import util
+
+
+class UtilTest(unittest.TestCase):
+ def test_extensions(self):
+ for extension in {'.pyi', '.py', '.pyw'}:
+ self.assertIn(extension, util.py_extensions)
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)