mailr18708 - in /branches/frame_order_testing: ./ lib/text/table.py test_suite/unit_tests/_lib/_text/test_table.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on March 08, 2013 - 15:47:
Author: bugman
Date: Fri Mar  8 15:47:48 2013
New Revision: 18708

URL: http://svn.gna.org/viewcvs/relax?rev=18708&view=rev
Log:
Merged revisions 18706-18707 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r18706 | bugman | 2013-03-08 15:46:30 +0100 (Fri, 08 Mar 2013) | 5 lines
  
  Created the test_format_table5() unit test for 
lib.text.table.format_table().
  
  This test checks what happens if no header is given to format_table().  
This currently fails.
........
  r18707 | bugman | 2013-03-08 15:47:12 +0100 (Fri, 08 Mar 2013) | 3 lines
  
  The lib.text.table.format_table() function can now create a table without 
headers.
........

Modified:
    branches/frame_order_testing/   (props changed)
    branches/frame_order_testing/lib/text/table.py
    
branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_table.py

Propchange: branches/frame_order_testing/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Mar  8 15:47:48 2013
@@ -1,1 +1,1 @@
-/trunk:1-18704
+/trunk:1-18707

Modified: branches/frame_order_testing/lib/text/table.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/lib/text/table.py?rev=18708&r1=18707&r2=18708&view=diff
==============================================================================
--- branches/frame_order_testing/lib/text/table.py (original)
+++ branches/frame_order_testing/lib/text/table.py Fri Mar  8 15:47:48 2013
@@ -217,33 +217,38 @@
     text = ''
     num_rows = len(contents)
     num_cols = len(contents[0])
-    num_head_rows = len(headings)
+    if headings != None:
+        num_head_rows = len(headings)
 
     # Deepcopy so that modifications to the data are not seen.
-    headings = deepcopy(headings)
+    if headings != None:
+        headings = deepcopy(headings)
     contents = deepcopy(contents)
 
     # Create data structures for specifying the cell justification.
-    justification_headings = deepcopy(headings)
+    if headings != None:
+        justification_headings = deepcopy(headings)
     justification_contents = deepcopy(contents)
 
     # Convert all data to strings.
-    _convert_to_string(data=headings, justification=justification_headings, 
custom_format=custom_format)
+    if headings != None:
+        _convert_to_string(data=headings, 
justification=justification_headings, custom_format=custom_format)
     _convert_to_string(data=contents, justification=justification_contents, 
custom_format=custom_format)
 
     # Initialise the pre-wrapping column widths.
     prewrap_widths = [0] * num_cols
 
     # Determine the maximum column widths from the headers.
-    for i in range(num_head_rows):
-        for j in range(num_cols):
-            # Skip multicolumn entries.
-            if headings[i][j] == MULTI_COL or (j < num_cols-1 and 
headings[i][j+1] == MULTI_COL):
-                continue
-
-            # The element is larger than the previous.
-            if len(headings[i][j]) > prewrap_widths[j]:
-                prewrap_widths[j] = len(headings[i][j])
+    if headings != None:
+        for i in range(num_head_rows):
+            for j in range(num_cols):
+                # Skip multicolumn entries.
+                if headings[i][j] == MULTI_COL or (j < num_cols-1 and 
headings[i][j+1] == MULTI_COL):
+                    continue
+
+                # The element is larger than the previous.
+                if len(headings[i][j]) > prewrap_widths[j]:
+                    prewrap_widths[j] = len(headings[i][j])
 
     # Determine the maximum column widths from the content.
     for i in range(num_rows):
@@ -336,13 +341,18 @@
     total_width = sum(new_widths) + used
 
     # The header.
-    text += _rule(width=total_width)    # Top rule.
-    text += _blank(width=total_width)    # Blank line.
-    for i in range(num_head_rows):
-        text += _table_line(text=headings[i], widths=new_widths, separator=' 
  ', pad_left=pad_left, pad_right=pad_right, prefix=prefix, postfix=postfix, 
justification=justification_headings[i])
-        if i < num_head_rows-1 and spacing:
-            text += _blank(width=total_width)
-    text += _rule(width=total_width)    # Middle rule.
+    if headings != None:
+        text += _rule(width=total_width)    # Top rule.
+        text += _blank(width=total_width)    # Blank line.
+        for i in range(num_head_rows):
+            text += _table_line(text=headings[i], widths=new_widths, 
separator='   ', pad_left=pad_left, pad_right=pad_right, prefix=prefix, 
postfix=postfix, justification=justification_headings[i])
+            if i < num_head_rows-1 and spacing:
+                text += _blank(width=total_width)
+        text += _rule(width=total_width)    # Middle rule.
+
+    # No header.
+    else:
+        text += _rule(width=total_width)    # Top rule.
 
     # The table contents.
     for i in range(num_rows):

Modified: 
branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_table.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_table.py?rev=18708&r1=18707&r2=18708&view=diff
==============================================================================
--- 
branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_table.py 
(original)
+++ 
branches/frame_order_testing/test_suite/unit_tests/_lib/_text/test_table.py 
Fri Mar  8 15:47:48 2013
@@ -212,3 +212,41 @@
         self.assertEqual(len(true_table), len(table_lines))
         for i in range(len(table_lines)):
             self.assertEqual(true_table[i], table_lines[i])
+
+
+    def test_format_table5(self):
+        """Test 5 of the lib.text.table.format_table() function - no 
headings."""
+
+        # The table data.
+        contents = [
+            ['A', 2],
+            ['B', 2]
+        ]
+
+        # Create the table.
+        table = format_table(contents=contents)
+        table_lines = table.split('\n')
+
+        # The true table.
+        true_table = [
+            " _______ ",
+            "         ",
+            "  A   2  ",
+            "  B   2  ",
+            " _______ ",
+            "         ",
+            ""    # This is because split combined with a final \n character.
+        ]
+
+        # Printout.
+        print("The formatted table:")
+        for i in range(len(table_lines)):
+            print("'%s'" % table_lines[i])
+        print("\nWhat the table should look like:")
+        for i in range(len(true_table)):
+            print("'%s'" % true_table[i])
+
+        # Check the table.
+        self.assertEqual(len(true_table), len(table_lines))
+        for i in range(len(table_lines)):
+            self.assertEqual(true_table[i], table_lines[i])




Related Messages


Powered by MHonArc, Updated Fri Mar 08 16:20:02 2013