Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sheet_save_to_django_model(self):
model = FakeDjangoModel()
sheet = pe.Sheet(self.data, name_columns_by_row=0)
sheet.save_to_django_model(model)
assert model.objects.objs == self.result
def test_issue_125_using_key():
test_file = "issue_125.xls"
book = p.Book()
book += p.Sheet([[1]], "A")
book += p.Sheet([[2]], "B")
book += p.Sheet([[3]], "C")
custom_order = {"A": 1, "B": 3, "C": 2}
book.sort_sheets(key=lambda x: custom_order[x])
book.save_as(test_file)
book2 = p.get_book(file_name=test_file)
eq_(book2.sheet_names(), ["A", "C", "B"])
os.unlink(test_file)
def test_delete_indexed_row3(self):
s = Sheet(self.data, "test")
s.name_rows_by_column(0)
del s.row["Row 0", "Row 1"]
assert s.number_of_rows() == 2
s.row["Row 1"] # already deleted
def test_save_sheet_to_sys_stdout():
data = [[1]]
sheet = pe.Sheet(data)
stream = sheet.save_to_memory("csv", sys.stdout)
eq_(stream.getvalue(), "1\r\n")
def test_book_in_jupyter_renderring(self):
self.fake_uuid.side_effect = ['1', '2', '3', '4']
self.dump_dict.return_value = DEFAULT_CONFIG
book = pyexcel.Book()
book += pyexcel.Sheet([[1]])
book += pyexcel.Sheet([[2]], name='pyexcel sheet_1')
book += pyexcel.Sheet([[3]], name='pyexcel sheet_2')
actual = book.handsontable
test_fixture = 'tests/fixtures/book.jupyter_notebook'
with codecs.open(test_fixture, 'r', encoding='utf-8') as f:
expected = f.read()
self.customAssertMultiLineEqual(expected, actual)
def test_book_renderring(self):
self.fake_uuid.side_effect = ['1', '2', '3', '4']
self.dump_dict.return_value = DEFAULT_CONFIG
book = pyexcel.Book()
book += pyexcel.Sheet([[1]])
book += pyexcel.Sheet([[2]])
book += pyexcel.Sheet([[3]])
book.save_as(self._test_file)
self.compareTwoFiles(
self._test_file,
'tests/fixtures/book.handsontable.html')
def test_set_indexed_row(self):
s = Sheet(self.data, "test")
s.name_columns_by_row(2)
s.row[0] = [10000, 1, 11]
assert s.row[0] == [10000, 1, 11]
def _add_supported_attributes_that_doesnt_exists(sheet):
supported_attributes_that_doesnt_exists = list(set(XLSFORM_PREDEFINED_COLUMN_NAMES[sheet.name]) - set(sheet.colnames))
additional_data = list()
additional_data.append(supported_attributes_that_doesnt_exists)
for row in sheet.rows():
additional_data.append(['' for x in supported_attributes_that_doesnt_exists])
additional_supported_attr_sheet = pe.Sheet(additional_data)
sheet.column += additional_supported_attr_sheet
def download():
sheet = pe.Sheet(data)
output = make_response(sheet.csv)
output.headers["Content-Disposition"] = "attachment; filename=export.csv"
output.headers["Content-type"] = "text/csv"
return output