def test_get_comment_header(self): Equal = self.assertEqual Equal(fp.get_comment_header(self.test_comment), '#') Equal(fp.get_comment_header(self.trailingws_comment), '#') Equal(fp.get_comment_header(self.leadingws_comment), ' #') Equal(fp.get_comment_header(self.leadingws_nocomment), ' ') Equal(fp.get_comment_header(self.test_nocomment), '')
def test_get_comment_header(self): Equal = self.assertEqual # Test comment strings Equal(fp.get_comment_header(self.test_comment), '#') Equal(fp.get_comment_header(self.trailingws_comment), '#') Equal(fp.get_comment_header(self.leadingws_comment), ' #') # Test non-comment strings Equal(fp.get_comment_header(self.leadingws_nocomment), ' ') Equal(fp.get_comment_header(self.test_nocomment), '')
def test_reformat_comment(self): Equal = self.assertEqual test_string = ' """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""' result = fp.reformat_comment(test_string, 70, ' ') expected = ' """this is a test of a reformat for a triple quoted string will it\n reformat to less than 70 characters for me?"""' Equal(result, expected) test_comment = '# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?' result = fp.reformat_comment(test_comment, 70, '#') expected = '# this is a test of a reformat for a triple quoted string will it\n# reformat to less than 70 characters for me?' Equal(result, expected)
def runcase(self, inserttext, stopline, expected): text = self.text text.insert('1.0', inserttext) for line in range(1, stopline): linelength = int(text.index('%d.end' % line).split('.')[1]) for col in (0, linelength // 2, linelength): tempindex = '%d.%d' % (line, col) self.assertEqual(fp.find_paragraph(text, tempindex), expected) text.delete('1.0', 'end')
def runcase(self, inserttext, stopline, expected): # Check that find_paragraph returns the expected paragraph when # the mark index is set to beginning, middle, end of each line # up to but not including the stop line text = self.text text.insert('1.0', inserttext) for line in range(1, stopline): linelength = int(text.index("%d.end" % line).split('.')[1]) for col in (0, linelength//2, linelength): tempindex = "%d.%d" % (line, col) self.assertEqual(fp.find_paragraph(text, tempindex), expected) text.delete('1.0', 'end')
def test_reformat_comment(self): Equal = self.assertEqual # reformat_comment formats to a minimum of 20 characters test_string = ( " \"\"\"this is a test of a reformat for a triple quoted string" " will it reformat to less than 70 characters for me?\"\"\"") result = fp.reformat_comment(test_string, 70, " ") expected = ( " \"\"\"this is a test of a reformat for a triple quoted string will it\n" " reformat to less than 70 characters for me?\"\"\"") Equal(result, expected) test_comment = ( "# this is a test of a reformat for a triple quoted string will " "it reformat to less than 70 characters for me?") result = fp.reformat_comment(test_comment, 70, "#") expected = ( "# this is a test of a reformat for a triple quoted string will it\n" "# reformat to less than 70 characters for me?") Equal(result, expected)
def runcase(self, inserttext, stopline, expected): # Check that find_paragraph returns the expected paragraph when # the mark index is set to beginning, middle, end of each line # up to but not including the stop line text = self.text text.insert('1.0', inserttext) for line in range(1, stopline): linelength = int(text.index("%d.end" % line).split('.')[1]) for col in (0, linelength // 2, linelength): tempindex = "%d.%d" % (line, col) self.assertEqual(fp.find_paragraph(text, tempindex), expected) text.delete('1.0', 'end')
def test_is_all_white(self): self.assertTrue(fp.is_all_white('')) self.assertTrue(fp.is_all_white('\t\n\r\x0c\x0b')) self.assertFalse(fp.is_all_white(self.test_comment))
def setUpClass(cls): requires('gui') cls.root = Tk() editor = Editor(root=cls.root) cls.text = editor.text.text cls.formatter = fp.FormatParagraph(editor).format_paragraph_event
def setUpClass(cls): requires('gui') cls.root = Tk() editor = Editor(root=cls.root) cls.text = editor.text.text # Test code does not need the wrapper. cls.formatter = fp.FormatParagraph(editor).format_paragraph_event
def test_init_close(self): instance = fp.FormatParagraph('editor') self.assertEqual(instance.editwin, 'editor') instance.close() self.assertEqual(instance.editwin, None)
def test_is_all_white(self): self.assertTrue(fp.is_all_white('')) self.assertTrue(fp.is_all_white('\t\n\r\f\v')) self.assertFalse(fp.is_all_white(self.test_comment))