-
Notifications
You must be signed in to change notification settings - Fork 24
/
pretty_table_tests.py
53 lines (42 loc) · 1.37 KB
/
pretty_table_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import unittest
import datetime
import mm
no_pretty_table = True
try:
import prettytable # NOQA
from mm.contrib.prettytable.composers import ComposerPrettyTable
no_pretty_table = False
except ImportError:
print "could not import pretty_table"
now = datetime.datetime.now().replace(microsecond=0)
class PrettyTableTestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
@unittest.skipIf(no_pretty_table, 'Skipping PrettyTable test (prettytable package not installed)')
def test_custom_pretty_table_serializer(self):
my_data = [
{
'msg': "My first Cell",
'id': 1,
'when': now,
},
{
'msg': "My second Cell",
'id': 2,
'when': now,
},
]
mm_doc = mm.Document(my_data) # data_model_class=PrettyTableModel)
mm_doc.set_composer_class(ComposerPrettyTable)
out = '''
+----------------+---------------------+----+
| msg | when | id |
+----------------+---------------------+----+
| My first Cell | %(now)s | 1 |
| My second Cell | %(now)s | 2 |
+----------------+---------------------+----+''' % dict(now=now)
self.assertEquals(str(mm_doc.writestr()), out.strip())
if __name__ == "__main__":
unittest.main()