Package test_suite :: Package unit_tests :: Package _lib :: Package _text :: Module test_sectioning
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib._text.test_sectioning

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from unittest import TestCase 
 24   
 25  # relax module imports. 
 26  from lib.text.sectioning import section, subsection, subsubsection, subsubtitle, subtitle, title 
 27  from lib.io import DummyFileObject 
 28   
 29   
30 -class Test_sectioning(TestCase):
31 """Unit tests for the lib.text.sectioning relax module.""" 32
33 - def test_section(self):
34 """Test of the lib.text.sectioning.section() function.""" 35 36 # Write out the section. 37 file = DummyFileObject() 38 section(file=file, text='Test section') 39 40 # Read the results. 41 lines = file.readlines() 42 print("Formatted section lines: %s" % lines) 43 44 # Check the title. 45 real_lines = [ 46 '\n', 47 '\n', 48 'Test section\n', 49 '============\n', 50 '\n', 51 ] 52 self.assertEqual(len(lines), len(real_lines)) 53 for i in range(len(lines)): 54 self.assertEqual(lines[i], real_lines[i])
55 56
57 - def test_subsection(self):
58 """Test of the lib.text.sectioning.subsection() function.""" 59 60 # Write out the subsection. 61 file = DummyFileObject() 62 subsection(file=file, text='Test subsection') 63 64 # Read the results. 65 lines = file.readlines() 66 print("Formatted subsection lines: %s" % lines) 67 68 # Check the title. 69 real_lines = [ 70 '\n', 71 'Test subsection\n', 72 '---------------\n', 73 '\n', 74 ] 75 self.assertEqual(len(lines), len(real_lines)) 76 for i in range(len(lines)): 77 self.assertEqual(lines[i], real_lines[i])
78 79
80 - def test_subsubsection(self):
81 """Test of the lib.text.sectioning.subsubsection() function.""" 82 83 # Write out the subsubsection. 84 file = DummyFileObject() 85 subsubsection(file=file, text='Test subsubsection') 86 87 # Read the results. 88 lines = file.readlines() 89 print("Formatted subsubsection lines: %s" % lines) 90 91 # Check the title. 92 real_lines = [ 93 '\n', 94 'Test subsubsection\n', 95 '~~~~~~~~~~~~~~~~~~\n', 96 '\n', 97 ] 98 self.assertEqual(len(lines), len(real_lines)) 99 for i in range(len(lines)): 100 self.assertEqual(lines[i], real_lines[i])
101 102
103 - def test_subsubtitle(self):
104 """Test of the lib.text.sectioning.subsubtitle() function.""" 105 106 # Write out the subtitle. 107 file = DummyFileObject() 108 subsubtitle(file=file, text='Test subsubtitle') 109 110 # Read the results. 111 lines = file.readlines() 112 print("Formatted subsubtitle lines: %s" % lines) 113 114 # Check the title. 115 real_lines = [ 116 '\n', 117 '~~~~~~~~~~~~~~~~~~~~\n', 118 '~ Test subsubtitle ~\n', 119 '~~~~~~~~~~~~~~~~~~~~\n', 120 '\n', 121 ] 122 self.assertEqual(len(lines), len(real_lines)) 123 for i in range(len(lines)): 124 self.assertEqual(lines[i], real_lines[i])
125 126
127 - def test_subtitle(self):
128 """Test of the lib.text.sectioning.subtitle() function.""" 129 130 # Write out the subtitle. 131 file = DummyFileObject() 132 subtitle(file=file, text='Test subtitle') 133 134 # Read the results. 135 lines = file.readlines() 136 print("Formatted subtitle lines: %s" % lines) 137 138 # Check the title. 139 real_lines = [ 140 '\n', 141 '-----------------\n', 142 '- Test subtitle -\n', 143 '-----------------\n', 144 '\n', 145 ] 146 self.assertEqual(len(lines), len(real_lines)) 147 for i in range(len(lines)): 148 self.assertEqual(lines[i], real_lines[i])
149 150
151 - def test_title(self):
152 """Test of the lib.text.sectioning.title() function.""" 153 154 # Write out the title. 155 file = DummyFileObject() 156 title(file=file, text='Test title') 157 158 # Read the results. 159 lines = file.readlines() 160 print("Formatted title lines: %s" % lines) 161 162 # Check the title. 163 real_lines = [ 164 '\n', 165 '\n', 166 '==============\n', 167 '= Test title =\n', 168 '==============\n', 169 '\n', 170 ] 171 self.assertEqual(len(lines), len(real_lines)) 172 for i in range(len(lines)): 173 self.assertEqual(lines[i], real_lines[i])
174