mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	On Windows use UTF-16 (or UTF-32 for 32-bit Tcl_UniChar) with the "surrogatepass" error handler for converting to/from Tcl Unicode objects. On Linux use UTF-8 with the "surrogateescape" error handler for converting to/from Tcl String objects. Converting strings from Tcl to Python and back now never fails (except MemoryError).
		
			
				
	
	
		
			95 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"Test editor, coverage 35%."
 | 
						|
 | 
						|
from idlelib import editor
 | 
						|
import unittest
 | 
						|
from test.support import requires
 | 
						|
from tkinter import Tk
 | 
						|
 | 
						|
Editor = editor.EditorWindow
 | 
						|
 | 
						|
 | 
						|
class EditorWindowTest(unittest.TestCase):
 | 
						|
 | 
						|
    @classmethod
 | 
						|
    def setUpClass(cls):
 | 
						|
        requires('gui')
 | 
						|
        cls.root = Tk()
 | 
						|
        cls.root.withdraw()
 | 
						|
 | 
						|
    @classmethod
 | 
						|
    def tearDownClass(cls):
 | 
						|
        cls.root.update_idletasks()
 | 
						|
        for id in cls.root.tk.call('after', 'info'):
 | 
						|
            cls.root.after_cancel(id)
 | 
						|
        cls.root.destroy()
 | 
						|
        del cls.root
 | 
						|
 | 
						|
    def test_init(self):
 | 
						|
        e = Editor(root=self.root)
 | 
						|
        self.assertEqual(e.root, self.root)
 | 
						|
        e._close()
 | 
						|
 | 
						|
 | 
						|
class TestGetLineIndent(unittest.TestCase):
 | 
						|
    def test_empty_lines(self):
 | 
						|
        for tabwidth in [1, 2, 4, 6, 8]:
 | 
						|
            for line in ['', '\n']:
 | 
						|
                with self.subTest(line=line, tabwidth=tabwidth):
 | 
						|
                    self.assertEqual(
 | 
						|
                        editor.get_line_indent(line, tabwidth=tabwidth),
 | 
						|
                        (0, 0),
 | 
						|
                    )
 | 
						|
 | 
						|
    def test_tabwidth_4(self):
 | 
						|
        #        (line, (raw, effective))
 | 
						|
        tests = (('no spaces', (0, 0)),
 | 
						|
                 # Internal space isn't counted.
 | 
						|
                 ('    space test', (4, 4)),
 | 
						|
                 ('\ttab test', (1, 4)),
 | 
						|
                 ('\t\tdouble tabs test', (2, 8)),
 | 
						|
                 # Different results when mixing tabs and spaces.
 | 
						|
                 ('    \tmixed test', (5, 8)),
 | 
						|
                 ('  \t  mixed test', (5, 6)),
 | 
						|
                 ('\t    mixed test', (5, 8)),
 | 
						|
                 # Spaces not divisible by tabwidth.
 | 
						|
                 ('  \tmixed test', (3, 4)),
 | 
						|
                 (' \t mixed test', (3, 5)),
 | 
						|
                 ('\t  mixed test', (3, 6)),
 | 
						|
                 # Only checks spaces and tabs.
 | 
						|
                 ('\nnewline test', (0, 0)))
 | 
						|
 | 
						|
        for line, expected in tests:
 | 
						|
            with self.subTest(line=line):
 | 
						|
                self.assertEqual(
 | 
						|
                    editor.get_line_indent(line, tabwidth=4),
 | 
						|
                    expected,
 | 
						|
                )
 | 
						|
 | 
						|
    def test_tabwidth_8(self):
 | 
						|
        #        (line, (raw, effective))
 | 
						|
        tests = (('no spaces', (0, 0)),
 | 
						|
                 # Internal space isn't counted.
 | 
						|
                 ('        space test', (8, 8)),
 | 
						|
                 ('\ttab test', (1, 8)),
 | 
						|
                 ('\t\tdouble tabs test', (2, 16)),
 | 
						|
                 # Different results when mixing tabs and spaces.
 | 
						|
                 ('        \tmixed test', (9, 16)),
 | 
						|
                 ('      \t  mixed test', (9, 10)),
 | 
						|
                 ('\t        mixed test', (9, 16)),
 | 
						|
                 # Spaces not divisible by tabwidth.
 | 
						|
                 ('  \tmixed test', (3, 8)),
 | 
						|
                 (' \t mixed test', (3, 9)),
 | 
						|
                 ('\t  mixed test', (3, 10)),
 | 
						|
                 # Only checks spaces and tabs.
 | 
						|
                 ('\nnewline test', (0, 0)))
 | 
						|
 | 
						|
        for line, expected in tests:
 | 
						|
            with self.subTest(line=line):
 | 
						|
                self.assertEqual(
 | 
						|
                    editor.get_line_indent(line, tabwidth=8),
 | 
						|
                    expected,
 | 
						|
                )
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    unittest.main(verbosity=2)
 |