예제 #1
0
 def test_freeze_csv(self):
     freeze(self.tbl.all(), format='csv',
            filename='weather.csv', prefix=self.d)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         rows = list(reader(fh))
         keys = rows[0]
         for i, d1 in enumerate(TEST_DATA):
             d2 = dict(zip(keys, rows[i + 1]))
             for k in d1.keys():
                 v2 = d2[k]
                 if not PY3:
                     v2 = v2.decode('utf8')
                 v1 = value_to_str(d1[k])
                 if not isinstance(v1, text_type):
                     if isinstance(v1, binary_type):
                         v1 = text_type(v1, encoding='utf8')
                     else:
                         v1 = '%s' % v1
                 self.assertEqual(v2, v1)
     finally:
         fh.close()
예제 #2
0
 def test_freeze_csv(self):
     freeze(self.tbl.all(),
            format='csv',
            filename='weather.csv',
            prefix=self.d)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         rows = list(reader(fh))
         keys = rows[0]
         for i, d1 in enumerate(TEST_DATA):
             d2 = dict(zip(keys, rows[i + 1]))
             for k in d1.keys():
                 v2 = d2[k]
                 if not PY3:
                     v2 = v2.decode('utf8')
                 v1 = value_to_str(d1[k])
                 if not isinstance(v1, text_type):
                     if isinstance(v1, binary_type):
                         v1 = text_type(v1, encoding='utf8')
                     else:
                         v1 = '%s' % v1
                 self.assertEqual(v2, v1)
     finally:
         fh.close()
예제 #3
0
 def test_value_to_str4(self):
     assert [] == value_to_str([])
예제 #4
0
 def test_value_to_str3(self):
     assert '' == value_to_str(None)
예제 #5
0
 def test_value_to_str2(self):
     if PY3:
         assert 'hóla' == value_to_str('\u0068\u00f3\u006c\u0061')
     else:
         assert u'hóla'.encode('utf-8') == value_to_str(u'\u0068\u00f3\u006c\u0061'), \
             [value_to_str(u'\u0068\u00f3\u006c\u0061')]
예제 #6
0
 def test_value_to_str1(self):
     assert '2011-01-01T00:00:00' == value_to_str(TEST_DATA[0]['date']), \
         value_to_str(TEST_DATA[0]['date'])
예제 #7
0
 def test_value_to_str4(self):
     assert [] == value_to_str([])
예제 #8
0
 def test_value_to_str3(self):
     assert '' == value_to_str(None)
예제 #9
0
 def test_value_to_str2(self):
     if PY3:
         assert 'hóla' == value_to_str('\u0068\u00f3\u006c\u0061')
     else:
         assert 'hóla' == value_to_str(u'\u0068\u00f3\u006c\u0061')
예제 #10
0
 def test_value_to_str1(self):
     assert '2011-01-01T00:00:00' == value_to_str(TEST_DATA[0]['date'])
예제 #11
0
 def test_value_to_str2(self):
     if PY3:
         assert 'hóla' == value_to_str('\u0068\u00f3\u006c\u0061')
     else:
         assert u'hóla'.encode('utf-8') == value_to_str(u'\u0068\u00f3\u006c\u0061'), \
             [value_to_str(u'\u0068\u00f3\u006c\u0061')]