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 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 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_get_indent(self):
     Equal = self.assertEqual
     Equal(fp.get_indent(self.test_comment), '')
     Equal(fp.get_indent(self.trailingws_comment), '')
     Equal(fp.get_indent(self.leadingws_comment), '    ')
     Equal(fp.get_indent(self.leadingws_nocomment), '    ')
 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))