prettytable 0.6.1__zip → 0.7.2__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.2}/CHANGELOG +28 -12
- {prettytable-0.6.1 → prettytable-0.7.2}/COPYING +3 -1
- {prettytable-0.6.1/prettytable.egg-info → prettytable-0.7.2}/PKG-INFO +3 -1
- {prettytable-0.6.1 → prettytable-0.7.2}/README +48 -12
- {prettytable-0.6.1 → prettytable-0.7.2/prettytable.egg-info}/PKG-INFO +3 -1
- {prettytable-0.6.1 → prettytable-0.7.2}/prettytable.py +590 -187
- {prettytable-0.6.1 → prettytable-0.7.2}/prettytable_test.py +173 -24
- {prettytable-0.6.1 → prettytable-0.7.2}/setup.py +2 -0
- {prettytable-0.6.1 → prettytable-0.7.2}/MANIFEST.in +0 -0
- {prettytable-0.6.1 → prettytable-0.7.2}/prettytable.egg-info/SOURCES.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.2}/prettytable.egg-info/dependency_links.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.2}/prettytable.egg-info/top_level.txt +0 -0
- {prettytable-0.6.1 → prettytable-0.7.2}/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."""
|
|
@@ -175,6 +223,25 @@ class HrulesAllBasicTests(BasicTests):
|
|
|
175
223
|
BasicTests.setUp(self)
|
|
176
224
|
self.x.hrules = ALL
|
|
177
225
|
|
|
226
|
+
class EmptyTableTests(CityDataTest):
|
|
227
|
+
|
|
228
|
+
"""Make sure the print_empty option works"""
|
|
229
|
+
|
|
230
|
+
def setUp(self):
|
|
231
|
+
CityDataTest.setUp(self)
|
|
232
|
+
self.y = PrettyTable()
|
|
233
|
+
self.y.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
|
|
234
|
+
|
|
235
|
+
def testPrintEmptyTrue(self):
|
|
236
|
+
assert self.y.get_string(print_empty=True) != ""
|
|
237
|
+
assert self.x.get_string(print_empty=True) != self.y.get_string(print_empty=True)
|
|
238
|
+
|
|
239
|
+
def testPrintEmptyFalse(self):
|
|
240
|
+
assert self.y.get_string(print_empty=False) == ""
|
|
241
|
+
assert self.y.get_string(print_empty=False) != self.x.get_string(print_empty=False)
|
|
242
|
+
|
|
243
|
+
def testInteractionWithBorder(self):
|
|
244
|
+
assert self.y.get_string(border=False, print_empty=True) == ""
|
|
178
245
|
class PresetBasicTests(BasicTests):
|
|
179
246
|
|
|
180
247
|
"""Run the basic tests after using set_style"""
|
|
@@ -188,6 +255,10 @@ class SlicingTests(CityDataTest):
|
|
|
188
255
|
def setUp(self):
|
|
189
256
|
CityDataTest.setUp(self)
|
|
190
257
|
|
|
258
|
+
def testSliceAll(self):
|
|
259
|
+
y = self.x[:]
|
|
260
|
+
assert self.x.get_string() == y.get_string()
|
|
261
|
+
|
|
191
262
|
def testSliceFirstTwoRows(self):
|
|
192
263
|
y = self.x[0:2]
|
|
193
264
|
string = y.get_string()
|
|
@@ -265,7 +336,7 @@ class FloatFormatBasicTests(BasicTests):
|
|
|
265
336
|
|
|
266
337
|
def setUp(self):
|
|
267
338
|
BasicTests.setUp(self)
|
|
268
|
-
self.x.float_format = "6.
|
|
339
|
+
self.x.float_format = "6.2f"
|
|
269
340
|
|
|
270
341
|
class FloatFormatTests(unittest.TestCase):
|
|
271
342
|
|
|
@@ -276,12 +347,12 @@ class FloatFormatTests(unittest.TestCase):
|
|
|
276
347
|
self.x.add_row(["sqrt(2)", sqrt(2)])
|
|
277
348
|
|
|
278
349
|
def testNoDecimals(self):
|
|
279
|
-
self.x.float_format = ".
|
|
350
|
+
self.x.float_format = ".0f"
|
|
280
351
|
self.x.caching = False
|
|
281
352
|
assert "." not in self.x.get_string()
|
|
282
353
|
|
|
283
354
|
def testRoundTo5DP(self):
|
|
284
|
-
self.x.float_format = ".
|
|
355
|
+
self.x.float_format = ".5f"
|
|
285
356
|
string = self.x.get_string()
|
|
286
357
|
assert "3.14159" in string
|
|
287
358
|
assert "3.141592" not in string
|
|
@@ -292,7 +363,7 @@ class FloatFormatTests(unittest.TestCase):
|
|
|
292
363
|
assert "1.414213" not in string
|
|
293
364
|
|
|
294
365
|
def testPadWith2Zeroes(self):
|
|
295
|
-
self.x.float_format = "06.
|
|
366
|
+
self.x.float_format = "06.2f"
|
|
296
367
|
string = self.x.get_string()
|
|
297
368
|
assert "003.14" in string
|
|
298
369
|
assert "002.72" in string
|
|
@@ -303,7 +374,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
303
374
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
304
375
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
305
376
|
t.add_row(['value 3', 'value4'])
|
|
306
|
-
result = t.get_string(hrules=
|
|
377
|
+
result = t.get_string(hrules=ALL)
|
|
307
378
|
assert result.strip() == """
|
|
308
379
|
+---------+-------------+
|
|
309
380
|
| Field 1 | Field 2 |
|
|
@@ -318,7 +389,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
318
389
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
319
390
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
320
391
|
t.add_row(['value 3\n\nother line', 'value4\n\n\nvalue5'])
|
|
321
|
-
result = t.get_string(hrules=
|
|
392
|
+
result = t.get_string(hrules=ALL)
|
|
322
393
|
assert result.strip() == """
|
|
323
394
|
+------------+-------------+
|
|
324
395
|
| Field 1 | Field 2 |
|
|
@@ -354,16 +425,16 @@ class BreakLineTests(unittest.TestCase):
|
|
|
354
425
|
t = PrettyTable(['Field 1', 'Field 2'])
|
|
355
426
|
t.add_row(['value 1', 'value2\nsecond line'])
|
|
356
427
|
t.add_row(['value 3', 'value4'])
|
|
357
|
-
result = t.get_html_string(hrules=
|
|
428
|
+
result = t.get_html_string(hrules=ALL)
|
|
358
429
|
assert result.strip() == """
|
|
359
|
-
<table
|
|
430
|
+
<table>
|
|
360
431
|
<tr>
|
|
361
432
|
<th>Field 1</th>
|
|
362
433
|
<th>Field 2</th>
|
|
363
434
|
</tr>
|
|
364
435
|
<tr>
|
|
365
436
|
<td>value 1</td>
|
|
366
|
-
<td>value2<br
|
|
437
|
+
<td>value2<br>second line</td>
|
|
367
438
|
</tr>
|
|
368
439
|
<tr>
|
|
369
440
|
<td>value 3</td>
|
|
@@ -373,6 +444,7 @@ class BreakLineTests(unittest.TestCase):
|
|
|
373
444
|
""".strip()
|
|
374
445
|
|
|
375
446
|
class HtmlOutputTests(unittest.TestCase):
|
|
447
|
+
|
|
376
448
|
def testHtmlOutput(self):
|
|
377
449
|
t = PrettyTable(['Field 1', 'Field 2', 'Field 3'])
|
|
378
450
|
t.add_row(['value 1', 'value2', 'value3'])
|
|
@@ -380,7 +452,7 @@ class HtmlOutputTests(unittest.TestCase):
|
|
|
380
452
|
t.add_row(['value 7', 'value8', 'value9'])
|
|
381
453
|
result = t.get_html_string()
|
|
382
454
|
assert result.strip() == """
|
|
383
|
-
<table
|
|
455
|
+
<table>
|
|
384
456
|
<tr>
|
|
385
457
|
<th>Field 1</th>
|
|
386
458
|
<th>Field 2</th>
|
|
@@ -411,29 +483,106 @@ class HtmlOutputTests(unittest.TestCase):
|
|
|
411
483
|
t.add_row(['value 7', 'value8', 'value9'])
|
|
412
484
|
result = t.get_html_string(format=True)
|
|
413
485
|
assert result.strip() == """
|
|
414
|
-
<table
|
|
486
|
+
<table frame="box" rules="cols">
|
|
415
487
|
<tr>
|
|
416
488
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 1</th>
|
|
417
489
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 2</th>
|
|
418
490
|
<th style="padding-left: 1em; padding-right: 1em; text-align: center">Field 3</th>
|
|
419
491
|
</tr>
|
|
420
492
|
<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>
|
|
493
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 1</td>
|
|
494
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value2</td>
|
|
495
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value3</td>
|
|
424
496
|
</tr>
|
|
425
497
|
<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>
|
|
498
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 4</td>
|
|
499
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value5</td>
|
|
500
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value6</td>
|
|
429
501
|
</tr>
|
|
430
502
|
<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>
|
|
503
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value 7</td>
|
|
504
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value8</td>
|
|
505
|
+
<td style="padding-left: 1em; padding-right: 1em; text-align: center; vertical-align: top">value9</td>
|
|
434
506
|
</tr>
|
|
435
507
|
</table>
|
|
436
508
|
""".strip()
|
|
437
509
|
|
|
510
|
+
class CsvConstructorTest(BasicTests):
|
|
511
|
+
|
|
512
|
+
def setUp(self):
|
|
513
|
+
|
|
514
|
+
csv_string = """City name, Area , Population , Annual Rainfall
|
|
515
|
+
Sydney, 2058 , 4336374 , 1214.8
|
|
516
|
+
Melbourne, 1566 , 3806092 , 646.9
|
|
517
|
+
Brisbane, 5905 , 1857594 , 1146.4
|
|
518
|
+
Perth, 5386 , 1554769 , 869.4
|
|
519
|
+
Adelaide, 1295 , 1158259 , 600.5
|
|
520
|
+
Hobart, 1357 , 205556 , 619.5
|
|
521
|
+
Darwin, 0112 , 120900 , 1714.7"""
|
|
522
|
+
csv_fp = StringIO.StringIO(csv_string)
|
|
523
|
+
self.x = from_csv(csv_fp)
|
|
524
|
+
|
|
525
|
+
if _have_sqlite:
|
|
526
|
+
class DatabaseConstructorTest(BasicTests):
|
|
527
|
+
|
|
528
|
+
def setUp(self):
|
|
529
|
+
self.conn = sqlite3.connect(":memory:")
|
|
530
|
+
self.cur = self.conn.cursor()
|
|
531
|
+
self.cur.execute("CREATE TABLE cities (name TEXT, area INTEGER, population INTEGER, rainfall REAL)")
|
|
532
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Adelaide\", 1295, 1158259, 600.5)")
|
|
533
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Brisbane\", 5905, 1857594, 1146.4)")
|
|
534
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Darwin\", 112, 120900, 1714.7)")
|
|
535
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Hobart\", 1357, 205556, 619.5)")
|
|
536
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Sydney\", 2058, 4336374, 1214.8)")
|
|
537
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Melbourne\", 1566, 3806092, 646.9)")
|
|
538
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Perth\", 5386, 1554769, 869.4)")
|
|
539
|
+
self.cur.execute("SELECT * FROM cities")
|
|
540
|
+
self.x = from_db_cursor(self.cur)
|
|
541
|
+
|
|
542
|
+
def testNonSelectCurosr(self):
|
|
543
|
+
self.cur.execute("INSERT INTO cities VALUES (\"Adelaide\", 1295, 1158259, 600.5)")
|
|
544
|
+
assert from_db_cursor(self.cur) is None
|
|
545
|
+
|
|
546
|
+
class HtmlConstructorTest(CityDataTest):
|
|
547
|
+
|
|
548
|
+
def testHtmlAndBack(self):
|
|
549
|
+
html_string = self.x.get_html_string()
|
|
550
|
+
new_table = from_html(html_string)[0]
|
|
551
|
+
assert new_table.get_string() == self.x.get_string()
|
|
552
|
+
|
|
553
|
+
def testHtmlOneAndBack(self):
|
|
554
|
+
html_string = self.x.get_html_string()
|
|
555
|
+
new_table = from_html_one(html_string)
|
|
556
|
+
assert new_table.get_string() == self.x.get_string()
|
|
557
|
+
|
|
558
|
+
def testHtmlOneFailOnMany(self):
|
|
559
|
+
html_string = self.x.get_html_string()
|
|
560
|
+
html_string += self.x.get_html_string()
|
|
561
|
+
self.assertRaises(Exception, from_html_one, html_string)
|
|
562
|
+
|
|
563
|
+
class PrintEnglishTest(CityDataTest):
|
|
564
|
+
|
|
565
|
+
def testPrint(self):
|
|
566
|
+
print()
|
|
567
|
+
print(self.x)
|
|
568
|
+
|
|
569
|
+
class PrintJapanestTest(unittest.TestCase):
|
|
570
|
+
|
|
571
|
+
def setUp(self):
|
|
572
|
+
|
|
573
|
+
self.x = PrettyTable(["Kanji", "Hiragana", "English"])
|
|
574
|
+
self.x.add_row(["神戸", "こうべ", "Kobe"])
|
|
575
|
+
self.x.add_row(["京都", "きょうと", "Kyoto"])
|
|
576
|
+
self.x.add_row(["長崎", "ながさき", "Nagasaki"])
|
|
577
|
+
self.x.add_row(["名古屋", "なごや", "Nagoya"])
|
|
578
|
+
self.x.add_row(["大阪", "おおさか", "Osaka"])
|
|
579
|
+
self.x.add_row(["札幌", "さっぽろ", "Sapporo"])
|
|
580
|
+
self.x.add_row(["東京", "とうきょう", "Tokyo"])
|
|
581
|
+
self.x.add_row(["横浜", "よこはま", "Yokohama"])
|
|
582
|
+
|
|
583
|
+
def testPrint(self):
|
|
584
|
+
print()
|
|
585
|
+
print(self.x)
|
|
586
|
+
|
|
438
587
|
if __name__ == "__main__":
|
|
439
588
|
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
|