prettytable 0.6__zip → 0.6.1__zip
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prettytable-0.6.1/CHANGELOG +126 -0
- prettytable-0.6.1/COPYING +28 -0
- prettytable-0.6.1/MANIFEST.in +4 -0
- {prettytable-0.6 → prettytable-0.6.1}/PKG-INFO +3 -3
- {prettytable-0.6 → prettytable-0.6.1}/prettytable.egg-info/PKG-INFO +3 -3
- {prettytable-0.6 → prettytable-0.6.1}/prettytable.egg-info/SOURCES.txt +4 -0
- {prettytable-0.6 → prettytable-0.6.1}/prettytable.py +7 -3
- prettytable-0.6.1/prettytable_test.py +439 -0
- {prettytable-0.6 → prettytable-0.6.1}/setup.py +3 -1
- {prettytable-0.6 → prettytable-0.6.1}/README +0 -0
- {prettytable-0.6 → prettytable-0.6.1}/prettytable.egg-info/dependency_links.txt +0 -0
- {prettytable-0.6 → prettytable-0.6.1}/prettytable.egg-info/top_level.txt +0 -0
- {prettytable-0.6 → prettytable-0.6.1}/setup.cfg +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
########## PrettyTable 0.6.1 - June 03, 2012 ##########
|
|
2
|
+
|
|
3
|
+
* Unicode encoding scheme can now be set by user
|
|
4
|
+
* __str__ now uses user-specified encoding instead of ASCII. This
|
|
5
|
+
fixes a bug where tables with non-ASCII characters would print
|
|
6
|
+
correctly with "print x.get_string()" but not "print x" in 2.x
|
|
7
|
+
(thanks to Google Code user kevincobain2000 for reporting this
|
|
8
|
+
bug!)
|
|
9
|
+
* Fixed an incompatibility with 3.0 and 3.1 (html.escape was new
|
|
10
|
+
in 3.2)
|
|
11
|
+
|
|
12
|
+
########## PrettyTable 0.6 - April 05, 2012 ##########
|
|
13
|
+
|
|
14
|
+
* Code is now simultaneously compatible with Python 2 and 3
|
|
15
|
+
* Replaced all setter methods with managed attributes
|
|
16
|
+
* All styling options can now be set persistently as managed attributes
|
|
17
|
+
* Added "add_style" method to make setting style options easily
|
|
18
|
+
* Added "del_row", "clear_rows" and "clear" methods to facilitate
|
|
19
|
+
removal of data from table.
|
|
20
|
+
* Added "copy" method to facilitate cloning of a table.
|
|
21
|
+
* Removed caching functionality, which added complexity and fragility
|
|
22
|
+
for relatively little gain
|
|
23
|
+
* Removed methods that just printed strings produced by get_string and
|
|
24
|
+
get_html_string - just use inbuilt print!
|
|
25
|
+
* Improved unicode support (thanks to Google Code user ru.w31rd0 for
|
|
26
|
+
patch!)
|
|
27
|
+
* Added support for decimal and floating point number formatting
|
|
28
|
+
support (thanks to Google Code user willfurnass for the suggestion!)
|
|
29
|
+
* Added support for using a custom key sorting methods (thanks to
|
|
30
|
+
Google Code user amannijhawan for the suggestion!)
|
|
31
|
+
* Added support for line breaks in data (suggested and implemented by
|
|
32
|
+
Klein Stephane)
|
|
33
|
+
* Added support for max column widths (thanks to Tibor Arpas for the
|
|
34
|
+
suggestion!)
|
|
35
|
+
* Fixed table slicing
|
|
36
|
+
* Fixed bug where closing <tr/> tags in HTML tables were not printed
|
|
37
|
+
(thanks to Google Code user kehander for reporting this bug!)
|
|
38
|
+
* Fixed HTML table sorting bug (thanks to Google Code user dougbeal
|
|
39
|
+
for reporting this bug!)
|
|
40
|
+
* Fixed bug whereby changing field_names did not recompute widths
|
|
41
|
+
(thanks to Google Code user denilsonsa for reporting this bug!)
|
|
42
|
+
|
|
43
|
+
########## PrettyTable 0.5 - May 26, 2009 ##########
|
|
44
|
+
|
|
45
|
+
* Fixed a bug whereby printing with headers=False and border=False
|
|
46
|
+
would introduce an extraneous newline. Thanks to Alexander Lamaison
|
|
47
|
+
for reporting this bug.
|
|
48
|
+
* When printing with headers=False, column widths will now be reduced
|
|
49
|
+
as appropriate in columns where the field name is wider than the
|
|
50
|
+
data. Thanks to Alexander Lamaison for suggesting this behaviour.
|
|
51
|
+
* Support for Unicode has improved. Thanks to Chris Clark for
|
|
52
|
+
submitting this improvement.
|
|
53
|
+
* The value of the "border" argument now correctly controls the
|
|
54
|
+
presence of a border when printing HTML tables with print_html or
|
|
55
|
+
get_html_string, instead of being incorrectly ignored. Thanks to
|
|
56
|
+
Chris Clark for fixing this.
|
|
57
|
+
* The print_html and get_html_string methods now accept an
|
|
58
|
+
"attributes" argument which is a dictionary of name/value pairs to be
|
|
59
|
+
placed inside the <table> tag (so you can, e.g. set class, name or id
|
|
60
|
+
values in order to style your table with CSS). Thanks to Chris Clark
|
|
61
|
+
for submitting this feature.
|
|
62
|
+
* The print_html and get_html_string methods now, by default, do their
|
|
63
|
+
best to match the various formatting options in their HTML output.
|
|
64
|
+
They use inline CSS to adjust the alignment of data in columns, the
|
|
65
|
+
padding widths of columns and in some cases the border settings. You
|
|
66
|
+
can give either method a "format=False" attribute to turn this
|
|
67
|
+
behaviour off if you want to do your own styling. With "format=False"
|
|
68
|
+
the methods print a "bare bones" table, similar to the default
|
|
69
|
+
behaviour in 0.4.
|
|
70
|
+
|
|
71
|
+
########## PrettyTable 0.4 - May 13, 2009 ##########
|
|
72
|
+
|
|
73
|
+
* Added "add_column" method to enable building tables up column-by-column.
|
|
74
|
+
* Added "print_HTML" and "get_HTML_string" methods to enable HTML table
|
|
75
|
+
production.
|
|
76
|
+
* Added "set_border_chars" method to enable control over characters used to
|
|
77
|
+
draw the table border.
|
|
78
|
+
* Added "set_left_padding" and "set_right_padding" methods to allow
|
|
79
|
+
independent padding control for both sides of a column.
|
|
80
|
+
* Added "sortby" option to enable column sorting.
|
|
81
|
+
* Added "header" option to enable switching off field name printing at top of
|
|
82
|
+
table.
|
|
83
|
+
* Modified "hrules" option to enable greater control over presence of
|
|
84
|
+
horizontal lines.
|
|
85
|
+
* Added "border" option to enable switching off all line printing.
|
|
86
|
+
|
|
87
|
+
Thanks to Tim Cera, Chris Clark, Alexander Lamaison for suggesting and helping
|
|
88
|
+
to test many of the new features in this release.
|
|
89
|
+
|
|
90
|
+
########## PrettyTable 0.3 - May 01, 2009 ##########
|
|
91
|
+
|
|
92
|
+
* Added "padding_width" option to control the number of spaces between the
|
|
93
|
+
vertical line rules at the edges of a column and its content. This can be
|
|
94
|
+
set as a keyword argument to the constructor or after instantiation using
|
|
95
|
+
the "set_padding_width" method. The value is set to 1 by defaut. If your
|
|
96
|
+
table is too wide for a small screen with this value, setting it to 0 might
|
|
97
|
+
help you squeeze it in.
|
|
98
|
+
|
|
99
|
+
Thanks to Chris Clark for contributing a patch against 0.2.1 to add this
|
|
100
|
+
feature!
|
|
101
|
+
|
|
102
|
+
########## PrettyTable 0.2.1 - April 29, 2009 ##########
|
|
103
|
+
|
|
104
|
+
* Caching no longer breaks when using the "printt(fields=[...])" syntax. The
|
|
105
|
+
list of fields was not hashable and hence could not be used as a dictionary
|
|
106
|
+
key. I fixed this using the output of the "cPickle" module's "dumps"
|
|
107
|
+
function as the dictionary key instead.
|
|
108
|
+
* Horizontal lines are now the appropriate length when the above syntax is
|
|
109
|
+
used.
|
|
110
|
+
|
|
111
|
+
Thanks to Julien Koesten for reporting these bugs and testing the fixes almost
|
|
112
|
+
immediately after the release of 0.2!
|
|
113
|
+
|
|
114
|
+
########## PrettyTable 0.2 - April 29, 2009 ##########
|
|
115
|
+
|
|
116
|
+
* Added "get_string" method.
|
|
117
|
+
* Added "__str__" method (which just calls "get_string") to enable nice
|
|
118
|
+
"print x" syntax.
|
|
119
|
+
* Can now pass field names as a constructor argument.
|
|
120
|
+
* Return values of "get_string" are cached in a dictionary that is only
|
|
121
|
+
cleared after a call to "add_row" or something else which invalidates the
|
|
122
|
+
cache.
|
|
123
|
+
|
|
124
|
+
########## PrettyTable 0.1 - February 26, 2009 #########
|
|
125
|
+
|
|
126
|
+
* Original release
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2009-2012 Luke Maurits <luke@maurits.id.au>
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
# With contributions from:
|
|
4
|
+
# * Chris Clark
|
|
5
|
+
# * Klein Stephane
|
|
6
|
+
#
|
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
|
8
|
+
# modification, are permitted provided that the following conditions are met:
|
|
9
|
+
#
|
|
10
|
+
# * Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
# this list of conditions and the following disclaimer.
|
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
# and/or other materials provided with the distribution.
|
|
15
|
+
# * The name of the author may not be used to endorse or promote products
|
|
16
|
+
# derived from this software without specific prior written permission.
|
|
17
|
+
#
|
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
22
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
23
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
24
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
25
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
26
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
27
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
28
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 1.
|
|
1
|
+
Metadata-Version: 1.0
|
|
2
2
|
Name: prettytable
|
|
3
|
-
Version: 0.6
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
|
|
5
5
|
Home-page: http://code.google.com/p/prettytable
|
|
6
6
|
Author: Luke Maurits
|
|
7
7
|
Author-email: luke@maurits.id.au
|
|
8
|
-
License:
|
|
8
|
+
License: BSD (3 clause)
|
|
9
9
|
Description: UNKNOWN
|
|
10
10
|
Platform: UNKNOWN
|
|
11
11
|
Classifier: Programming Language :: Python
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 1.
|
|
1
|
+
Metadata-Version: 1.0
|
|
2
2
|
Name: prettytable
|
|
3
|
-
Version: 0.6
|
|
3
|
+
Version: 0.6.1
|
|
4
4
|
Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
|
|
5
5
|
Home-page: http://code.google.com/p/prettytable
|
|
6
6
|
Author: Luke Maurits
|
|
7
7
|
Author-email: luke@maurits.id.au
|
|
8
|
-
License:
|
|
8
|
+
License: BSD (3 clause)
|
|
9
9
|
Description: UNKNOWN
|
|
10
10
|
Platform: UNKNOWN
|
|
11
11
|
Classifier: Programming Language :: Python
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
30
30
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
31
31
|
|
|
32
|
-
__version__ = "0.6"
|
|
32
|
+
__version__ = "0.6.1"
|
|
33
33
|
|
|
34
34
|
import sys
|
|
35
35
|
import copy
|
|
@@ -40,6 +40,7 @@ py3k = sys.version_info[0] >= 3
|
|
|
40
40
|
if py3k:
|
|
41
41
|
unicode = str
|
|
42
42
|
basestring = str
|
|
43
|
+
if py3k and sys.version_info[1] >= 2:
|
|
43
44
|
from html import escape
|
|
44
45
|
else:
|
|
45
46
|
from cgi import escape
|
|
@@ -75,13 +76,14 @@ def _unicode(value, encoding="UTF-8"):
|
|
|
75
76
|
|
|
76
77
|
class PrettyTable(object):
|
|
77
78
|
|
|
78
|
-
def __init__(self, field_names=None, **kwargs):
|
|
79
|
+
def __init__(self, field_names=None, encoding="UTF-8", **kwargs):
|
|
79
80
|
|
|
80
81
|
"""Return a new PrettyTable instance
|
|
81
82
|
|
|
82
83
|
Arguments:
|
|
83
84
|
|
|
84
85
|
field_names - list or tuple of field names
|
|
86
|
+
encoding - Unicode encoding scheme to use
|
|
85
87
|
fields - list or tuple of field names to include in displays
|
|
86
88
|
start - index of first data row to include in output
|
|
87
89
|
end - index of last data row to include in output PLUS ONE (list slice style)
|
|
@@ -101,6 +103,8 @@ class PrettyTable(object):
|
|
|
101
103
|
sort_key - sorting key function, applied to data points before sorting
|
|
102
104
|
reversesort - True or False to sort in descending or ascending order"""
|
|
103
105
|
|
|
106
|
+
self.encoding = encoding
|
|
107
|
+
|
|
104
108
|
# Data
|
|
105
109
|
self._field_names = []
|
|
106
110
|
self._align = {}
|
|
@@ -177,7 +181,7 @@ class PrettyTable(object):
|
|
|
177
181
|
if py3k:
|
|
178
182
|
return self.get_string()
|
|
179
183
|
else:
|
|
180
|
-
return self.get_string().encode(
|
|
184
|
+
return self.get_string().encode(self.encoding)
|
|
181
185
|
|
|
182
186
|
def __unicode__(self):
|
|
183
187
|
return self.get_string()
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import sys
|
|
3
|
+
sys.path.append("../src/")
|
|
4
|
+
from math import pi, e, sqrt
|
|
5
|
+
from prettytable import *
|
|
6
|
+
|
|
7
|
+
class BuildEquivelanceTest(unittest.TestCase):
|
|
8
|
+
|
|
9
|
+
"""Make sure that building a table row-by-row and column-by-column yield the same results"""
|
|
10
|
+
|
|
11
|
+
def setUp(self):
|
|
12
|
+
|
|
13
|
+
# Row by row...
|
|
14
|
+
self.row = PrettyTable()
|
|
15
|
+
self.row.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
|
|
16
|
+
self.row.add_row(["Adelaide",1295, 1158259, 600.5])
|
|
17
|
+
self.row.add_row(["Brisbane",5905, 1857594, 1146.4])
|
|
18
|
+
self.row.add_row(["Darwin", 112, 120900, 1714.7])
|
|
19
|
+
self.row.add_row(["Hobart", 1357, 205556, 619.5])
|
|
20
|
+
self.row.add_row(["Sydney", 2058, 4336374, 1214.8])
|
|
21
|
+
self.row.add_row(["Melbourne", 1566, 3806092, 646.9])
|
|
22
|
+
self.row.add_row(["Perth", 5386, 1554769, 869.4])
|
|
23
|
+
|
|
24
|
+
# Column by column...
|
|
25
|
+
self.col = PrettyTable()
|
|
26
|
+
self.col.add_column("City name",["Adelaide","Brisbane","Darwin","Hobart","Sydney","Melbourne","Perth"])
|
|
27
|
+
self.col.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5386])
|
|
28
|
+
self.col.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769])
|
|
29
|
+
self.col.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4])
|
|
30
|
+
|
|
31
|
+
# A mix of both!
|
|
32
|
+
self.mix = PrettyTable()
|
|
33
|
+
self.mix.field_names = ["City name", "Area"]
|
|
34
|
+
self.mix.add_row(["Adelaide",1295])
|
|
35
|
+
self.mix.add_row(["Brisbane",5905])
|
|
36
|
+
self.mix.add_row(["Darwin", 112])
|
|
37
|
+
self.mix.add_row(["Hobart", 1357])
|
|
38
|
+
self.mix.add_row(["Sydney", 2058])
|
|
39
|
+
self.mix.add_row(["Melbourne", 1566])
|
|
40
|
+
self.mix.add_row(["Perth", 5386])
|
|
41
|
+
self.mix.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092, 1554769])
|
|
42
|
+
self.mix.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9, 869.4])
|
|
43
|
+
|
|
44
|
+
def testRowColEquivalenceASCII(self):
|
|
45
|
+
|
|
46
|
+
self.assertEqual(self.row.get_string(), self.col.get_string())
|
|
47
|
+
|
|
48
|
+
def testRowMixEquivalenceASCII(self):
|
|
49
|
+
|
|
50
|
+
self.assertEqual(self.row.get_string(), self.mix.get_string())
|
|
51
|
+
|
|
52
|
+
def testRowColEquivalenceHTML(self):
|
|
53
|
+
|
|
54
|
+
self.assertEqual(self.row.get_html_string(), self.col.get_html_string())
|
|
55
|
+
|
|
56
|
+
def testRowMixEquivalenceHTML(self):
|
|
57
|
+
|
|
58
|
+
self.assertEqual(self.row.get_html_string(), self.mix.get_html_string())
|
|
59
|
+
|
|
60
|
+
#class FieldnamelessTableTest(unittest.TestCase):
|
|
61
|
+
#
|
|
62
|
+
# """Make sure that building and stringing a table with no fieldnames works fine"""
|
|
63
|
+
#
|
|
64
|
+
# def setUp(self):
|
|
65
|
+
# self.x = PrettyTable()
|
|
66
|
+
# self.x.add_row(["Adelaide",1295, 1158259, 600.5])
|
|
67
|
+
# self.x.add_row(["Brisbane",5905, 1857594, 1146.4])
|
|
68
|
+
# self.x.add_row(["Darwin", 112, 120900, 1714.7])
|
|
69
|
+
# self.x.add_row(["Hobart", 1357, 205556, 619.5])
|
|
70
|
+
# self.x.add_row(["Sydney", 2058, 4336374, 1214.8])
|
|
71
|
+
# self.x.add_row(["Melbourne", 1566, 3806092, 646.9])
|
|
72
|
+
# self.x.add_row(["Perth", 5386, 1554769, 869.4])
|
|
73
|
+
#
|
|
74
|
+
# def testCanStringASCII(self):
|
|
75
|
+
# self.x.get_string()
|
|
76
|
+
#
|
|
77
|
+
# def testCanStringHTML(self):
|
|
78
|
+
# self.x.get_html_string()
|
|
79
|
+
#
|
|
80
|
+
# def testAddFieldnamesLater(self):
|
|
81
|
+
# self.x.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
|
|
82
|
+
# self.x.get_string()
|
|
83
|
+
|
|
84
|
+
class CityDataTest(unittest.TestCase):
|
|
85
|
+
|
|
86
|
+
"""Just build the Australian capital city data example table."""
|
|
87
|
+
|
|
88
|
+
def setUp(self):
|
|
89
|
+
|
|
90
|
+
self.x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
|
|
91
|
+
self.x.add_row(["Adelaide",1295, 1158259, 600.5])
|
|
92
|
+
self.x.add_row(["Brisbane",5905, 1857594, 1146.4])
|
|
93
|
+
self.x.add_row(["Darwin", 112, 120900, 1714.7])
|
|
94
|
+
self.x.add_row(["Hobart", 1357, 205556, 619.5])
|
|
95
|
+
self.x.add_row(["Sydney", 2058, 4336374, 1214.8])
|
|
96
|
+
self.x.add_row(["Melbourne", 1566, 3806092, 646.9])
|
|
97
|
+
self.x.add_row(["Perth", 5386, 1554769, 869.4])
|
|
98
|
+
|
|
99
|
+
class OptionOverrideTests(CityDataTest):
|
|
100
|
+
|
|
101
|
+
"""Make sure all options are properly overwritten by printt."""
|
|
102
|
+
|
|
103
|
+
def testBorder(self):
|
|
104
|
+
default = self.x.get_string()
|
|
105
|
+
override = self.x.get_string(border=False)
|
|
106
|
+
self.assertTrue(default != override)
|
|
107
|
+
|
|
108
|
+
def testHeader(self):
|
|
109
|
+
default = self.x.get_string()
|
|
110
|
+
override = self.x.get_string(header=False)
|
|
111
|
+
self.assertTrue(default != override)
|
|
112
|
+
|
|
113
|
+
def testHrulesAll(self):
|
|
114
|
+
default = self.x.get_string()
|
|
115
|
+
override = self.x.get_string(hrules=ALL)
|
|
116
|
+
self.assertTrue(default != override)
|
|
117
|
+
|
|
118
|
+
def testHrulesNone(self):
|
|
119
|
+
|
|
120
|
+
default = self.x.get_string()
|
|
121
|
+
override = self.x.get_string(hrules=NONE)
|
|
122
|
+
self.assertTrue(default != override)
|
|
123
|
+
|
|
124
|
+
class BasicTests(CityDataTest):
|
|
125
|
+
|
|
126
|
+
"""Some very basic tests."""
|
|
127
|
+
|
|
128
|
+
def testNoBlankLines(self):
|
|
129
|
+
|
|
130
|
+
"""No table should ever have blank lines in it."""
|
|
131
|
+
|
|
132
|
+
string = self.x.get_string()
|
|
133
|
+
lines = string.split("\n")
|
|
134
|
+
self.assertTrue("" not in lines)
|
|
135
|
+
|
|
136
|
+
def testAllLengthsEqual(self):
|
|
137
|
+
|
|
138
|
+
"""All lines in a table should be of the same length."""
|
|
139
|
+
|
|
140
|
+
string = self.x.get_string()
|
|
141
|
+
lines = string.split("\n")
|
|
142
|
+
lengths = [len(line) for line in lines]
|
|
143
|
+
lengths = set(lengths)
|
|
144
|
+
self.assertEqual(len(lengths),1)
|
|
145
|
+
|
|
146
|
+
class NoBorderBasicTests(BasicTests):
|
|
147
|
+
|
|
148
|
+
"""Run the basic tests with border = False"""
|
|
149
|
+
|
|
150
|
+
def setUp(self):
|
|
151
|
+
BasicTests.setUp(self)
|
|
152
|
+
self.x.border = False
|
|
153
|
+
|
|
154
|
+
class NoHeaderBasicTests(BasicTests):
|
|
155
|
+
|
|
156
|
+
"""Run the basic tests with header = False"""
|
|
157
|
+
|
|
158
|
+
def setUp(self):
|
|
159
|
+
BasicTests.setUp(self)
|
|
160
|
+
self.x.header = False
|
|
161
|
+
|
|
162
|
+
class HrulesNoneBasicTests(BasicTests):
|
|
163
|
+
|
|
164
|
+
"""Run the basic tests with hrules = NONE"""
|
|
165
|
+
|
|
166
|
+
def setUp(self):
|
|
167
|
+
BasicTests.setUp(self)
|
|
168
|
+
self.x.hrules = NONE
|
|
169
|
+
|
|
170
|
+
class HrulesAllBasicTests(BasicTests):
|
|
171
|
+
|
|
172
|
+
"""Run the basic tests with hrules = ALL"""
|
|
173
|
+
|
|
174
|
+
def setUp(self):
|
|
175
|
+
BasicTests.setUp(self)
|
|
176
|
+
self.x.hrules = ALL
|
|
177
|
+
|
|
178
|
+
class PresetBasicTests(BasicTests):
|
|
179
|
+
|
|
180
|
+
"""Run the basic tests after using set_style"""
|
|
181
|
+
|
|
182
|
+
def setUp(self):
|
|
183
|
+
BasicTests.setUp(self)
|
|
184
|
+
self.x.set_style(MSWORD_FRIENDLY)
|
|
185
|
+
|
|
186
|
+
class SlicingTests(CityDataTest):
|
|
187
|
+
|
|
188
|
+
def setUp(self):
|
|
189
|
+
CityDataTest.setUp(self)
|
|
190
|
+
|
|
191
|
+
def testSliceFirstTwoRows(self):
|
|
192
|
+
y = self.x[0:2]
|
|
193
|
+
string = y.get_string()
|
|
194
|
+
assert len(string.split("\n")) == 6
|
|
195
|
+
assert "Adelaide" in string
|
|
196
|
+
assert "Brisbane" in string
|
|
197
|
+
assert "Melbourne" not in string
|
|
198
|
+
assert "Perth" not in string
|
|
199
|
+
|
|
200
|
+
def testSliceLastTwoRows(self):
|
|
201
|
+
y = self.x[-2:]
|
|
202
|
+
string = y.get_string()
|
|
203
|
+
assert len(string.split("\n")) == 6
|
|
204
|
+
assert "Adelaide" not in string
|
|
205
|
+
assert "Brisbane" not in string
|
|
206
|
+
assert "Melbourne" in string
|
|
207
|
+
assert "Perth" in string
|
|
208
|
+
|
|
209
|
+
class SortingTests(CityDataTest):
|
|
210
|
+
|
|
211
|
+
def setUp(self):
|
|
212
|
+
CityDataTest.setUp(self)
|
|
213
|
+
|
|
214
|
+
def testSortBy(self):
|
|
215
|
+
self.x.sortby = self.x.field_names[0]
|
|
216
|
+
old = self.x.get_string()
|
|
217
|
+
for field in self.x.field_names[1:]:
|
|
218
|
+
self.x.sortby = field
|
|
219
|
+
new = self.x.get_string()
|
|
220
|
+
assert new != old
|
|
221
|
+
|
|
222
|
+
def testReverseSort(self):
|
|
223
|
+
for field in self.x.field_names:
|
|
224
|
+
self.x.sortby = field
|
|
225
|
+
self.x.reversesort = False
|
|
226
|
+
forward = self.x.get_string()
|
|
227
|
+
self.x.reversesort = True
|
|
228
|
+
backward = self.x.get_string()
|
|
229
|
+
forward_lines = forward.split("\n")[2:] # Discard header lines
|
|
230
|
+
backward_lines = backward.split("\n")[2:]
|
|
231
|
+
backward_lines.reverse()
|
|
232
|
+
assert forward_lines == backward_lines
|
|
233
|
+
|
|
234
|
+
def testSortKey(self):
|
|
235
|
+
# Test sorting by length of city name
|
|
236
|
+
def key(vals):
|
|
237
|
+
vals[0] = len(vals[0])
|
|
238
|
+
return vals
|
|
239
|
+
self.x.sortby = "City name"
|
|
240
|
+
self.x.sort_key = key
|
|
241
|
+
assert self.x.get_string().strip() == """+-----------+------+------------+-----------------+
|
|
242
|
+
| City name | Area | Population | Annual Rainfall |
|
|
243
|
+
+-----------+------+------------+-----------------+
|
|
244
|
+
| Perth | 5386 | 1554769 | 869.4 |
|
|
245
|
+
| Darwin | 112 | 120900 | 1714.7 |
|
|
246
|
+
| Hobart | 1357 | 205556 | 619.5 |
|
|
247
|
+
| Sydney | 2058 | 4336374 | 1214.8 |
|
|
248
|
+
| Adelaide | 1295 | 1158259 | 600.5 |
|
|
249
|
+
| Brisbane | 5905 | 1857594 | 1146.4 |
|
|
250
|
+
| Melbourne | 1566 | 3806092 | 646.9 |
|
|
251
|
+
+-----------+------+------------+-----------------+
|
|
252
|
+
""".strip()
|
|
253
|
+
|
|
254
|
+
class IntegerFormatBasicTests(BasicTests):
|
|
255
|
+
|
|
256
|
+
"""Run the basic tests after setting an integer format string"""
|
|
257
|
+
|
|
258
|
+
def setUp(self):
|
|
259
|
+
BasicTests.setUp(self)
|
|
260
|
+
self.x.int_format = "04"
|
|
261
|
+
|
|
262
|
+
class FloatFormatBasicTests(BasicTests):
|
|
263
|
+
|
|
264
|
+
"""Run the basic tests after setting a float format string"""
|
|
265
|
+
|
|
266
|
+
def setUp(self):
|
|
267
|
+
BasicTests.setUp(self)
|
|
268
|
+
self.x.float_format = "6.2"
|
|
269
|
+
|
|
270
|
+
class FloatFormatTests(unittest.TestCase):
|
|
271
|
+
|
|
272
|
+
def setUp(self):
|
|
273
|
+
self.x = PrettyTable(["Constant", "Value"])
|
|
274
|
+
self.x.add_row(["Pi", pi])
|
|
275
|
+
self.x.add_row(["e", e])
|
|
276
|
+
self.x.add_row(["sqrt(2)", sqrt(2)])
|
|
277
|
+
|
|
278
|
+
def testNoDecimals(self):
|
|
279
|
+
self.x.float_format = ".0"
|
|
280
|
+
self.x.caching = False
|
|
281
|
+
assert "." not in self.x.get_string()
|
|
282
|
+
|
|
283
|
+
def testRoundTo5DP(self):
|
|
284
|
+
self.x.float_format = ".5"
|
|
285
|
+
string = self.x.get_string()
|
|
286
|
+
assert "3.14159" in string
|
|
287
|
+
assert "3.141592" not in string
|
|
288
|
+
assert "2.71828" in string
|
|
289
|
+
assert "2.718281" not in string
|
|
290
|
+
assert "2.718282" not in string
|
|
291
|
+
assert "1.41421" in string
|
|
292
|
+
assert "1.414213" not in string
|
|
293
|
+
|
|
294
|
+
def testPadWith2Zeroes(self):
|
|
295
|
+
self.x.float_format = "06.2"
|
|
296
|
+
string = self.x.get_string()
|
|
297
|
+
assert "003.14" in string
|
|
298
|
+
assert "002.72" in string
|
|
299
|
+
assert "001.41" in string
|
|
300
|
+
|
|
301
|
+
class BreakLineTests(unittest.TestCase):
|
|
302
|
+
def testAsciiBreakLine(self):
|
|
303
|
+
t = PrettyTable(['Field 1', 'Field 2'])
|
|
304
|
+
t.add_row(['value 1', 'value2\nsecond line'])
|
|
305
|
+
t.add_row(['value 3', 'value4'])
|
|
306
|
+
result = t.get_string(hrules=True)
|
|
307
|
+
assert result.strip() == """
|
|
308
|
+
+---------+-------------+
|
|
309
|
+
| Field 1 | Field 2 |
|
|
310
|
+
+---------+-------------+
|
|
311
|
+
| value 1 | value2 |
|
|
312
|
+
| | second line |
|
|
313
|
+
+---------+-------------+
|
|
314
|
+
| value 3 | value4 |
|
|
315
|
+
+---------+-------------+
|
|
316
|
+
""".strip()
|
|
317
|
+
|
|
318
|
+
t = PrettyTable(['Field 1', 'Field 2'])
|
|
319
|
+
t.add_row(['value 1', 'value2\nsecond line'])
|
|
320
|
+
t.add_row(['value 3\n\nother line', 'value4\n\n\nvalue5'])
|
|
321
|
+
result = t.get_string(hrules=True)
|
|
322
|
+
assert result.strip() == """
|
|
323
|
+
+------------+-------------+
|
|
324
|
+
| Field 1 | Field 2 |
|
|
325
|
+
+------------+-------------+
|
|
326
|
+
| value 1 | value2 |
|
|
327
|
+
| | second line |
|
|
328
|
+
+------------+-------------+
|
|
329
|
+
| value 3 | value4 |
|
|
330
|
+
| | |
|
|
331
|
+
| other line | |
|
|
332
|
+
| | value5 |
|
|
333
|
+
+------------+-------------+
|
|
334
|
+
""".strip()
|
|
335
|
+
|
|
336
|
+
t = PrettyTable(['Field 1', 'Field 2'])
|
|
337
|
+
t.add_row(['value 1', 'value2\nsecond line'])
|
|
338
|
+
t.add_row(['value 3\n\nother line', 'value4\n\n\nvalue5'])
|
|
339
|
+
result = t.get_string()
|
|
340
|
+
assert result.strip() == """
|
|
341
|
+
+------------+-------------+
|
|
342
|
+
| Field 1 | Field 2 |
|
|
343
|
+
+------------+-------------+
|
|
344
|
+
| value 1 | value2 |
|
|
345
|
+
| | second line |
|
|
346
|
+
| value 3 | value4 |
|
|
347
|
+
| | |
|
|
348
|
+
| other line | |
|
|
349
|
+
| | value5 |
|
|
350
|
+
+------------+-------------+
|
|
351
|
+
""".strip()
|
|
352
|
+
|
|
353
|
+
def testHtmlBreakLine(self):
|
|
354
|
+
t = PrettyTable(['Field 1', 'Field 2'])
|
|
355
|
+
t.add_row(['value 1', 'value2\nsecond line'])
|
|
356
|
+
t.add_row(['value 3', 'value4'])
|
|
357
|
+
result = t.get_html_string(hrules=True)
|
|
358
|
+
assert result.strip() == """
|
|
359
|
+
<table border="1">
|
|
360
|
+
<tr>
|
|
361
|
+
<th>Field 1</th>
|
|
362
|
+
<th>Field 2</th>
|
|
363
|
+
</tr>
|
|
364
|
+
<tr>
|
|
365
|
+
<td>value 1</td>
|
|
366
|
+
<td>value2<br />second line</td>
|
|
367
|
+
</tr>
|
|
368
|
+
<tr>
|
|
369
|
+
<td>value 3</td>
|
|
370
|
+
<td>value4</td>
|
|
371
|
+
</tr>
|
|
372
|
+
</table>
|
|
373
|
+
""".strip()
|
|
374
|
+
|
|
375
|
+
class HtmlOutputTests(unittest.TestCase):
|
|
376
|
+
def testHtmlOutput(self):
|
|
377
|
+
t = PrettyTable(['Field 1', 'Field 2', 'Field 3'])
|
|
378
|
+
t.add_row(['value 1', 'value2', 'value3'])
|
|
379
|
+
t.add_row(['value 4', 'value5', 'value6'])
|
|
380
|
+
t.add_row(['value 7', 'value8', 'value9'])
|
|
381
|
+
result = t.get_html_string()
|
|
382
|
+
assert result.strip() == """
|
|
383
|
+
<table border="1">
|
|
384
|
+
<tr>
|
|
385
|
+
<th>Field 1</th>
|
|
386
|
+
<th>Field 2</th>
|
|
387
|
+
<th>Field 3</th>
|
|
388
|
+
</tr>
|
|
389
|
+
<tr>
|
|
390
|
+
<td>value 1</td>
|
|
391
|
+
<td>value2</td>
|
|
392
|
+
<td>value3</td>
|
|
393
|
+
</tr>
|
|
394
|
+
<tr>
|
|
395
|
+
<td>value 4</td>
|
|
396
|
+
<td>value5</td>
|
|
397
|
+
<td>value6</td>
|
|
398
|
+
</tr>
|
|
399
|
+
<tr>
|
|
400
|
+
<td>value 7</td>
|
|
401
|
+
<td>value8</td>
|
|
402
|
+
<td>value9</td>
|
|
403
|
+
</tr>
|
|
404
|
+
</table>
|
|
405
|
+
""".strip()
|
|
406
|
+
|
|
407
|
+
def testHtmlOutputFormated(self):
|
|
408
|
+
t = PrettyTable(['Field 1', 'Field 2', 'Field 3'])
|
|
409
|
+
t.add_row(['value 1', 'value2', 'value3'])
|
|
410
|
+
t.add_row(['value 4', 'value5', 'value6'])
|
|
411
|
+
t.add_row(['value 7', 'value8', 'value9'])
|
|
412
|
+
result = t.get_html_string(format=True)
|
|
413
|
+
assert result.strip() == """
|
|
414
|
+
<table border="1">
|
|
415
|
+
<tr>
|
|
416
|
+
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 1</th>
|
|
417
|
+
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 2</th>
|
|
418
|
+
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 3</th>
|
|
419
|
+
</tr>
|
|
420
|
+
<tr>
|
|
421
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value 1</td>
|
|
422
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value2</td>
|
|
423
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value3</td>
|
|
424
|
+
</tr>
|
|
425
|
+
<tr>
|
|
426
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value 4</td>
|
|
427
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value5</td>
|
|
428
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value6</td>
|
|
429
|
+
</tr>
|
|
430
|
+
<tr>
|
|
431
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value 7</td>
|
|
432
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value8</td>
|
|
433
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center">value9</td>
|
|
434
|
+
</tr>
|
|
435
|
+
</table>
|
|
436
|
+
""".strip()
|
|
437
|
+
|
|
438
|
+
if __name__ == "__main__":
|
|
439
|
+
unittest.main()
|
|
@@ -13,9 +13,11 @@ setup(
|
|
|
13
13
|
'License :: OSI Approved :: BSD License',
|
|
14
14
|
'Topic :: Text Processing'
|
|
15
15
|
],
|
|
16
|
+
license="BSD (3 clause)",
|
|
16
17
|
description='A simple Python library for easily displaying tabular data in a visually appealing ASCII table format',
|
|
17
18
|
author='Luke Maurits',
|
|
18
19
|
author_email='luke@maurits.id.au',
|
|
19
20
|
url='http://code.google.com/p/prettytable',
|
|
20
|
-
py_modules=['prettytable']
|
|
21
|
+
py_modules=['prettytable'],
|
|
22
|
+
test_suite = "prettytable_test"
|
|
21
23
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|