1import os
2
3from base import PyexcelWriterBase, PyexcelHatWriterBase
4from pyexcel_xlsx import get_data
5from pyexcel_xlsx.xlsxw import XLSXWriter as Writer
6
7
8class TestNativeXLSXWriter:
9    def test_write_book(self):
10        self.content = {
11            "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],
12            "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]],
13            "Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]],
14        }
15        self.testfile = "writer.xlsx"
16        writer = Writer(self.testfile, "xlsx")
17        writer.write(self.content)
18        writer.close()
19        content = get_data(self.testfile)
20        for key in content.keys():
21            content[key] = list(content[key])
22        assert content == self.content
23
24    def tearDown(self):
25        if os.path.exists(self.testfile):
26            os.unlink(self.testfile)
27
28
29class TestxlsxnCSVWriter(PyexcelWriterBase):
30    def setUp(self):
31        self.testfile = "test.xlsx"
32        self.testfile2 = "test.csv"
33
34    def tearDown(self):
35        if os.path.exists(self.testfile):
36            os.unlink(self.testfile)
37        if os.path.exists(self.testfile2):
38            os.unlink(self.testfile2)
39
40
41class TestxlsxHatWriter(PyexcelHatWriterBase):
42    def setUp(self):
43        self.testfile = "test.xlsx"
44
45    def tearDown(self):
46        if os.path.exists(self.testfile):
47            os.unlink(self.testfile)
48