本文整理汇总了Python中_compact.OrderedDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.update方法的具体用法?Python OrderedDict.update怎么用?Python OrderedDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_compact.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save_book_to_memory_from_sql
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_save_book_to_memory_from_sql(self):
test_file = pe.save_book_as(dest_file_type="xls", session=Session(), tables=[Signature, Signature2])
book_dict = pe.get_book_dict(file_content=test_file.getvalue(), file_type="xls")
expected = OrderedDict()
expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
assert book_dict == expected
示例2: setUp
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
class TestCSVNXlsMultipleSheets:
def setUp(self):
self.testfile = "multiple1.csv"
self.content = OrderedDict()
self.content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
self.content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
self.content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
pe.save_book_as(dest_file_name=self.testfile, bookdict=self.content)
def test_read_multiple_csv_into_book(self):
book = pe.load_book(self.testfile)
assert book.sheet_names() == ["Sheet1", "Sheet2", "Sheet3"]
book["Sheet1"].format(int)
assert self.content["Sheet1"] == book["Sheet1"].to_array()
book["Sheet2"].format(int)
assert self.content["Sheet2"] == book["Sheet2"].to_array()
book["Sheet3"].format(int)
assert self.content["Sheet3"] == book["Sheet3"].to_array()
def tearDown(self):
if os.path.exists("multiple1__Sheet1__0.csv"):
os.unlink("multiple1__Sheet1__0.csv")
if os.path.exists("multiple1__Sheet2__1.csv"):
os.unlink("multiple1__Sheet2__1.csv")
if os.path.exists("multiple1__Sheet3__2.csv"):
os.unlink("multiple1__Sheet3__2.csv")
示例3: test_get_book_from_book_dict
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_from_book_dict(self):
content = OrderedDict()
content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
book = pe.get_book(bookdict=content)
assert book.to_dict() == content
示例4: setUp
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
class TestBook:
def setUp(self):
self.content = OrderedDict()
self.content.update({"Sheet1": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
self.content.update({"Sheet2": [[u'A', u'B', u'C'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
self.result1 = [{'Y': 4, 'X': 1, 'Z': 7}, {'Y': 5, 'X': 2, 'Z': 8}, {'Y': 6, 'X': 3, 'Z': 9}]
self.result2 = [{'B': 4, 'A': 1, 'C': 7}, {'B': 5, 'A': 2, 'C': 8}, {'B': 6, 'A': 3, 'C': 9}]
def test_book_save_to_models(self):
model1=FakeDjangoModel()
model2=FakeDjangoModel()
book = pe.Book(self.content)
book.save_to_django_models([model1, model2])
assert model1.objects.objs == self.result1
assert model2.objects.objs == self.result2
def test_model_save_to_models(self):
model=FakeDjangoModel()
pe.save_book_as(dest_models=[model, None, None], bookdict=self.content)
assert model.objects.objs == self.result1
def test_load_book_from_django_model(self):
model=FakeDjangoModel()
book = pe.Book(self.content)
book.save_to_django_models([model])
assert model.objects.objs == self.result1
model._meta.update(["X", "Y", "Z"])
book2 = pe.get_book(models=[model])
assert book2[0].to_array() == book[0].to_array()
def test_more_sheets_than_models(self):
self.content.update({"IgnoreMe":[[1,2,3]]})
model=FakeDjangoModel()
pe.save_book_as(dest_models=[model], bookdict=self.content)
assert model.objects.objs == self.result1
示例5: test_get_book_from_sql
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_from_sql(self):
book_dict = pe.get_book_dict(session=Session(),
tables=[Signature, Signature2])
expected = OrderedDict()
expected.update({'signature': [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]})
expected.update({'signature2': [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]})
assert book_dict == expected
示例6: test_pyexcel_xls_issue_2
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_pyexcel_xls_issue_2():
data = OrderedDict()
array = []
for i in range(4100):
array.append([datetime.datetime.now()])
data.update({"test": array})
save_data("test.xls", data)
os.unlink("test.xls")
示例7: test_get_book_from_memory_compatibility
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_from_memory_compatibility(self):
content = OrderedDict()
content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
io = pe.save_book_as(dest_file_type="xls", bookdict=content)
book2 = pe.get_book(content=io.getvalue(), file_type="xls")
assert book2.to_dict() == content
示例8: test_get_book_from_file_stream
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_from_file_stream(self):
content = OrderedDict()
content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
io = pe.save_book_as(dest_file_type="xls", bookdict=content)
book2 = pe.get_book(file_stream=io, file_type="xls")
assert book2.to_dict() == content
示例9: test_get_book_dict
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_dict(self):
content = OrderedDict()
content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
io = pe.save_book_as(dest_file_type="xls", bookdict=content)
adict = pe.get_book_dict(file_content=io.getvalue(), file_type="xls")
assert adict == content
示例10: test_save_book_as_file_from_sql
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_save_book_as_file_from_sql(self):
test_file = "book_from_sql.xls"
pe.save_book_as(out_file=test_file, session=Session(), tables=[Signature, Signature2])
book_dict = pe.get_book_dict(file_name=test_file)
expected = OrderedDict()
expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
assert book_dict == expected
os.unlink(test_file)
示例11: test_issue_10
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_issue_10(self):
thedict = OrderedDict()
thedict.update({"Column 1": [1,2,3]})
thedict.update({"Column 2": [1,2,3]})
thedict.update({"Column 3": [1,2,3]})
pe.save_as(adict=thedict, dest_file_name="issue10.xls")
newdict = pe.get_dict(file_name="issue10.xls")
assert isinstance(newdict, OrderedDict) == True
assert thedict == newdict
示例12: test_get_book_from_file
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_get_book_from_file(self):
test_file = "test_get_book.xls"
content = OrderedDict()
content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
book = pe.Book(content)
book.save_as(test_file)
book2 = pe.get_book(file_name=test_file)
assert book2.to_dict() == content
os.unlink(test_file)
示例13: test_tutorial05_example3
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_tutorial05_example3(self):
content="Column 1,Column 2,Column 3\n1,4,7\n2,5,8\n3,6,9"
reader = pe.SeriesReader(("csv", content))
print(reader.column["Column 3"])
extra_data = OrderedDict()
extra_data.update({"Column 4":[10, 11, 12]})
extra_data.update({"Column 5":[13, 14, 15]})
reader.column += extra_data
print(pe.utils.to_dict(reader))
assert reader.column["Column 4"] == [10, 11, 12]
assert reader.column["Column 5"] == [13, 14, 15]
示例14: test_save_book_as_file_from_sql
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
def test_save_book_as_file_from_sql(self):
test_file="book_from_sql.xls"
pe.save_book_as(out_file=test_file,
session=Session(),
tables=[Signature, Signature2])
book_dict = pe.get_book_dict(file_name=test_file)
expected = OrderedDict()
expected.update({'signature': [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]})
expected.update({'signature2': [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]})
assert book_dict == expected
os.unlink(test_file)
示例15: TestXlsNXlsmMultipleSheets
# 需要导入模块: from _compact import OrderedDict [as 别名]
# 或者: from _compact.OrderedDict import update [as 别名]
class TestXlsNXlsmMultipleSheets(PyexcelMultipleSheetBase):
def setUp(self):
self.testfile = "multiple1.xls"
self.testfile2 = "multiple1.xlsm"
self.content = OrderedDict()
self.content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
self.content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
self.content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
self._write_test_file(self.testfile)
def tearDown(self):
self._clean_up()