prettytable 0.6.1__zip → 0.7.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 → prettytable-0.7.1}/CHANGELOG +28 -12
- {prettytable-0.6.1 → prettytable-0.7.1}/COPYING +3 -1
- {prettytable-0.6.1/prettytable.egg-info → prettytable-0.7.1}/PKG-INFO +3 -1
- {prettytable-0.6.1 → prettytable-0.7.1}/README +48 -12
- {prettytable-0.6.1 → prettytable-0.7.1/prettytable.egg-info}/PKG-INFO +3 -1
- {prettytable-0.6.1 → prettytable-0.7.1}/prettytable.py +561 -185
- {prettytable-0.6.1 → prettytable-0.7.1}/prettytable_test.py +154 -24
- {prettytable-0.6.1 → prettytable-0.7.1}/setup.py +2 -0
- {prettytable-0.6.1 → prettytable-0.7.1}/MANIFEST.in +0 -0
- {prettytable-0.6.1 → prettytable-0.7.1}/prettytable.egg-info/SOURCES.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.1}/prettytable.egg-info/dependency_links.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.1}/prettytable.egg-info/top_level.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.1}/setup.cfg +0 -0
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
# coding=UTF-8
|
|
2
|
+
|
|
3
|
+
from prettytable import *
|
|
4
|
+
|
|
2
5
|
import sys
|
|
3
|
-
sys.
|
|
6
|
+
py3k = sys.version_info[0] >= 3
|
|
7
|
+
try:
|
|
8
|
+
import sqlite3
|
|
9
|
+
_have_sqlite = True
|
|
10
|
+
except ImportError:
|
|
11
|
+
_have_sqlite = False
|
|
12
|
+
if py3k:
|
|
13
|
+
import io as StringIO
|
|
14
|
+
else:
|
|
15
|
+
import StringIO
|
|
4
16
|
from math import pi, e, sqrt
|
|
5
|
-
|
|
17
|
+
import unittest
|
|
6
18
|
|
|
7
19
|
class BuildEquivelanceTest(unittest.TestCase):
|
|
8
20
|
|
|
@@ -98,7 +110,7 @@ class CityDataTest(unittest.TestCase):
|
|
|
98
110
|
|
|
99
111
|
class OptionOverrideTests(CityDataTest):
|
|
100
112
|
|
|
101
|
-
"""Make sure all options are properly overwritten by
|
|
113
|
+
"""Make sure all options are properly overwritten by get_string."""
|
|
102
114
|
|
|
103
115
|
def testBorder(self):
|
|
104
116
|
default = self.x.get_string()
|
|
@@ -121,6 +133,42 @@ class OptionOverrideTests(CityDataTest):
|
|
|
121
133
|
override = self.x.get_string(hrules=NONE)
|
|
122
134
|
self.assertTrue(default != override)
|
|
123
135
|
|
|
136
|
+
class OptionAttributeTests(CityDataTest):
|
|
137
|
+
|
|
138
|
+
"""Make sure all options which have an attribute interface work as they should.
|
|
139
|
+
Also make sure option settings are copied correctly when a table is cloned by
|
|
140
|
+
slicing."""
|
|
141
|
+
|
|
142
|
+
def testSetForAllColumns(self):
|
|
143
|
+
self.x.field_names = sorted(self.x.field_names)
|
|
144
|
+
self.x.align = "l"
|
|
145
|
+
self.x.max_width = 10
|
|
146
|
+
self.x.start = 2
|
|
147
|
+
self.x.end = 4
|
|
148
|
+
self.x.sortby = "Area"
|
|
149
|
+
self.x.reversesort = True
|
|
150
|
+
self.x.header = True
|
|
151
|
+
self.x.border = False
|
|
152
|
+
self.x.hrule = True
|
|
153
|
+
self.x.int_format = "4"
|
|
154
|
+
self.x.float_format = "2.2"
|
|
155
|
+
self.x.padding_width = 2
|
|
156
|
+
self.x.left_padding_width = 2
|
|
157
|
+
self.x.right_padding_width = 2
|
|
158
|
+
self.x.vertical_char = "!"
|
|
159
|
+
self.x.horizontal_char = "~"
|
|
160
|
+
self.x.junction_char = "*"
|
|
161
|
+
self.x.format = True
|
|
162
|
+
self.x.attributes = {"class" : "prettytable"}
|
|
163
|
+
assert self.x.get_string() == self.x[:].get_string()
|
|
164
|
+
|
|
165
|
+
def testSetForOneColumn(self):
|
|
166
|
+
self.x.align["Rainfall"] = "l"
|
|
167
|
+
self.x.max_width["Name"] = 10
|
|
168
|
+
self.x.int_format["Population"] = "4"
|
|
169
|
+
self.x.float_format["Area"] = "2.2"
|
|
170
|
+
assert self.x.get_string() == self.x[:].get_string()
|
|
171
|
+
|
|
124
172
|
class BasicTests(CityDataTest):
|
|
125
173
|
|
|
126
174
|
"""Some very basic tests."""
|
|
@@ -188,6 +236,10 @@ class SlicingTests(CityDataTest):
|
|
|
188
236
|
def setUp(self):
|
|
189
237
|
CityDataTest.setUp(self)
|
|
190
238
|
|
|
239
|
+
def testSliceAll(self):
|
|
240
|
+
y = self.x[:]
|
|
241
|
+
assert self.x.get_string() == y.get_string()
|
|
242
|
+
|
|
191
243
|
def testSliceFirstTwoRows(self):
|
|
192
244
|
y = self.x[0:2]
|
|
193
245
|
string = y.get_string()
|
|
@@ -265,7 +317,7 @@ class FloatFormatBasicTests(BasicTests):
|
|
|
265
317
|
|
|
266
318
|
def setUp(self):
|
|
267
319
|
BasicTests.setUp(self)
|
|
268
|
-
self.x.float_format = "6.
|
|
320
|
+
self.x.float_format = "6.2f"
|
|
269
321
|
|
|
270
322
|
class FloatFormatTests(unittest.TestCase):
|
|
271
323
|
|
|
@@ -276,12 +328,12 @@ class FloatFormatTests(unittest.TestCase):
|
|
|
276
328
|
self.x.add_row(["sqrt(2)", sqrt(2)])
|
|
277
329
|
|
|
278
330
|
def testNoDecimals(self):
|
|
279
|
-
self.x.float_format = ".
|
|
331
|
+
self.x.float_format = ".0f"
|
|
280
332
|
self.x.caching = False
|
|
281
333
|
assert "." not in self.x.get_string()
|
|
282
334
|
|
|
283
335
|
def testRoundTo5DP(self):
|
|
284
|
-
self.x.float_format = ".
|
|
336
|
+
self.x.float_format = ".5f"
|
|
285
337
|
string = self.x.get_string()
|
|
286
338
|
assert "3.14159" in string
|
|
287
339
|
assert "3.141592" not in string
|
|
@@ -292,7 +344,7 @@ class FloatFormatTests(unittest.TestCase):
|
|
|
292
344
|
assert "1.414213" not in string
|
|
293
345
|
|
|
294
346
|
def testPadWith2Zeroes(self):
|
|
295
|
-
self.x.float_format = "06.
|
|
347
|
+
self.x.float_format = "06.2f"
|
|
296
348
|
string = self.x.get_string()
|
|
297
349
|
assert "003.14" in string
|
|
298
350
|
assert "002.72" in string
|
|
@@ -303,7 +355,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
303
355
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
304
356
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
305
357
|
t.add_row(['value 3', 'value4'])
|
|
306
|
-
result = t.get_string(hrules=
|
|
358
|
+
result = t.get_string(hrules=ALL)
|
|
307
359
|
assert result.strip() == """
|
|
308
360
|
+---------+-------------+
|
|
309
361
|
| Field 1 | Field 2 |
|
|
@@ -318,7 +370,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
318
370
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
319
371
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
320
372
|
t.add_row(['value 3\n\nother line', 'value4\n\n\nvalue5'])
|
|
321
|
-
result = t.get_string(hrules=
|
|
373
|
+
result = t.get_string(hrules=ALL)
|
|
322
374
|
assert result.strip() == """
|
|
323
375
|
+------------+-------------+
|
|
324
376
|
| Field 1 | Field 2 |
|
|
@@ -354,16 +406,16 @@ class BreakLineTests(unittest.TestCase):
|
|
|
354
406
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
355
407
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
356
408
|
t.add_row(['value 3', 'value4'])
|
|
357
|
-
result = t.get_html_string(hrules=
|
|
409
|
+
result = t.get_html_string(hrules=ALL)
|
|
358
410
|
assert result.strip() == """
|
|
359
|
-
<table
|
|
411
|
+
<table>
|
|
360
412
|
<tr>
|
|
361
413
|
<th>Field 1</th>
|
|
362
414
|
<th>Field 2</th>
|
|
363
415
|
</tr>
|
|
364
416
|
<tr>
|
|
365
417
|
<td>value 1</td>
|
|
366
|
-
<td>value2<br
|
|
418
|
+
<td>value2<br>second line</td>
|
|
367
419
|
</tr>
|
|
368
420
|
<tr>
|
|
369
421
|
<td>value 3</td>
|
|
@@ -373,6 +425,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
373
425
|
""".strip()
|
|
374
426
|
|
|
375
427
|
class HtmlOutputTests(unittest.TestCase):
|
|
428
|
+
|
|
376
429
|
def testHtmlOutput(self):
|
|
377
430
|
t = PrettyTable(['Field 1', 'Field 2', 'Field 3'])
|
|
378
431
|
t.add_row(['value 1', 'value2', 'value3'])
|
|
@@ -380,7 +433,7 @@ class HtmlOutputTests(unittest.TestCase):
|
|
|
380
433
|
t.add_row(['value 7', 'value8', 'value9'])
|
|
381
434
|
result = t.get_html_string()
|
|
382
435
|
assert result.strip() == """
|
|
383
|
-
<table
|
|
436
|
+
<table>
|
|
384
437
|
<tr>
|
|
385
438
|
<th>Field 1</th>
|
|
386
439
|
<th>Field 2</th>
|
|
@@ -411,29 +464,106 @@ class HtmlOutputTests(unittest.TestCase):
|
|
|
411
464
|
t.add_row(['value 7', 'value8', 'value9'])
|
|
412
465
|
result = t.get_html_string(format=True)
|
|
413
466
|
assert result.strip() == """
|
|
414
|
-
<table
|
|
467
|
+
<table frame="box" rules="cols">
|
|
415
468
|
<tr>
|
|
416
469
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 1</th>
|
|
417
470
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 2</th>
|
|
418
471
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 3</th>
|
|
419
472
|
</tr>
|
|
420
473
|
<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>
|
|
474
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 1</td>
|
|
475
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value2</td>
|
|
476
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value3</td>
|
|
424
477
|
</tr>
|
|
425
478
|
<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>
|
|
479
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 4</td>
|
|
480
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value5</td>
|
|
481
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value6</td>
|
|
429
482
|
</tr>
|
|
430
483
|
<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>
|
|
484
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 7</td>
|
|
485
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value8</td>
|
|
486
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value9</td>
|
|
434
487
|
</tr>
|
|
435
488
|
</table>
|
|
436
489
|
""".strip()
|
|
437
490
|
|
|
491
|
+
class CsvConstructorTest(BasicTests):
|
|
492
|
+
|
|
493
|
+
def setUp(self):
|
|
494
|
+
|
|
495
|
+
csv_string = """City name, Area , Population , Annual Rainfall
|
|
496
|
+
Sydney, 2058 , 4336374 , 1214.8
|
|
497
|
+
Melbourne, 1566 , 3806092 , 646.9
|
|
498
|
+
Brisbane, 5905 , 1857594 , 1146.4
|
|
499
|
+
Perth, 5386 , 1554769 , 869.4
|
|
500
|
+
Adelaide, 1295 , 1158259 , 600.5
|
|
501
|
+
Hobart, 1357 , 205556 , 619.5
|
|
502
|
+
Darwin, 0112 , 120900 , 1714.7"""
|
|
503
|
+
csv_fp = StringIO.StringIO(csv_string)
|
|
504
|
+
self.x = from_csv(csv_fp)
|
|
505
|
+
|
|
506
|
+
if _have_sqlite:
|
|
507
|
+
class DatabaseConstructorTest(BasicTests):
|
|
508
|
+
|
|
509
|
+
def setUp(self):
|
|
510
|
+
self.conn = sqlite3.connect(":memory:")
|
|
511
|
+
self.cur = self.conn.cursor()
|
|
512
|
+
self.cur.execute("CREATE TABLE cities (name TEXT, area INTEGER, population INTEGER, rainfall REAL)")
|
|
513
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Adelaide\", 1295, 1158259, 600.5)")
|
|
514
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Brisbane\", 5905, 1857594, 1146.4)")
|
|
515
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Darwin\", 112, 120900, 1714.7)")
|
|
516
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Hobart\", 1357, 205556, 619.5)")
|
|
517
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Sydney\", 2058, 4336374, 1214.8)")
|
|
518
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Melbourne\", 1566, 3806092, 646.9)")
|
|
519
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Perth\", 5386, 1554769, 869.4)")
|
|
520
|
+
self.cur.execute("SELECT * FROM cities")
|
|
521
|
+
self.x = from_db_cursor(self.cur)
|
|
522
|
+
|
|
523
|
+
def testNonSelectCurosr(self):
|
|
524
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Adelaide\", 1295, 1158259, 600.5)")
|
|
525
|
+
assert from_db_cursor(self.cur) is None
|
|
526
|
+
|
|
527
|
+
class HtmlConstructorTest(CityDataTest):
|
|
528
|
+
|
|
529
|
+
def testHtmlAndBack(self):
|
|
530
|
+
html_string = self.x.get_html_string()
|
|
531
|
+
new_table = from_html(html_string)[0]
|
|
532
|
+
assert new_table.get_string() == self.x.get_string()
|
|
533
|
+
|
|
534
|
+
def testHtmlOneAndBack(self):
|
|
535
|
+
html_string = self.x.get_html_string()
|
|
536
|
+
new_table = from_html_one(html_string)
|
|
537
|
+
assert new_table.get_string() == self.x.get_string()
|
|
538
|
+
|
|
539
|
+
def testHtmlOneFailOnMany(self):
|
|
540
|
+
html_string = self.x.get_html_string()
|
|
541
|
+
html_string += self.x.get_html_string()
|
|
542
|
+
self.assertRaises(Exception, from_html_one, html_string)
|
|
543
|
+
|
|
544
|
+
class PrintEnglishTest(CityDataTest):
|
|
545
|
+
|
|
546
|
+
def testPrint(self):
|
|
547
|
+
print()
|
|
548
|
+
print(self.x)
|
|
549
|
+
|
|
550
|
+
class PrintJapanestTest(unittest.TestCase):
|
|
551
|
+
|
|
552
|
+
def setUp(self):
|
|
553
|
+
|
|
554
|
+
self.x = PrettyTable(["Kanji", "Hiragana", "English"])
|
|
555
|
+
self.x.add_row(["神戸", "こうべ", "Kobe"])
|
|
556
|
+
self.x.add_row(["京都", "きょうと", "Kyoto"])
|
|
557
|
+
self.x.add_row(["長崎", "ながさき", "Nagasaki"])
|
|
558
|
+
self.x.add_row(["名古屋", "なごや", "Nagoya"])
|
|
559
|
+
self.x.add_row(["大阪", "おおさか", "Osaka"])
|
|
560
|
+
self.x.add_row(["札幌", "さっぽろ", "Sapporo"])
|
|
561
|
+
self.x.add_row(["東京", "とうきょう", "Tokyo"])
|
|
562
|
+
self.x.add_row(["横浜", "よこはま", "Yokohama"])
|
|
563
|
+
|
|
564
|
+
def testPrint(self):
|
|
565
|
+
print()
|
|
566
|
+
print(self.x)
|
|
567
|
+
|
|
438
568
|
if __name__ == "__main__":
|
|
439
569
|
unittest.main()
|
|
@@ -7,6 +7,8 @@ setup(
|
|
|
7
7
|
version=version,
|
|
8
8
|
classifiers=[
|
|
9
9
|
'Programming Language :: Python',
|
|
10
|
+
'Programming Language :: Python :: 2.4',
|
|
11
|
+
'Programming Language :: Python :: 2.5',
|
|
10
12
|
'Programming Language :: Python :: 2.6',
|
|
11
13
|
'Programming Language :: Python :: 2.7',
|
|
12
14
|
'Programming Language :: Python :: 3',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|