Merge pull request #2 from msabramo/add_tests · v3rd1shax/python-texttable@75f516e · GitHub
Skip to content

Commit 75f516e

Browse files
Merge pull request bufordtaylor#2 from msabramo/add_tests
Add tests and tox.ini
2 parents 0908dd9 + 07c8f70 commit 75f516e

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 31 additions & 0 deletions

‎test_texttable.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from textwrap import dedent
2+
3+
from texttable import Texttable, get_color_string, bcolors
4+
5+
def test_colored():
6+
table = Texttable()
7+
table.set_cols_align(["l", "r", "c"])
8+
table.set_cols_valign(["t", "m", "b"])
9+
table.add_rows([
10+
[get_color_string(bcolors.GREEN, "Name Of Person"), "Age", "Nickname"],
11+
["Mr\nXavier\nHuon", 32, "Xav'"],
12+
[get_color_string(bcolors.BLUE,"Mr\nBaptiste\nClement"),
13+
1,
14+
get_color_string(bcolors.RED,"Baby")] ])
15+
expected_output = dedent("""
16+
+----------------+-----+----------+
17+
| [92mName Of Person[0m | Age | Nickname |
18+
+================+=====+==========+
19+
| Mr | | |
20+
| Xavier | 32 | |
21+
| Huon | | Xav' |
22+
+----------------+-----+----------+
23+
| [94mMr[0m | | |
24+
| [94mBaptiste[0m | 1 | |
25+
| [94mClement[0m | | [91mBaby[0m |
26+
+----------------+-----+----------+
27+
""").strip('\n')
28+
29+
assert table.draw() == expected_output
30+
31+
def test_typed_columns():
32+
table = Texttable()
33+
table.set_deco(Texttable.HEADER)
34+
table.set_cols_dtype(['t', # text
35+
'f', # float (decimal)
36+
'e', # float (exponent)
37+
'i', # integer
38+
'a']) # automatic
39+
table.set_cols_align(["l", "r", "r", "r", "l"])
40+
table.add_rows([["text", "float", "exp", "int", "auto"],
41+
["abcd", "67", 654, 89, 128.001],
42+
["efghijk", 67.5434, .654, 89.6, 12800000000000000000000.00023],
43+
["lmn", 5e-78, 5e-78, 89.4, .000000000000128],
44+
["opqrstu", .023, 5e+78, 92., 12800000000000000000000]])
45+
expected_output = dedent("""
46+
text float exp int auto
47+
==============================================
48+
abcd 67.000 6.540e+02 89 128.001
49+
efghijk 67.543 6.540e-01 90 1.280e+22
50+
lmn 0.000 5.000e-78 89 0.000
51+
opqrstu 0.023 5.000e+78 92 1.280e+22
52+
""").strip('\n')
53+
54+
assert table.draw() == expected_output

‎tox.ini‎

Lines changed: 13 additions & 0 deletions

0 commit comments

Comments
 (0)