Exemple #1
0
 def test_write_a_book_reader(self):
     b = pe.BookReader(self.testfile)
     b.save_as(self.testfile2)
     x = pe.BookReader(self.testfile2)
     for s in x:
         data = pe.utils.to_array(s)
         assert self.content[s.name] == data
Exemple #2
0
 def test_write_book_reader(self):
     reader = pe.BookReader(self.testfile)
     writer = pe.BookWriter(self.testfile2)
     writer.write_book_reader(reader)
     writer.close()
     reader2 = pe.BookReader(self.testfile2)
     data = pe.utils.to_dict(reader2)
     assert data == self.content
Exemple #3
0
 def test_add_book3(self):
     """
     test this scenario: book3 = sheet1 + sheet2
     """
     b1 = pyexcel.BookReader(self.testfile, library="pyexcel-odsr")
     b2 = pyexcel.BookReader(self.testfile2)
     b3 = b1["Sheet1"] + b2["Sheet3"]
     content = b3.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 2
     assert content["Sheet3"] == self.content["Sheet3"]
     assert content["Sheet1"] == self.content["Sheet1"]
Exemple #4
0
 def test_add_book3(self):
     """
     test this scenario: book3 = sheet1 + sheet2
     """
     b1 = pe.BookReader(self.testfile)
     b2 = pe.BookReader(self.testfile2)
     b3 = b1["Sheet1"] + b2["Sheet3"]
     content = pe.utils.to_dict(b3)
     sheet_names = content.keys()
     assert len(sheet_names) == 2
     assert content["Sheet3"] == self.content["Sheet3"]
     assert content["Sheet1"] == self.content["Sheet1"]
Exemple #5
0
 def test_write_a_book_reader(self):
     b = pe.BookReader(self.testfile)
     bw = pe.BookWriter(self.testfile2)
     for s in b:
         data = pe.utils.to_array(s)
         sheet = bw.create_sheet(s.name)
         sheet.write_array(data)
         sheet.close()
     bw.close()
     x = pe.BookReader(self.testfile2)
     for s in x:
         data = pe.utils.to_array(s)
         assert self.content[s.name] == data
Exemple #6
0
 def test_add_sheet(self):
     """
     test this scenario: book3 = sheet1 + single_sheet_book
     """
     b1 = pe.BookReader(self.testfile)
     b2 = pe.BookReader(self.test_single_sheet_file)
     b3 = b1["Sheet1"] + b2
     content = pe.utils.to_dict(b3)
     sheet_names = content.keys()
     assert len(sheet_names) == 2
     for name in sheet_names:
         if "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
         elif "single.xls" in name:
             assert content[name] == self.content1["Sheet1"]
 def test_merge_any_files_to_a_book(self):
     file_array = [
         self.testfile,
         self.testfile2,
         self.testfile3,
         self.testfile4,
     ]
     pe.cookbook.merge_all_to_a_book(file_array, "merged.xlsx")
     r = pe.BookReader("merged.xlsx")
     r[self.testfile].name_columns_by_row(0)
     content = r[self.testfile].to_dict()
     assert content == self.content
     r[self.testfile2].format(int)
     r[self.testfile2].name_columns_by_row(0)
     content2 = r[self.testfile2].to_dict()
     assert content2 == self.content2
     r[self.testfile3].name_columns_by_row(0)
     content3 = r[self.testfile3].to_dict()
     assert content3 == self.content3
     content4 = r["Sheet1"].to_array()
     assert content4 == self.content4["Sheet1"]
     content5 = r["Sheet2"].to_array()
     assert content5 == self.content4["Sheet2"]
     content6 = r["Sheet3"].to_array()
     assert content6 == self.content4["Sheet3"]
Exemple #8
0
 def test_add_book4(self):
     """
     test this scenario: book3 = sheet1 + book
     """
     b1 = pyexcel.BookReader(self.testfile, library="pyexcel-odsr")
     b2 = pyexcel.BookReader(self.testfile2)
     b3 = b1["Sheet1"] + b2
     content = b3.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 4
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
 def test_add_sheet2(self):
     """
     test this scenario: book3 = sheet1 + single_sheet_book
     """
     b1 = pe.BookReader(self.testfile)
     b3 = b1["Sheet1"] + b1["Sheet1"]
     b3["Sheet1"].row[0] = [3, 3, 3, 3]
     eq_(b1["Sheet1"].row[0], [1, 1, 1, 1])
Exemple #10
0
 def test_random_access_operator(self):
     r = pyexcel.BookReader(self.testfile)
     value = r["Sheet1"][0, 1]
     assert value == 1
     value = r["Sheet3"][0, 1]
     assert value == 'Y'
     r["Sheet3"].name_columns_by_row(0)
     assert r["Sheet3"][0, 1] == 4
Exemple #11
0
 def test_add_book2_in_place(self):
     """
     test this scenario: book3 = book1 + sheet3
     """
     b1 = pe.BookReader(self.testfile)
     b2 = pe.BookReader(self.testfile2)
     b1 += b2["Sheet3"]
     content = pe.utils.to_dict(b1)
     sheet_names = content.keys()
     assert len(sheet_names) == 4
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
 def test_add_book1_in_place(self):
     """
     test this scenario: book1 +=  book2
     """
     b1 = pyexcel.BookReader(self.testfile)
     b2 = pyexcel.BookReader(self.testfile2)
     b1 += b2
     content = b1.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 6
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
 def test_add_book2(self):
     """
     test this scenario: book3 = book1 + sheet3
     """
     b1 = pyexcel.BookReader(self.testfile)
     b2 = pyexcel.BookReader(self.testfile2)
     b3 = b1 + b2["Sheet3"]
     content = b3.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 4
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
Exemple #14
0
 def test_add_book4(self):
     """
     test this scenario: book3 = sheet1 + book
     """
     b1 = pe.BookReader(self.testfile)
     b2 = pe.BookReader(self.testfile2)
     b3 = b1["Sheet1"] + b2
     content = pe.utils.to_dict(b3)
     sheet_names = content.keys()
     assert len(sheet_names) == 4
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
Exemple #15
0
 def test_iterate_through_sheets(self):
     b = pyexcel.BookReader(self.testfile)
     for s in b:
         data = pyexcel.utils.to_array(s)
         assert self.content[s.name] == data
     si = pyexcel.iterators.SheetIterator(b)
     for s in si:
         data = pyexcel.utils.to_array(s)
         assert self.content[s.name] == data
Exemple #16
0
 def test_random_access_operator(self):
     r = pe.BookReader(self.testfile)
     value = r["Sheet1"].row[0][1]
     assert value == 1
     value = r["Sheet3"].row[0][1]
     assert value == 'Y'
     r["Sheet3"].name_columns_by_row(0)
     value = r["Sheet3"].row[0][1]
     assert value == 4
Exemple #17
0
 def test_add_book6(self):
     """
     test this scenario: book3 = book + single_sheet_book
     """
     b1 = pe.BookReader(self.test_single_sheet_file)
     b2 = pe.BookReader(self.testfile2)
     b3 = b2 + b1
     content = b3.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 4
     for name in sheet_names:
         if "Sheet3" in name:
             assert content[name] == self.content["Sheet3"]
         elif "Sheet2" in name:
             assert content[name] == self.content["Sheet2"]
         elif "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
         elif "single.xls" in name:
             assert content[name] == self.content1["Sheet1"]
Exemple #18
0
    def test_add_book4_2(self):
        """
        test this scenario: book3 = sheet1 + book

        use . notation
        """
        b1 = pe.BookReader(self.testfile)
        b2 = pe.BookReader(self.testfile2)
        b3 = b1.Sheet1 + b2
        content = b3.dict
        sheet_names = content.keys()
        assert len(sheet_names) == 4
        for name in sheet_names:
            if "Sheet3" in name:
                assert content[name] == self.content["Sheet3"]
            elif "Sheet2" in name:
                assert content[name] == self.content["Sheet2"]
            elif "Sheet1" in name:
                assert content[name] == self.content["Sheet1"]
Exemple #19
0
 def test_merge_csv_files_to_a_book(self):
     file_array = [self.testfile, self.testfile2, self.testfile3]
     pe.cookbook.merge_csv_to_a_book(file_array, "merged.xlsx")
     r = pe.BookReader("merged.xlsx")
     content = pe.utils.to_dict(r[self.testfile].become_series())
     assert content == self.content
     content2 = pe.utils.to_dict(r[self.testfile2].become_series())
     assert content2 == self.content2
     content3 = pe.utils.to_dict(r[self.testfile3].become_series())
     assert content3 == self.content3
Exemple #20
0
 def test_random_access_operator(self):
     r = pe.BookReader(self.testfile)
     value = r["Sheet1"].row[0][1]
     assert value == 1
     value = r["Sheet3"].row[0][1]
     assert value == 'Y'
     value = r["Sheet3"].become_series().row[0][1]
     assert value == 4
     value = r["Sheet3"].become_sheet().row[0][1]
     assert value == 'Y'
Exemple #21
0
 def test_add_sheet2(self):
     """
     test this scenario: book3 = sheet1 + single_sheet_book
     """
     b1 = pe.BookReader(self.testfile)
     b3 = b1["Sheet1"] + b1["Sheet1"]
     content = b3.dict
     sheet_names = content.keys()
     assert len(sheet_names) == 2
     for name in sheet_names:
         if "Sheet1" in name:
             assert content[name] == self.content["Sheet1"]
 def test_merge_csv_files_to_a_book(self):
     file_array = [self.testfile, self.testfile2, self.testfile3]
     pe.cookbook.merge_csv_to_a_book(file_array, "merged.xlsx")
     r = pe.BookReader("merged.xlsx")
     r[self.testfile].name_columns_by_row(0)
     content = r[self.testfile].to_dict()
     assert content == self.content
     r[self.testfile2].format(int)
     r[self.testfile2].name_columns_by_row(0)
     content2 = r[self.testfile2].to_dict()
     assert content2 == self.content2
     r[self.testfile3].name_columns_by_row(0)
     content3 = r[self.testfile3].to_dict()
     assert content3 == self.content3
 def test_add_book_error(self):
     """
     test this scenario: book3 = sheet1 + book
     """
     b1 = pyexcel.BookReader(self.testfile)
     try:
         b1 + 12
         assert 1 == 2
     except TypeError:
         assert 1 == 1
     try:
         b1 += 12
         assert 1 == 2
     except TypeError:
         assert 1 == 1
Exemple #24
0
 def test_add_book_error(self):
     """
     test this scenario: book3 = book + integer
     """
     b1 = pe.BookReader(self.testfile)
     try:
         b1 + 12
         assert 1==2
     except TypeError:
         assert 1==1
     try:
         b1 += 12
         assert 1==2
     except TypeError:
         assert 1==1
Exemple #25
0
 def test_reading_through_sheets(self):
     b = pyexcel.BookReader(self.testfile)
     data = list(b["Sheet1"].rows())
     expected = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
     assert data == expected
     data = list(b["Sheet2"].rows())
     expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
     assert data == expected
     data = list(b["Sheet3"].rows())
     expected = [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
     sheet3 = b["Sheet3"]
     sheet3.name_columns_by_row(0)
     data = list(b["Sheet3"].rows())
     expected = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
Exemple #26
0
 def test_reading_through_sheets(self):
     b = pe.BookReader(self.testfile)
     data = pe.utils.to_array(b["Sheet1"].rows())
     expected = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
     assert data == expected
     data = pe.utils.to_array(b["Sheet2"].rows())
     expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
     assert data == expected
     data = pe.utils.to_array(b["Sheet3"].rows())
     expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
     sheet3 = b["Sheet3"]
     sheet3.become_series()
     data = pe.utils.to_array(b["Sheet3"].rows())
     expected = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
     assert data == expected
Exemple #27
0
 def test_write_book_reader(self):
     reader = pe.BookReader(self.testfile)
     writer = pe.BookWriter(self.testfile2)
     writer.write_book_reader(reader)
     writer.close()
     sheet1 = "test_Sheet 1.csv"
     reader1 = pe.Reader(sheet1)
     data = pe.utils.to_array(reader1)
     assert data == self.content["Sheet 1"]
     sheet2 = "test_Sheet 2.csv"
     reader2 = pe.Reader(sheet2)
     data = pe.utils.to_array(reader2)
     assert data == self.content["Sheet 2"]
     sheet3 = "test_Sheet 3.csv"
     reader3 = pe.Reader(sheet3)
     data = pe.utils.to_array(reader3)
     assert data == self.content["Sheet 3"]
Exemple #28
0
 def test_merge_any_files_to_a_book(self):
     file_array = [
         self.testfile, self.testfile2, self.testfile3, self.testfile4
     ]
     pe.cookbook.merge_all_to_a_book(file_array, "merged.xlsx")
     r = pe.BookReader("merged.xlsx")
     content = pe.utils.to_dict(r[self.testfile].become_series())
     assert content == self.content
     content2 = pe.utils.to_dict(r[self.testfile2].become_series())
     assert content2 == self.content2
     content3 = pe.utils.to_dict(r[self.testfile3].become_series())
     assert content3 == self.content3
     content4 = pe.utils.to_array(r["Sheet1"])
     assert content4 == self.content4["Sheet1"]
     content5 = pe.utils.to_array(r["Sheet2"])
     assert content5 == self.content4["Sheet2"]
     content6 = pe.utils.to_array(r["Sheet3"])
     assert content6 == self.content4["Sheet3"]
Exemple #29
0
 def test_add_sheet_error(self):
     """
     test this scenario: book3 = sheet1 + integer
     """
     b1 = pe.BookReader(self.testfile)
     try:
         b1["Sheet1"] + 12
         assert 1==2
     except TypeError:
         assert 1==1
     try:
         b1["Sheet1"] += 12
         assert 1==2
     except TypeError:
         assert 1==1
     try:
         b1["Sheet1"] += pe.sheets.AS_COLUMNS(12)
         assert 1==2
     except TypeError:
         assert 1==1
Exemple #30
0
 def test_write_book_reader(self):
     reader = pe.BookReader(self.testfile)
     writer = pe.BookWriter(self.testfile2)
     writer.write_book_reader(reader)
     writer.close()
     sheet1 = "test__Sheet 1__0.csv"
     reader1 = pe.Reader(sheet1)
     reader1.apply_formatter(pe.formatters.SheetFormatter(float))
     data = pe.utils.to_array(reader1)
     assert data == self.content["Sheet 1"]
     sheet2 = "test__Sheet 2__1.csv"
     reader2 = pe.Reader(sheet2)
     reader2.apply_formatter(pe.formatters.SheetFormatter(float))
     data = pe.utils.to_array(reader2)
     assert data == self.content["Sheet 2"]
     sheet3 = "test__Sheet 3__2.csv"
     reader3 = pe.Reader(sheet3)
     reader3.apply_formatter(pe.formatters.SheetFormatter(float))
     data = pe.utils.to_array(reader3)
     assert data == self.content["Sheet 3"]