Author: bugman Date: Wed Mar 20 14:58:45 2013 New Revision: 18915 URL: http://svn.gna.org/viewcvs/relax?rev=18915&view=rev Log: Merged revisions 18913-18914 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r18913 | bugman | 2013-03-20 14:57:41 +0100 (Wed, 20 Mar 2013) | 6 lines Expansion of the lib.text.sectioning module. The following new functions have been added: box(), section(), subsection(), subsubsection(), subtitle(), subsubtitle(), underline(). ........ r18914 | bugman | 2013-03-20 14:58:16 +0100 (Wed, 20 Mar 2013) | 3 lines Expanded the unit testing of the lib.text.sectioning module to cover all title and section functions. ........ Modified: branches/frame_order_testing/ (props changed) branches/frame_order_testing/lib/text/sectioning.py branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_sectioning.py Propchange: branches/frame_order_testing/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Wed Mar 20 14:58:45 2013 @@ -1,1 +1,1 @@ -/trunk:1-18911 +/trunk:1-18914 Modified: branches/frame_order_testing/lib/text/sectioning.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/lib/text/sectioning.py?rev=18915&r1=18914&r2=18915&view=diff ============================================================================== --- branches/frame_order_testing/lib/text/sectioning.py (original) +++ branches/frame_order_testing/lib/text/sectioning.py Wed Mar 20 14:58:45 2013 @@ -23,27 +23,99 @@ """Functions for the formatting of titles, subtitles and other sectioning.""" +def box(file=None, text=None, char=None): + """Format and write out a box surrounding the text. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The text to box. + @type text: str + @keyword char: The single character to use for the box. + @type char: str + """ + + # The length and horizontal box text. + length = len(text) + 4 + hline = char * length + + # The text. + file.write("%s\n" % hline) + file.write("%s %s %s\n" % (char, text, char)) + file.write("%s\n" % hline) + + +def section(file=None, text=None): + """Format and write out a section to the given file. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The section text. + @type text: str + """ + + # Underline the text. + file.write("\n\n") + underline(file=file, text=text, char="=") + file.write("\n") + + +def subsection(file=None, text=None): + """Format and write out a subsection to the given file. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The subsection text. + @type text: str + """ + + # Underline the text. + file.write("\n") + underline(file=file, text=text, char="-") + file.write("\n") + + +def subsubsection(file=None, text=None): + """Format and write out a subsubsection to the given file. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The subsubsection text. + @type text: str + """ + + # Underline the text. + file.write("\n") + underline(file=file, text=text, char="~") + file.write("\n") + + +def subsubtitle(file=None, text=None): + """Format and write out a subsubtitle to the given file. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The subsubtitle text. + @type text: str + """ + + # Box the text. + file.write("\n") + box(file=file, text=text, char="~") + file.write("\n") + + def subtitle(file=None, text=None): """Format and write out a subtitle to the given file. @keyword file: The file object to write to. @type file: file object - @keyword text: The subtitle. + @keyword text: The subtitle text. @type text: str """ - # The length and hline text. - length = len(text) + 2 - hline = '#' * length - - # First the spacing above the section. + # Box the text. file.write("\n") - - # The text. - file.write("# %s\n" % text) - file.write("%s\n" % hline) - - # Final spacing. + box(file=file, text=text, char="-") file.write("\n") @@ -52,21 +124,31 @@ @keyword file: The file object to write to. @type file: file object - @keyword text: The title. + @keyword text: The title text. @type text: str """ - # The length and hline text. - length = len(text) + 4 - hline = '#' * length + # Box the text. + file.write("\n\n") + box(file=file, text=text, char="=") + file.write("\n") - # First the spacing above the section. - file.write("\n\n") + +def underline(file=None, text=None, char=None): + """Format and write out the text underlined by the given character. + + @keyword file: The file object to write to. + @type file: file object + @keyword text: The text to underline. + @type text: str + @keyword char: The single character to use for the underline. + @type char: str + """ + + # The length and horizontal underline text. + length = len(text) + hline = char * length # The text. + file.write("%s\n" % text) file.write("%s\n" % hline) - file.write("# %s #\n" % text) - file.write("%s\n" % hline) - - # Final spacing. - file.write("\n") Modified: branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_sectioning.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_sectioning.py?rev=18915&r1=18914&r2=18915&view=diff ============================================================================== --- branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_sectioning.py (original) +++ branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_sectioning.py Wed Mar 20 14:58:45 2013 @@ -23,12 +23,106 @@ from unittest import TestCase # relax module imports. -from lib.text.sectioning import subtitle, title +from lib.text.sectioning import section, subsection, subsubsection, subsubtitle, subtitle, title from relax_io import DummyFileObject class Test_sectioning(TestCase): """Unit tests for the lib.text.sectioning relax module.""" + + def test_section(self): + """Test of the lib.text.sectioning.section() function.""" + + # Write out the section. + file = DummyFileObject() + section(file=file, text='Test section') + + # Read the results. + lines = file.readlines() + print("Formatted section lines: %s" % lines) + + # Check the title. + real_lines = [ + '\n', + '\n', + 'Test section\n', + '============\n', + '\n', + ] + self.assertEqual(len(lines), len(real_lines)) + for i in range(len(lines)): + self.assertEqual(lines[i], real_lines[i]) + + + def test_subsection(self): + """Test of the lib.text.sectioning.subsection() function.""" + + # Write out the subsection. + file = DummyFileObject() + subsection(file=file, text='Test subsection') + + # Read the results. + lines = file.readlines() + print("Formatted subsection lines: %s" % lines) + + # Check the title. + real_lines = [ + '\n', + 'Test subsection\n', + '---------------\n', + '\n', + ] + self.assertEqual(len(lines), len(real_lines)) + for i in range(len(lines)): + self.assertEqual(lines[i], real_lines[i]) + + + def test_subsubsection(self): + """Test of the lib.text.sectioning.subsubsection() function.""" + + # Write out the subsubsection. + file = DummyFileObject() + subsubsection(file=file, text='Test subsubsection') + + # Read the results. + lines = file.readlines() + print("Formatted subsubsection lines: %s" % lines) + + # Check the title. + real_lines = [ + '\n', + 'Test subsubsection\n', + '~~~~~~~~~~~~~~~~~~\n', + '\n', + ] + self.assertEqual(len(lines), len(real_lines)) + for i in range(len(lines)): + self.assertEqual(lines[i], real_lines[i]) + + + def test_subsubtitle(self): + """Test of the lib.text.sectioning.subsubtitle() function.""" + + # Write out the subtitle. + file = DummyFileObject() + subsubtitle(file=file, text='Test subsubtitle') + + # Read the results. + lines = file.readlines() + print("Formatted subsubtitle lines: %s" % lines) + + # Check the title. + real_lines = [ + '\n', + '~~~~~~~~~~~~~~~~~~~~\n', + '~ Test subsubtitle ~\n', + '~~~~~~~~~~~~~~~~~~~~\n', + '\n', + ] + self.assertEqual(len(lines), len(real_lines)) + for i in range(len(lines)): + self.assertEqual(lines[i], real_lines[i]) + def test_subtitle(self): """Test of the lib.text.sectioning.subtitle() function.""" @@ -42,15 +136,16 @@ print("Formatted subtitle lines: %s" % lines) # Check the title. - subtitle_lines = [ + real_lines = [ '\n', - '# Test subtitle\n', - '###############\n', + '-----------------\n', + '- Test subtitle -\n', + '-----------------\n', '\n', ] - self.assertEqual(len(lines), len(subtitle_lines)) + self.assertEqual(len(lines), len(real_lines)) for i in range(len(lines)): - self.assertEqual(lines[i], subtitle_lines[i]) + self.assertEqual(lines[i], real_lines[i]) def test_title(self): @@ -65,14 +160,14 @@ print("Formatted title lines: %s" % lines) # Check the title. - title_lines = [ + real_lines = [ '\n', '\n', - '##############\n', - '# Test title #\n', - '##############\n', + '==============\n', + '= Test title =\n', + '==============\n', '\n', ] - self.assertEqual(len(lines), len(title_lines)) + self.assertEqual(len(lines), len(real_lines)) for i in range(len(lines)): - self.assertEqual(lines[i], title_lines[i]) + self.assertEqual(lines[i], real_lines[i])