示例#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_freeze(self):
     freeze(self.tbl.all(), format='csv',
            filename='wäther.csv'.encode('utf8'), prefix=self.d)
     self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
     freeze(self.tbl.all(), format='csv',
            filename='wäther.csv', prefix=self.d)
     self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
示例#4
0
    def test_freeze(self):
        from dataset.freeze.app import freeze

        freeze(self.db['weather'].all(), format='csv', filename='wäther.csv'.encode('utf8'), prefix=self.d)
        self.assert_(os.path.exists(os.path.join(self.d, 'wäther.csv')))
        freeze(self.db['weather'].all(), format='csv', filename='wäther.csv', prefix=self.d)
        self.assert_(os.path.exists(os.path.join(self.d, 'wäther.csv')))
示例#5
0
 def test_freeze(self):
     freeze(self.tbl.all(),
            format='csv',
            filename='wäther.csv'.encode('utf8'),
            prefix=self.d)
     self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
     freeze(self.tbl.all(),
            format='csv',
            filename='wäther.csv',
            prefix=self.d)
     self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
示例#6
0
    def test_memory_streams(self):
        if PY3:
            from io import StringIO
        else:
            from io import BytesIO as StringIO

        for fmt in ('csv', 'json', 'tabson'):
            with StringIO() as fd:
                freeze(self.tbl.all(), format=fmt, fileobj=fd)
                self.assertFalse(fd.closed, 'fileobj was closed for format %s' % fmt)
                fd.getvalue()  # should not throw
示例#7
0
    def test_memory_streams(self):
        if PY3:
            from io import StringIO
        else:
            from io import BytesIO as StringIO

        for fmt in ('csv', 'json', 'tabson'):
            with StringIO() as fd:
                freeze(self.tbl.all(), format=fmt, fileobj=fd)
                self.assertFalse(fd.closed,
                                 'fileobj was closed for format %s' % fmt)
                fd.getvalue()  # should not throw
示例#8
0
    def test_freeze(self):
        from dataset.freeze.app import freeze

        freeze(self.db['weather'].all(),
               format='csv',
               filename='wäther.csv'.encode('utf8'),
               prefix=self.d)
        self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
        freeze(self.db['weather'].all(),
               format='csv',
               filename='wäther.csv',
               prefix=self.d)
        self.assertTrue(os.path.exists(os.path.join(self.d, 'wäther.csv')))
示例#9
0
 def test_freeze_json_no_wrap(self):
     freeze(self.tbl.all(), format='json',
             filename='weather.csv', prefix=self.d, wrap=False)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         import json
         data = json.load(fh)
         self.assertIsInstance(data, list,
             'Without wrapping, returned JSON should be a list')
     finally:
         fh.close()
示例#10
0
 def test_freeze_json_no_wrap(self):
     freeze(self.tbl.all(),
            format='json',
            filename='weather.csv',
            prefix=self.d,
            wrap=False)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         import json
         data = json.load(fh)
         self.assertIsInstance(
             data, list, 'Without wrapping, returned JSON should be a list')
     finally:
         fh.close()
示例#11
0
 def test_freeze_json_wrap(self):
     freeze(self.tbl.all(), format='json',
             filename='weather.csv', prefix=self.d, wrap=True)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         import json
         data = json.load(fh)
         self.assertIsInstance(data, dict,
             'With wrapping, returned JSON should be a dict')
         self.assertIn('results', data.keys())
         self.assertIn('count', data.keys())
         self.assertIn('meta', data.keys())
     finally:
         fh.close()
示例#12
0
 def test_freeze_json_wrap(self):
     freeze(self.tbl.all(),
            format='json',
            filename='weather.csv',
            prefix=self.d,
            wrap=True)
     path = os.path.join(self.d, 'weather.csv')
     if PY3:
         fh = open(path, 'rt', encoding='utf8', newline='')
     else:
         fh = open(path, 'rU')
     try:
         import json
         data = json.load(fh)
         self.assertIsInstance(
             data, dict, 'With wrapping, returned JSON should be a dict')
         self.assertIn('results', data.keys())
         self.assertIn('count', data.keys())
         self.assertIn('meta', data.keys())
     finally:
         fh.close()