def test_array(self):
     test_sample = {
         "array": {
             u'result': [[u'X', u'Y', u'Z'],
                         [1.0, 2.0, 3.0],
                         [4.0, 5.0, 6.0]]},
         "dict": {
             u'result': {
                 u'Y': [2.0, 5.0],
                 u'X': [1.0, 4.0],
                 u'Z': [3.0, 6.0]
             }},
         "records": {
             u'result': [
                 {u'Y': 2.0, u'X': 1.0, u'Z': 3.0},
                 {u'Y': 5.0, u'X': 4.0, u'Z': 6.0}
             ]}
     }
     for struct_type in test_sample.keys():
         io = BytesIO()
         sheet = pe.Sheet(self.data)
         sheet.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post(
             '/respond/%s' % struct_type, buffered=True,
             data={"file": (io, "test.xls")},
             content_type="multipart/form-data")
         expected = test_sample[struct_type]
         assert json.loads(response.data.decode('utf-8')) == expected
 def test_array(self):
     test_sample = {
         "array": {
             'result': [['X', 'Y', 'Z'], [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
         },
         "dict": {
             'result': {
                 'Y': [2.0, 5.0],
                 'X': [1.0, 4.0],
                 'Z': [3.0, 6.0]
             }
         },
         "records": {
             'result': [{
                 'Y': 2.0,
                 'X': 1.0,
                 'Z': 3.0
             }, {
                 'Y': 5.0,
                 'X': 4.0,
                 'Z': 6.0
             }]
         }
     }
     for struct_type in list(test_sample.keys()):
         io = BytesIO()
         sheet = pe.Sheet(self.data)
         sheet.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post('/respond/%s' % struct_type,
                                  buffered=True,
                                  data={"file": (io, "test.xls")},
                                  content_type="multipart/form-data")
         expected = test_sample[struct_type]
         assert json.loads(response.data.decode('utf-8')) == expected
 def test_book(self):
     test_sample = ["book", "book_dict"]
     expected = {
         u"result": {
             u"Sheet1": [
                 [1.0, 1.0, 1.0, 1.0],
                 [2.0, 2.0, 2.0, 2.0],
                 [3.0, 3.0, 3.0, 3.0],
             ],
             u"Sheet3": [
                 [u"X", u"Y", u"Z"],
                 [1.0, 4.0, 7.0],
                 [2.0, 5.0, 8.0],
                 [3.0, 6.0, 9.0],
             ],
             u"Sheet2": [
                 [4.0, 4.0, 4.0, 4.0],
                 [5.0, 5.0, 5.0, 5.0],
                 [6.0, 6.0, 6.0, 6.0],
             ],
         }
     }
     for struct_type in test_sample:
         io = BytesIO()
         book = pe.Book(self.content)
         book.save_to_memory("xls", io)
         io.seek(0)
         response = self.app.post(
             "/respond/%s" % struct_type,
             buffered=True,
             data={"file": (io, "test.xls")},
             content_type="multipart/form-data",
         )
         assert json.loads(response.data.decode("utf-8")) == expected
 def test_book(self):
     test_sample = ["book", "book_dict"]
     expected = {u'result': {u'Sheet1': [[1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0], [3.0, 3.0, 3.0, 3.0]], u'Sheet3': [[u'X', u'Y', u'Z'], [1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]], u'Sheet2': [[4.0, 4.0, 4.0, 4.0], [5.0, 5.0, 5.0, 5.0], [6.0, 6.0, 6.0, 6.0]]}}
     for struct_type in test_sample:
         io = BytesIO()
         book = pe.Book(self.content)
         book.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post('/respond/%s' % struct_type, buffered=True,
                                  data={"file": (io, "test.xls")},
                                  content_type="multipart/form-data")
         assert json.loads(response.data.decode('utf-8')) == expected
 def test_book(self):
     for struct_type in ["book", "book_dict"]:
         io = BytesIO()
         book = pe.Book(self.content)
         book.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post('/exchange/%s' % struct_type,
                                  buffered=True,
                                  data={"file": (io, "test.xls")},
                                  content_type="multipart/form-data")
         assert response.content_type == "application/vnd.ms-excel"
         book2 = pe.load_book_from_memory('xls', response.data)
         assert book2.to_dict() == self.content
 def test_array(self):
     for struct_type in ["array", "dict", "records"]:
         print("Testing %s" % struct_type)
         io = BytesIO()
         sheet = pe.Sheet(self.data)
         sheet.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post('/exchange/%s' % struct_type,
                                  buffered=True,
                                  data={"file": (io, "test.xls")},
                                  content_type="multipart/form-data")
         assert response.content_type == "application/vnd.ms-excel"
         sheet = pe.load_from_memory('xls', response.data)
         assert sheet.to_array() == self.data
 def test_download(self):
     for upload_file_type in ['xlsx']:#FILE_TYPE_MIME_TABLE.keys():
         file_name = 'test.%s' % upload_file_type
         for download_file_type in ['tsv']:#FILE_TYPE_MIME_TABLE.keys():
             print("Uploading %s Downloading %s" % (upload_file_type, download_file_type))
             io = BytesIO()
             sheet = pe.Sheet(self.data)
             sheet.save_to_memory(upload_file_type, io)
             io.seek(0)
             response = self.app.post('/switch/%s' % download_file_type,
                                      buffered=True,
                                      data={"file": (io, file_name)},
                                      content_type="multipart/form-data")
             assert response.content_type == FILE_TYPE_MIME_TABLE[download_file_type]
             sheet = pe.load_from_memory(download_file_type, response.data)
             sheet.format(int)
             array = sheet.to_array()
             assert array == self.data
 def test_array(self):
     test_sample = {
         "array": {
             u"result": [
                 [u"X", u"Y", u"Z"],
                 [1.0, 2.0, 3.0],
                 [4.0, 5.0, 6.0],
             ]
         },
         "dict": {
             u"result": {
                 u"Y": [2.0, 5.0],
                 u"X": [1.0, 4.0],
                 u"Z": [3.0, 6.0],
             }
         },
         "records": {
             u"result": [
                 {
                     u"Y": 2.0,
                     u"X": 1.0,
                     u"Z": 3.0
                 },
                 {
                     u"Y": 5.0,
                     u"X": 4.0,
                     u"Z": 6.0
                 },
             ]
         },
     }
     for struct_type in test_sample.keys():
         io = BytesIO()
         sheet = pe.Sheet(self.data)
         sheet.save_to_memory("xls", io)
         io.seek(0)
         response = self.app.post(
             "/respond/%s" % struct_type,
             buffered=True,
             data={"file": (io, "test.xls")},
             content_type="multipart/form-data",
         )
         expected = test_sample[struct_type]
         assert json.loads(response.data.decode("utf-8")) == expected
 def test_book(self):
     test_sample = ["book", "book_dict"]
     expected = {
         'result': {
             'Sheet1': [[1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0],
                        [3.0, 3.0, 3.0, 3.0]],
             'Sheet3': [['X', 'Y', 'Z'], [1.0, 4.0, 7.0], [2.0, 5.0, 8.0],
                        [3.0, 6.0, 9.0]],
             'Sheet2': [[4.0, 4.0, 4.0, 4.0], [5.0, 5.0, 5.0, 5.0],
                        [6.0, 6.0, 6.0, 6.0]]
         }
     }
     for struct_type in test_sample:
         io = BytesIO()
         book = pe.Book(self.content)
         book.save_to_memory('xls', io)
         io.seek(0)
         response = self.app.post('/respond/%s' % struct_type,
                                  buffered=True,
                                  data={"file": (io, "test.xls")},
                                  content_type="multipart/form-data")
         assert json.loads(response.data.decode('utf-8')) == expected